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-jdk7u51-b13.patch 498KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233
  1. diff -r 6c6a2299029a make/bsd/makefiles/gcc.make
  2. --- a/make/bsd/makefiles/gcc.make Sat Dec 14 11:51:15 2013 -0800
  3. +++ b/make/bsd/makefiles/gcc.make Mon Apr 28 13:12:30 2014 -0700
  4. @@ -116,7 +116,10 @@
  5. CFLAGS += -fno-rtti
  6. CFLAGS += -fno-exceptions
  7. CFLAGS += -pthread
  8. -CFLAGS += -fcheck-new
  9. +## well, strictly speaking we should check for clang not Darwin
  10. +ifneq ($(OS_VENDOR), Darwin)
  11. + CFLAGS += -fcheck-new
  12. +endif
  13. # version 4 and above support fvisibility=hidden (matches jni_x86.h file)
  14. # except 4.1.2 gives pointless warnings that can't be disabled (afaik)
  15. ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0"
  16. diff -r 6c6a2299029a src/cpu/x86/vm/templateTable_x86_32.cpp
  17. --- a/src/cpu/x86/vm/templateTable_x86_32.cpp Sat Dec 14 11:51:15 2013 -0800
  18. +++ b/src/cpu/x86/vm/templateTable_x86_32.cpp Mon Apr 28 13:12:30 2014 -0700
  19. @@ -2109,6 +2109,22 @@
  20. // resolve first time through
  21. address entry;
  22. switch (bytecode()) {
  23. + case Bytecodes::_fast_agetfield : // fall through
  24. + case Bytecodes::_fast_bgetfield : // fall through
  25. + case Bytecodes::_fast_cgetfield : // fall through
  26. + case Bytecodes::_fast_dgetfield : // fall through
  27. + case Bytecodes::_fast_fgetfield : // fall through
  28. + case Bytecodes::_fast_igetfield : // fall through
  29. + case Bytecodes::_fast_lgetfield : // fall through
  30. + case Bytecodes::_fast_sgetfield : // fall through
  31. + case Bytecodes::_fast_aputfield : // fall through
  32. + case Bytecodes::_fast_bputfield : // fall through
  33. + case Bytecodes::_fast_cputfield : // fall through
  34. + case Bytecodes::_fast_dputfield : // fall through
  35. + case Bytecodes::_fast_fputfield : // fall through
  36. + case Bytecodes::_fast_iputfield : // fall through
  37. + case Bytecodes::_fast_lputfield : // fall through
  38. + case Bytecodes::_fast_sputfield : // fall through
  39. case Bytecodes::_getstatic : // fall through
  40. case Bytecodes::_putstatic : // fall through
  41. case Bytecodes::_getfield : // fall through
  42. @@ -2211,6 +2227,7 @@
  43. // Correct values of the cache and index registers are preserved.
  44. void TemplateTable::jvmti_post_field_access(Register cache,
  45. Register index,
  46. + int byte_no,
  47. bool is_static,
  48. bool has_tos) {
  49. if (JvmtiExport::can_post_field_access()) {
  50. @@ -2237,7 +2254,11 @@
  51. // cache: cache entry pointer
  52. __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access),
  53. rax, cache);
  54. - __ get_cache_and_index_at_bcp(cache, index, 1);
  55. +
  56. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  57. + __ restore_bcp();
  58. + resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  59. +
  60. __ bind(L1);
  61. }
  62. }
  63. @@ -2258,7 +2279,7 @@
  64. const Register flags = rax;
  65. resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  66. - jvmti_post_field_access(cache, index, is_static, false);
  67. + jvmti_post_field_access(cache, index, byte_no, is_static, false);
  68. load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  69. if (!is_static) pop_and_check_object(obj);
  70. @@ -2393,7 +2414,7 @@
  71. // The registers cache and index expected to be set before call.
  72. // The function may destroy various registers, just not the cache and index registers.
  73. -void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is_static) {
  74. +void TemplateTable::jvmti_post_field_mod(Register cache, Register index, int byte_no, bool is_static) {
  75. ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();
  76. @@ -2451,7 +2472,11 @@
  77. // rcx: jvalue object on the stack
  78. __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification),
  79. rbx, rax, rcx);
  80. - __ get_cache_and_index_at_bcp(cache, index, 1);
  81. +
  82. + // (tw) Redefinition might have occured => reresolve the cp entry.
  83. + __ restore_bcp();
  84. + resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  85. +
  86. __ bind(L1);
  87. }
  88. }
  89. @@ -2467,7 +2492,7 @@
  90. const Register flags = rax;
  91. resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  92. - jvmti_post_field_mod(cache, index, is_static);
  93. + jvmti_post_field_mod(cache, index, byte_no, is_static);
  94. load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  95. // Doug Lea believes this is not needed with current Sparcs (TSO) and Intel (PSO).
  96. @@ -2818,6 +2843,11 @@
  97. // rcx: cache entry pointer
  98. __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access), rax, rcx);
  99. __ pop_ptr(rax); // restore object pointer
  100. +
  101. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  102. + __ restore_bcp();
  103. + resolve_cache_and_index(1, noreg, rax, rcx, sizeof(u2));
  104. +
  105. __ bind(L1);
  106. }
  107. @@ -3008,6 +3038,26 @@
  108. __ bind(notFinal);
  109. + // DCEVM: Check if we are calling an old method (and have to go slow path)
  110. + Label notOld;
  111. + __ movl(rax, flags);
  112. + __ andl(rax, (1 << ConstantPoolCacheEntry::is_old_method_shift));
  113. + __ jcc(Assembler::zero, notOld);
  114. +
  115. + // Need a null check here!
  116. + __ null_check(recv);
  117. +
  118. + // 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)
  119. + // DCEVM: TODO: Check if we can improve performance by inlining.
  120. + // DCEVM: TODO: Check if this additional branch affects normal execution time.
  121. + __ call_VM(method, CAST_FROM_FN_PTR(address, InterpreterRuntime::find_correct_method), recv, index);
  122. +
  123. + // profile this call
  124. + __ profile_final_call(rax);
  125. + __ jump_from_interpreted(method, rdx);
  126. +
  127. + __ bind(notOld);
  128. +
  129. // get receiver klass
  130. __ null_check(recv, oopDesc::klass_offset_in_bytes());
  131. __ load_klass(rax, recv);
  132. @@ -3093,6 +3143,31 @@
  133. invokevirtual_helper(rbx, rcx, rdx);
  134. __ bind(notMethod);
  135. + // DCEVM: Check if we are calling an old method (and have to go slow path)
  136. + //__ movl(rax, rdx);
  137. + Label notOld;
  138. + __ andl(rdx, (1 << ConstantPoolCacheEntry::is_old_method_shift));
  139. + __ jcc(Assembler::zero, notOld);
  140. +
  141. + // Get receiver klass into rdx - also a null check
  142. + __ movptr(rdx, Address(rcx, oopDesc::klass_offset_in_bytes()));
  143. + __ verify_oop(rdx);
  144. +
  145. + // 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)
  146. + // DCEVM: TODO: Check if we can improve performance by inlining.
  147. + // DCEVM: TODO: Check if this additional branch affects normal execution time.
  148. + // DCEVM: TODO: Check the exact semantic (with respect to destoying registers) of call_VM
  149. + __ call_VM(rbx, CAST_FROM_FN_PTR(address, InterpreterRuntime::find_correct_interface_method), rcx, rax, rbx);
  150. +
  151. + // DCEVM: TODO: Check if resolved method could be null.
  152. +
  153. + // profile this call
  154. + __ profile_virtual_call(rdx, rsi, rdi);
  155. +
  156. + __ jump_from_interpreted(rbx, rdx);
  157. +
  158. + __ bind(notOld);
  159. +
  160. // Get receiver klass into rdx - also a null check
  161. __ restore_locals(); // restore rdi
  162. __ null_check(rcx, oopDesc::klass_offset_in_bytes());
  163. diff -r 6c6a2299029a src/cpu/x86/vm/templateTable_x86_64.cpp
  164. --- a/src/cpu/x86/vm/templateTable_x86_64.cpp Sat Dec 14 11:51:15 2013 -0800
  165. +++ b/src/cpu/x86/vm/templateTable_x86_64.cpp Mon Apr 28 13:12:30 2014 -0700
  166. @@ -2151,6 +2151,22 @@
  167. // resolve first time through
  168. address entry;
  169. switch (bytecode()) {
  170. + case Bytecodes::_fast_agetfield : // fall through
  171. + case Bytecodes::_fast_bgetfield : // fall through
  172. + case Bytecodes::_fast_cgetfield : // fall through
  173. + case Bytecodes::_fast_dgetfield : // fall through
  174. + case Bytecodes::_fast_fgetfield : // fall through
  175. + case Bytecodes::_fast_igetfield : // fall through
  176. + case Bytecodes::_fast_lgetfield : // fall through
  177. + case Bytecodes::_fast_sgetfield : // fall through
  178. + case Bytecodes::_fast_aputfield : // fall through
  179. + case Bytecodes::_fast_bputfield : // fall through
  180. + case Bytecodes::_fast_cputfield : // fall through
  181. + case Bytecodes::_fast_dputfield : // fall through
  182. + case Bytecodes::_fast_fputfield : // fall through
  183. + case Bytecodes::_fast_iputfield : // fall through
  184. + case Bytecodes::_fast_lputfield : // fall through
  185. + case Bytecodes::_fast_sputfield : // fall through
  186. case Bytecodes::_getstatic:
  187. case Bytecodes::_putstatic:
  188. case Bytecodes::_getfield:
  189. @@ -2267,7 +2283,7 @@
  190. // The registers cache and index expected to be set before call.
  191. // Correct values of the cache and index registers are preserved.
  192. void TemplateTable::jvmti_post_field_access(Register cache, Register index,
  193. - bool is_static, bool has_tos) {
  194. + int byte_no, bool is_static, bool has_tos) {
  195. // do the JVMTI work here to avoid disturbing the register state below
  196. // We use c_rarg registers here because we want to use the register used in
  197. // the call to the VM
  198. @@ -2298,7 +2314,11 @@
  199. __ call_VM(noreg, CAST_FROM_FN_PTR(address,
  200. InterpreterRuntime::post_field_access),
  201. c_rarg1, c_rarg2, c_rarg3);
  202. - __ get_cache_and_index_at_bcp(cache, index, 1);
  203. +
  204. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  205. + __ restore_bcp();
  206. + resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  207. +
  208. __ bind(L1);
  209. }
  210. }
  211. @@ -2320,7 +2340,7 @@
  212. const Register bc = c_rarg3; // uses same reg as obj, so don't mix them
  213. resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  214. - jvmti_post_field_access(cache, index, is_static, false);
  215. + jvmti_post_field_access(cache, index, byte_no, is_static, false);
  216. load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  217. if (!is_static) {
  218. @@ -2455,7 +2475,7 @@
  219. // The registers cache and index expected to be set before call.
  220. // The function may destroy various registers, just not the cache and index registers.
  221. -void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is_static) {
  222. +void TemplateTable::jvmti_post_field_mod(Register cache, Register index, int byte_no, bool is_static) {
  223. transition(vtos, vtos);
  224. ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();
  225. @@ -2507,7 +2527,11 @@
  226. CAST_FROM_FN_PTR(address,
  227. InterpreterRuntime::post_field_modification),
  228. c_rarg1, c_rarg2, c_rarg3);
  229. - __ get_cache_and_index_at_bcp(cache, index, 1);
  230. +
  231. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  232. + __ restore_bcp();
  233. + resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  234. +
  235. __ bind(L1);
  236. }
  237. }
  238. @@ -2523,7 +2547,7 @@
  239. const Register bc = c_rarg3;
  240. resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  241. - jvmti_post_field_mod(cache, index, is_static);
  242. + jvmti_post_field_mod(cache, index, byte_no, is_static);
  243. load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  244. // [jk] not needed currently
  245. @@ -2837,6 +2861,11 @@
  246. InterpreterRuntime::post_field_access),
  247. c_rarg1, c_rarg2);
  248. __ pop_ptr(rax); // restore object pointer
  249. +
  250. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  251. + __ restore_bcp();
  252. + resolve_cache_and_index(1, noreg, rax, rcx, sizeof(u2));
  253. +
  254. __ bind(L1);
  255. }
  256. @@ -3073,6 +3102,26 @@
  257. __ bind(notFinal);
  258. + // DCEVM: Check if we are calling an old method (and have to go slow path)
  259. + Label notOld;
  260. + __ movl(rax, flags);
  261. + __ andl(rax, (1 << ConstantPoolCacheEntry::is_old_method_shift));
  262. + __ jcc(Assembler::zero, notOld);
  263. +
  264. + // Need a null check here!
  265. + __ null_check(recv);
  266. +
  267. + // 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)
  268. + // DCEVM: TODO: Check if we can improve performance by inlining.
  269. + // DCEVM: TODO: Check if this additional branch affects normal execution time.
  270. + __ call_VM(method, CAST_FROM_FN_PTR(address, InterpreterRuntime::find_correct_method), recv, index);
  271. +
  272. + // profile this call
  273. + __ profile_final_call(rax);
  274. + __ jump_from_interpreted(method, rdx);
  275. +
  276. + __ bind(notOld);
  277. +
  278. // get receiver klass
  279. __ null_check(recv, oopDesc::klass_offset_in_bytes());
  280. __ load_klass(rax, recv);
  281. @@ -3156,6 +3205,35 @@
  282. invokevirtual_helper(rbx, rcx, rdx);
  283. __ bind(notMethod);
  284. + // DCEVM: Check if we are calling an old method (and have to go slow path)
  285. + Label notOld;
  286. + __ andl(rdx, (1 << ConstantPoolCacheEntry::is_old_method_shift));
  287. + __ jcc(Assembler::zero, notOld);
  288. +
  289. + // Call out to VM to do look up based on correct vTable version (has to iterate back over the class history of the receiver class)
  290. + // DCEVM: TODO: Check if we can improve performance by inlining.
  291. + // DCEVM: TODO: Check if this additional branch affects normal execution time.
  292. + // DCEVM: TODO: Check the exact semantic (with respect to destoying registers) of call_VM
  293. + // DCEVM: FIXME: What exactly should we store here?
  294. + __ push(rcx); // destroyed by Linux arguments passing conventions
  295. + __ movptr(r14, rcx);
  296. + __ call_VM(rbx, CAST_FROM_FN_PTR(address, InterpreterRuntime::find_correct_interface_method), r14, rax, rbx);
  297. + __ pop(rcx);
  298. +
  299. + // Get receiver klass into rdx - also a null check
  300. + __ restore_locals(); // restore r14
  301. + __ load_klass(rdx, rcx);
  302. + __ verify_oop(rdx);
  303. +
  304. + // DCEVM: TODO: Check if resolved method could be null.
  305. +
  306. + // profile this call
  307. + __ profile_virtual_call(rdx, r13, r14);
  308. +
  309. + __ jump_from_interpreted(rbx, rdx);
  310. +
  311. + __ bind(notOld);
  312. +
  313. // Get receiver klass into rdx - also a null check
  314. __ restore_locals(); // restore r14
  315. __ null_check(rcx, oopDesc::klass_offset_in_bytes());
  316. diff -r 6c6a2299029a src/os/bsd/vm/attachListener_bsd.cpp
  317. --- a/src/os/bsd/vm/attachListener_bsd.cpp Sat Dec 14 11:51:15 2013 -0800
  318. +++ b/src/os/bsd/vm/attachListener_bsd.cpp Mon Apr 28 13:12:30 2014 -0700
  319. @@ -460,14 +460,14 @@
  320. void AttachListener::vm_start() {
  321. char fn[UNIX_PATH_MAX];
  322. - struct stat64 st;
  323. + struct stat st;
  324. int ret;
  325. int n = snprintf(fn, UNIX_PATH_MAX, "%s/.java_pid%d",
  326. os::get_temp_directory(), os::current_process_id());
  327. assert(n < (int)UNIX_PATH_MAX, "java_pid file name buffer overflow");
  328. - RESTARTABLE(::stat64(fn, &st), ret);
  329. + RESTARTABLE(::stat(fn, &st), ret);
  330. if (ret == 0) {
  331. ret = ::unlink(fn);
  332. if (ret == -1) {
  333. diff -r 6c6a2299029a src/share/vm/c1/c1_Compilation.hpp
  334. --- a/src/share/vm/c1/c1_Compilation.hpp Sat Dec 14 11:51:15 2013 -0800
  335. +++ b/src/share/vm/c1/c1_Compilation.hpp Mon Apr 28 13:12:30 2014 -0700
  336. @@ -242,8 +242,8 @@
  337. #define BAILOUT(msg) { bailout(msg); return; }
  338. #define BAILOUT_(msg, res) { bailout(msg); return res; }
  339. -#define CHECK_BAILOUT() { if (bailed_out()) return; }
  340. -#define CHECK_BAILOUT_(res) { if (bailed_out()) return res; }
  341. +#define CHECK_BAILOUT() { if (((CompilerThread *)Thread::current())->should_bailout()) bailout("Aborted externally"); if (bailed_out()) return; }
  342. +#define CHECK_BAILOUT_(res) { if (((CompilerThread *)Thread::current())->should_bailout()) bailout("Aborted externally"); if (bailed_out()) return res; }
  343. class InstructionMark: public StackObj {
  344. diff -r 6c6a2299029a src/share/vm/ci/ciEnv.cpp
  345. --- a/src/share/vm/ci/ciEnv.cpp Sat Dec 14 11:51:15 2013 -0800
  346. +++ b/src/share/vm/ci/ciEnv.cpp Mon Apr 28 13:12:30 2014 -0700
  347. @@ -1172,3 +1172,11 @@
  348. // If memory is low, we stop compiling methods.
  349. record_method_not_compilable("out of memory");
  350. }
  351. +
  352. +// DCEVM: Called after class redefinition to clean up possibly invalidated state.
  353. +void ciEnv::cleanup_after_redefinition() {
  354. +
  355. + if (_factory != NULL) {
  356. + _factory->cleanup_after_redefinition();
  357. + }
  358. +}
  359. diff -r 6c6a2299029a src/share/vm/ci/ciEnv.hpp
  360. --- a/src/share/vm/ci/ciEnv.hpp Sat Dec 14 11:51:15 2013 -0800
  361. +++ b/src/share/vm/ci/ciEnv.hpp Mon Apr 28 13:12:30 2014 -0700
  362. @@ -417,6 +417,8 @@
  363. void record_failure(const char* reason);
  364. void record_method_not_compilable(const char* reason, bool all_tiers = true);
  365. void record_out_of_memory_failure();
  366. +
  367. + void cleanup_after_redefinition();
  368. };
  369. #endif // SHARE_VM_CI_CIENV_HPP
  370. diff -r 6c6a2299029a src/share/vm/ci/ciObjectFactory.cpp
  371. --- a/src/share/vm/ci/ciObjectFactory.cpp Sat Dec 14 11:51:15 2013 -0800
  372. +++ b/src/share/vm/ci/ciObjectFactory.cpp Mon Apr 28 13:12:30 2014 -0700
  373. @@ -296,6 +296,11 @@
  374. // into the table. We need to recompute our index.
  375. index = find(keyHandle(), _ci_objects);
  376. }
  377. +
  378. + if (is_found_at(index, keyHandle(), _ci_objects)) {
  379. + // DCEVM: Check if this is an error? Can occur when redefining classes.
  380. + return _ci_objects->at(index);
  381. + }
  382. assert(!is_found_at(index, keyHandle(), _ci_objects), "no double insert");
  383. insert(index, new_object, _ci_objects);
  384. return new_object;
  385. @@ -764,3 +769,50 @@
  386. _unloaded_instances->length(),
  387. _unloaded_klasses->length());
  388. }
  389. +
  390. +// DCEVM: Resoring the ciObject arrays after class redefinition
  391. +void ciObjectFactory::sort_ci_objects(GrowableArray<ciObject*>* objects) {
  392. +
  393. + // Resort the _ci_objects array. The order of two class pointers can be changed during class redefinition.
  394. + oop last = NULL;
  395. + for (int j = 0; j< objects->length(); j++) {
  396. + oop o = objects->at(j)->get_oop();
  397. + if (last >= o) {
  398. + int cur_last_index = j - 1;
  399. + oop cur_last = last;
  400. + while (cur_last >= o) {
  401. +
  402. + // Swap the two objects to guarantee ordering
  403. + ciObject *tmp = objects->at(cur_last_index);
  404. + objects->at_put(cur_last_index, objects->at(cur_last_index + 1));
  405. + objects->at_put(cur_last_index + 1, tmp);
  406. +
  407. + // Decrement index to move one step to the left
  408. + cur_last_index--;
  409. + if (cur_last_index < 0) {
  410. + break;
  411. + }
  412. + cur_last = objects->at(cur_last_index)->get_oop();
  413. + }
  414. + } else {
  415. + assert(last < o, "out of order");
  416. + last = o;
  417. + }
  418. + }
  419. +
  420. +#ifdef ASSERT
  421. + if (CIObjectFactoryVerify) {
  422. + oop last = NULL;
  423. + for (int j = 0; j< objects->length(); j++) {
  424. + oop o = objects->at(j)->get_oop();
  425. + assert(last < o, "out of order");
  426. + last = o;
  427. + }
  428. + }
  429. +#endif // ASSERT
  430. +}
  431. +
  432. +// DCEVM: Called after class redefinition to clean up possibly invalidated state.
  433. +void ciObjectFactory::cleanup_after_redefinition() {
  434. + sort_ci_objects(_ci_objects);
  435. +}
  436. diff -r 6c6a2299029a src/share/vm/ci/ciObjectFactory.hpp
  437. --- a/src/share/vm/ci/ciObjectFactory.hpp Sat Dec 14 11:51:15 2013 -0800
  438. +++ b/src/share/vm/ci/ciObjectFactory.hpp Mon Apr 28 13:12:30 2014 -0700
  439. @@ -38,6 +38,7 @@
  440. class ciObjectFactory : public ResourceObj {
  441. friend class VMStructs;
  442. friend class ciEnv;
  443. + friend class CompileBroker;
  444. private:
  445. static volatile bool _initialized;
  446. @@ -137,6 +138,11 @@
  447. void print_contents();
  448. void print();
  449. +
  450. +private:
  451. +
  452. + static void sort_ci_objects(GrowableArray<ciObject*>* objects);
  453. + void cleanup_after_redefinition();
  454. };
  455. #endif // SHARE_VM_CI_CIOBJECTFACTORY_HPP
  456. diff -r 6c6a2299029a src/share/vm/classfile/classFileParser.cpp
  457. --- a/src/share/vm/classfile/classFileParser.cpp Sat Dec 14 11:51:15 2013 -0800
  458. +++ b/src/share/vm/classfile/classFileParser.cpp Mon Apr 28 13:12:30 2014 -0700
  459. @@ -795,6 +795,7 @@
  460. Handle class_loader,
  461. Handle protection_domain,
  462. Symbol* class_name,
  463. + KlassHandle old_klass,
  464. TRAPS) {
  465. ClassFileStream* cfs = stream();
  466. assert(length > 0, "only called for length>0");
  467. @@ -813,6 +814,9 @@
  468. interface_index, CHECK_(nullHandle));
  469. if (cp->tag_at(interface_index).is_klass()) {
  470. interf = KlassHandle(THREAD, cp->resolved_klass_at(interface_index));
  471. + if (!old_klass.is_null() && !interf->is_newest_version()) {
  472. + interf = KlassHandle(THREAD, interf->newest_version());
  473. + }
  474. } else {
  475. Symbol* unresolved_klass = cp->klass_name_at(interface_index);
  476. @@ -825,6 +829,9 @@
  477. klassOop k = SystemDictionary::resolve_super_or_fail(class_name,
  478. unresolved_klass, class_loader, protection_domain,
  479. false, CHECK_(nullHandle));
  480. + if (!old_klass.is_null()) {
  481. + k = k->klass_part()->newest_version();
  482. + }
  483. interf = KlassHandle(THREAD, k);
  484. }
  485. @@ -1912,6 +1919,8 @@
  486. int runtime_invisible_parameter_annotations_length = 0;
  487. u1* annotation_default = NULL;
  488. int annotation_default_length = 0;
  489. + u2 code_section_table_length;
  490. + typeArrayHandle code_section_table;
  491. // Parse code and exceptions attribute
  492. u2 method_attributes_count = cfs->get_u2_fast();
  493. @@ -2081,6 +2090,24 @@
  494. parse_stackmap_table(code_attribute_length, CHECK_(nullHandle));
  495. stackmap_data = typeArrayHandle(THREAD, sm);
  496. parsed_stackmap_attribute = true;
  497. + } else if (UseMethodForwardPoints && cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_code_sections()) {
  498. + int length = code_attribute_length;
  499. + int value_count = length / sizeof(u2);
  500. + int line_count = length / 3;
  501. + if (TraceRedefineClasses >= 3) {
  502. + tty->print_cr("Found code section attribute when loading class with %d entries", value_count, line_count);
  503. + }
  504. + code_section_table_length = value_count;
  505. + code_section_table = oopFactory::new_permanent_shortArray(value_count, CHECK_NULL);
  506. + code_section_table->set_length(value_count);
  507. +
  508. + for (int i = 0; i < value_count; ++i) {
  509. + u2 value = cfs->get_u2(CHECK_(nullHandle));
  510. + code_section_table->short_at_put(i, value);
  511. + if (TraceRedefineClasses >= 4) {
  512. + tty->print_cr("Code section table at %d: %d", i, value);
  513. + }
  514. + }
  515. } else {
  516. // Skip unknown attributes
  517. cfs->skip_u1(code_attribute_length, CHECK_(nullHandle));
  518. @@ -2206,6 +2233,18 @@
  519. }
  520. #endif
  521. + // DCEVM: TODO: Get a different solution for the problem of method forward
  522. + // points and variable sized interpreter frames.
  523. + if (UseMethodForwardPoints) {
  524. + if (max_stack > MethodForwardPointsMaxStack) {
  525. + fatal(err_msg("Method has too large stack (%d), increase the value of MethodForwardPointsMaxStack (%d)", max_stack, MethodForwardPointsMaxStack));
  526. + }
  527. + if (max_locals > MethodForwardPointsMaxLocals) {
  528. + fatal(err_msg("Method has too many locals (%d), increase the value of MethodForwardPointsMaxLocals (%d)", max_stack, MethodForwardPointsMaxStack));
  529. + }
  530. + max_stack = MethodForwardPointsMaxStack;
  531. + max_locals = MethodForwardPointsMaxLocals;
  532. + }
  533. // Fill in code attribute information
  534. m->set_max_stack(max_stack);
  535. m->set_max_locals(max_locals);
  536. @@ -2219,6 +2258,8 @@
  537. */
  538. m->constMethod()->set_stackmap_data(stackmap_data());
  539. + m->constMethod()->set_code_section_table(code_section_table());
  540. +
  541. // Copy byte codes
  542. m->set_code(code_start);
  543. @@ -2792,6 +2833,15 @@
  544. "Invalid Deprecated classfile attribute length %u in class file %s",
  545. attribute_length, CHECK);
  546. }
  547. + } else if (tag == vmSymbols::tag_field_redefinition_policy()) {
  548. + // DCEVM: Check for deleted field attribute
  549. + _field_redefinition_policy = cfs->get_u1_fast();
  550. + } else if (tag == vmSymbols::tag_static_field_redefinition_policy()) {
  551. + // DCEVM: Check for deleted static field attribute
  552. + _static_field_redefinition_policy = cfs->get_u1_fast();
  553. + } else if (tag == vmSymbols::tag_method_redefinition_policy()) {
  554. + // DCEVM: Check for deleted method attribute
  555. + _method_redefinition_policy = cfs->get_u1_fast();
  556. } else if (_major_version >= JAVA_1_5_VERSION) {
  557. if (tag == vmSymbols::tag_signature()) {
  558. if (attribute_length != 2) {
  559. @@ -2895,6 +2945,17 @@
  560. }
  561. k->set_inner_classes(_inner_classes());
  562. k->set_class_annotations(_annotations());
  563. +
  564. +
  565. + if (_field_redefinition_policy != 0xff) {
  566. + k->set_field_redefinition_policy(_field_redefinition_policy);
  567. + }
  568. + if (_static_field_redefinition_policy != 0xff) {
  569. + k->set_static_field_redefinition_policy(_static_field_redefinition_policy);
  570. + }
  571. + if (_method_redefinition_policy != 0xff) {
  572. + k->set_method_redefinition_policy(_method_redefinition_policy);
  573. + }
  574. }
  575. typeArrayHandle ClassFileParser::assemble_annotations(u1* runtime_visible_annotations,
  576. @@ -2918,9 +2979,126 @@
  577. }
  578. +// DCEVM: Finds the super symbols by reading the bytes of the class and returns
  579. +// them in a growable array.
  580. +void ClassFileParser::findSuperSymbols(Symbol* name,
  581. + Handle class_loader,
  582. + Handle protection_domain,
  583. + KlassHandle old_klass,
  584. + GrowableArray<Symbol*> &handles,
  585. + TRAPS) {
  586. +
  587. + _cp_patches = NULL;
  588. + // So that JVMTI can cache class file in the state before retransformable agents
  589. + // have modified it
  590. + unsigned char *cached_class_file_bytes = NULL;
  591. +
  592. + ClassFileStream* cfs = stream();
  593. +
  594. + _has_finalizer = _has_empty_finalizer = _has_vanilla_constructor = false;
  595. +
  596. + instanceKlassHandle nullHandle;
  597. +
  598. + // Save the class file name for easier error message printing.
  599. + _class_name = name != NULL ? name : vmSymbols::unknown_class_name();
  600. +
  601. + cfs->guarantee_more(8, CHECK); // magic, major, minor
  602. + // Magic value
  603. + u4 magic = cfs->get_u4_fast();
  604. + if (magic != JAVA_CLASSFILE_MAGIC) {
  605. + // Invalid class file!
  606. + return;
  607. + }
  608. +
  609. + // Version numbers
  610. + u2 minor_version = cfs->get_u2_fast();
  611. + u2 major_version = cfs->get_u2_fast();
  612. +
  613. + // Check version numbers - we check this even with verifier off
  614. + if (!is_supported_version(major_version, minor_version)) {
  615. +
  616. + // Unsupported version!
  617. + return;
  618. + }
  619. +
  620. + _major_version = major_version;
  621. + _minor_version = minor_version;
  622. +
  623. +
  624. + // Check if verification needs to be relaxed for this class file
  625. + // Do not restrict it to jdk1.0 or jdk1.1 to maintain backward compatibility (4982376)
  626. + _relax_verify = Verifier::relax_verify_for(class_loader());
  627. + _need_verify = false;
  628. +
  629. + // Constant pool
  630. + constantPoolHandle cp = parse_constant_pool(class_loader(), CHECK);
  631. + int cp_size = cp->length();
  632. +
  633. + cfs->guarantee_more(8, CHECK); // flags, this_class, super_class, infs_len
  634. +
  635. + // Access flags
  636. + AccessFlags access_flags;
  637. + jint flags = cfs->get_u2_fast() & JVM_RECOGNIZED_CLASS_MODIFIERS;
  638. +
  639. + if ((flags & JVM_ACC_INTERFACE) && _major_version < JAVA_6_VERSION) {
  640. + // Set abstract bit for old class files for backward compatibility
  641. + flags |= JVM_ACC_ABSTRACT;
  642. + }
  643. + access_flags.set_flags(flags);
  644. +
  645. + // This class and superclass
  646. + instanceKlassHandle super_klass;
  647. + u2 this_class_index = cfs->get_u2_fast();
  648. + check_property(
  649. + valid_cp_range(this_class_index, cp_size) &&
  650. + cp->tag_at(this_class_index).is_unresolved_klass(),
  651. + "Invalid this class index %u in constant pool in class file %s",
  652. + this_class_index, CHECK);
  653. +
  654. + Symbol* class_name = cp->unresolved_klass_at(this_class_index);
  655. + assert(class_name != NULL, "class_name can't be null");
  656. +
  657. + // Update _class_name which could be null previously to be class_name
  658. + _class_name = class_name;
  659. +
  660. + // DCEVM: DO NOT release all handles when parsing is done
  661. + {// HandleMark hm(THREAD);
  662. +
  663. + // Checks if name in class file matches requested name
  664. + if (name != NULL && class_name != name) {
  665. + return;
  666. + }
  667. +
  668. + u2 super_class_index = cfs->get_u2_fast();
  669. +
  670. + if (super_class_index != 0) {
  671. + Symbol* super_class = cp->klass_name_at(super_class_index);
  672. + handles.append(super_class);
  673. + } else {
  674. + // DCEVM: This redefinition must be for the Object class.
  675. + }
  676. +
  677. + // Interfaces
  678. + u2 itfs_len = cfs->get_u2_fast();
  679. + objArrayHandle local_interfaces;
  680. + if (itfs_len == 0) {
  681. + local_interfaces = objArrayHandle(THREAD, Universe::the_empty_system_obj_array());
  682. + } else {
  683. + local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, old_klass, CHECK);
  684. + }
  685. +
  686. + for (int i=0; i<local_interfaces->length(); i++) {
  687. + oop o = local_interfaces->obj_at(i);
  688. + Symbol* interface_handle = ((klassOop)o)->klass_part()->name();
  689. + handles.append(interface_handle);
  690. + }
  691. + }
  692. +}
  693. +
  694. instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  695. Handle class_loader,
  696. Handle protection_domain,
  697. + KlassHandle old_klass,
  698. KlassHandle host_klass,
  699. GrowableArray<Handle>* cp_patches,
  700. TempNewSymbol& parsed_name,
  701. @@ -2971,10 +3149,13 @@
  702. unsigned char* ptr = cfs->buffer();
  703. unsigned char* end_ptr = cfs->buffer() + cfs->length();
  704. + bool pretend_new_universe = Thread::current()->pretend_new_universe();
  705. + Thread::current()->set_pretend_new_universe(false);
  706. JvmtiExport::post_class_file_load_hook(name, class_loader, protection_domain,
  707. &ptr, &end_ptr,
  708. &cached_class_file_bytes,
  709. &cached_class_file_length);
  710. + Thread::current()->set_pretend_new_universe(pretend_new_universe);
  711. if (ptr != cfs->buffer()) {
  712. // JVMTI agent has modified class file data.
  713. @@ -3130,7 +3311,11 @@
  714. // However, make sure it is not an array type.
  715. bool is_array = false;
  716. if (cp->tag_at(super_class_index).is_klass()) {
  717. - super_klass = instanceKlassHandle(THREAD, cp->resolved_klass_at(super_class_index));
  718. + klassOop resolved_klass = cp->resolved_klass_at(super_class_index);
  719. + if (!old_klass.is_null()) {
  720. + resolved_klass = resolved_klass->klass_part()->newest_version();
  721. + }
  722. + super_klass = instanceKlassHandle(THREAD, resolved_klass);
  723. if (_need_verify)
  724. is_array = super_klass->oop_is_array();
  725. } else if (_need_verify) {
  726. @@ -3148,7 +3333,7 @@
  727. if (itfs_len == 0) {
  728. local_interfaces = objArrayHandle(THREAD, Universe::the_empty_system_obj_array());
  729. } else {
  730. - local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, CHECK_(nullHandle));
  731. + local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, old_klass, CHECK_(nullHandle));
  732. }
  733. u2 java_fields_count = 0;
  734. @@ -3202,7 +3387,9 @@
  735. protection_domain,
  736. true,
  737. CHECK_(nullHandle));
  738. -
  739. + if (!old_klass.is_null()) {
  740. + k = k->klass_part()->newest_version();
  741. + }
  742. KlassHandle kh (THREAD, k);
  743. super_klass = instanceKlassHandle(THREAD, kh());
  744. }
  745. @@ -3591,6 +3778,19 @@
  746. rt = REF_NONE;
  747. } else {
  748. rt = super_klass->reference_type();
  749. +
  750. + // DCEVM: With class redefinition, it can also happen that special classes are loaded.
  751. + if (name == vmSymbols::java_lang_ref_Reference()) {
  752. + rt = REF_OTHER;
  753. + } else if (name == vmSymbols::java_lang_ref_SoftReference()) {
  754. + rt = REF_SOFT;
  755. + } else if (name == vmSymbols::java_lang_ref_WeakReference()) {
  756. + rt = REF_WEAK;
  757. + } else if (name == vmSymbols::java_lang_ref_FinalReference()) {
  758. + rt = REF_FINAL;
  759. + } else if (name == vmSymbols::java_lang_ref_PhantomReference()) {
  760. + rt = REF_PHANTOM;
  761. + }
  762. }
  763. // We can now create the basic klassOop for this klass
  764. @@ -3691,7 +3891,7 @@
  765. fill_oop_maps(this_klass, nonstatic_oop_map_count, nonstatic_oop_offsets, nonstatic_oop_counts);
  766. // Fill in has_finalizer, has_vanilla_constructor, and layout_helper
  767. - set_precomputed_flags(this_klass);
  768. + set_precomputed_flags(this_klass, old_klass);
  769. // reinitialize modifiers, using the InnerClasses attribute
  770. int computed_modifiers = this_klass->compute_modifier_flags(CHECK_(nullHandle));
  771. @@ -3714,6 +3914,10 @@
  772. // Allocate mirror and initialize static fields
  773. java_lang_Class::create_mirror(this_klass, CHECK_(nullHandle));
  774. + if (rt == REF_OTHER) {
  775. + instanceRefKlass::update_nonstatic_oop_maps(ik);
  776. + }
  777. +
  778. ClassLoadingService::notify_class_loaded(instanceKlass::cast(this_klass()),
  779. false /* not shared class */);
  780. @@ -3856,7 +4060,7 @@
  781. }
  782. -void ClassFileParser::set_precomputed_flags(instanceKlassHandle k) {
  783. +void ClassFileParser::set_precomputed_flags(instanceKlassHandle k, KlassHandle old_klass) {
  784. klassOop super = k->super();
  785. // Check if this klass has an empty finalize method (i.e. one with return bytecode only),
  786. @@ -3864,7 +4068,9 @@
  787. if (!_has_empty_finalizer) {
  788. if (_has_finalizer ||
  789. (super != NULL && super->klass_part()->has_finalizer())) {
  790. - k->set_has_finalizer();
  791. + if (old_klass.is_null() || old_klass->has_finalizer()) {
  792. + k->set_has_finalizer();
  793. + }
  794. }
  795. }
  796. @@ -3880,7 +4086,7 @@
  797. // Check if this klass supports the java.lang.Cloneable interface
  798. if (SystemDictionary::Cloneable_klass_loaded()) {
  799. - if (k->is_subtype_of(SystemDictionary::Cloneable_klass())) {
  800. + if (k->is_subtype_of(SystemDictionary::Cloneable_klass()) || k->is_subtype_of(SystemDictionary::Cloneable_klass()->klass_part()->newest_version())) {
  801. k->set_is_cloneable();
  802. }
  803. }
  804. diff -r 6c6a2299029a src/share/vm/classfile/classFileParser.hpp
  805. --- a/src/share/vm/classfile/classFileParser.hpp Sat Dec 14 11:51:15 2013 -0800
  806. +++ b/src/share/vm/classfile/classFileParser.hpp Mon Apr 28 13:12:30 2014 -0700
  807. @@ -64,6 +64,9 @@
  808. int _sde_length;
  809. typeArrayHandle _inner_classes;
  810. typeArrayHandle _annotations;
  811. + u1 _field_redefinition_policy;
  812. + u1 _static_field_redefinition_policy;
  813. + u1 _method_redefinition_policy;
  814. void set_class_synthetic_flag(bool x) { _synthetic_flag = x; }
  815. void set_class_sourcefile(Symbol* x) { _sourcefile = x; }
  816. @@ -151,6 +154,7 @@
  817. Handle class_loader,
  818. Handle protection_domain,
  819. Symbol* class_name,
  820. + KlassHandle old_klass,
  821. TRAPS);
  822. // Field parsing
  823. @@ -237,7 +241,7 @@
  824. unsigned int nonstatic_oop_map_count,
  825. int* nonstatic_oop_offsets,
  826. unsigned int* nonstatic_oop_counts);
  827. - void set_precomputed_flags(instanceKlassHandle k);
  828. + void set_precomputed_flags(instanceKlassHandle k, KlassHandle old_klass);
  829. objArrayHandle compute_transitive_interfaces(instanceKlassHandle super,
  830. objArrayHandle local_ifs, TRAPS);
  831. @@ -337,7 +341,12 @@
  832. public:
  833. // Constructor
  834. - ClassFileParser(ClassFileStream* st) { set_stream(st); }
  835. + ClassFileParser(ClassFileStream* st) {
  836. + set_stream(st);
  837. + _field_redefinition_policy = 0xff;
  838. + _static_field_redefinition_policy = 0xff;
  839. + _method_redefinition_policy = 0xff;
  840. + }
  841. // Parse .class file and return new klassOop. The klassOop is not hooked up
  842. // to the system dictionary or any other structures, so a .class file can
  843. @@ -349,21 +358,33 @@
  844. instanceKlassHandle parseClassFile(Symbol* name,
  845. Handle class_loader,
  846. Handle protection_domain,
  847. + KlassHandle old_klass,
  848. TempNewSymbol& parsed_name,
  849. bool verify,
  850. TRAPS) {
  851. KlassHandle no_host_klass;
  852. - return parseClassFile(name, class_loader, protection_domain, no_host_klass, NULL, parsed_name, verify, THREAD);
  853. + return parseClassFile(name, class_loader, protection_domain, old_klass, no_host_klass, NULL, parsed_name, verify, THREAD);
  854. }
  855. instanceKlassHandle parseClassFile(Symbol* name,
  856. Handle class_loader,
  857. Handle protection_domain,
  858. + KlassHandle old_klass,
  859. KlassHandle host_klass,
  860. GrowableArray<Handle>* cp_patches,
  861. TempNewSymbol& parsed_name,
  862. bool verify,
  863. TRAPS);
  864. + static void initialize_static_field(fieldDescriptor* fd, TRAPS);
  865. +
  866. + // DCEVM: Creates symbol handles for the super class and the interfaces
  867. + void findSuperSymbols(Symbol* name,
  868. + Handle class_loader,
  869. + Handle protection_domain,
  870. + KlassHandle old_klass,
  871. + GrowableArray<Symbol*> &handles,
  872. + TRAPS);
  873. +
  874. // Verifier checks
  875. static void check_super_class_access(instanceKlassHandle this_klass, TRAPS);
  876. static void check_super_interface_access(instanceKlassHandle this_klass, TRAPS);
  877. diff -r 6c6a2299029a src/share/vm/classfile/classLoader.cpp
  878. --- a/src/share/vm/classfile/classLoader.cpp Sat Dec 14 11:51:15 2013 -0800
  879. +++ b/src/share/vm/classfile/classLoader.cpp Mon Apr 28 13:12:30 2014 -0700
  880. @@ -915,6 +915,7 @@
  881. instanceKlassHandle result = parser.parseClassFile(h_name,
  882. class_loader,
  883. protection_domain,
  884. + KlassHandle(),
  885. parsed_name,
  886. false,
  887. CHECK_(h));
  888. diff -r 6c6a2299029a src/share/vm/classfile/dictionary.cpp
  889. --- a/src/share/vm/classfile/dictionary.cpp Sat Dec 14 11:51:15 2013 -0800
  890. +++ b/src/share/vm/classfile/dictionary.cpp Mon Apr 28 13:12:30 2014 -0700
  891. @@ -326,6 +326,21 @@
  892. }
  893. }
  894. +
  895. +// DCEVM: Just the classes from defining class loaders
  896. +void Dictionary::classes_do(ObjectClosure *closure) {
  897. + for (int index = 0; index < table_size(); index++) {
  898. + for (DictionaryEntry* probe = bucket(index);
  899. + probe != NULL;
  900. + probe = probe->next()) {
  901. + klassOop k = probe->klass();
  902. + if (probe->loader() == instanceKlass::cast(k)->class_loader()) {
  903. + closure->do_object(k);
  904. + }
  905. + }
  906. + }
  907. +}
  908. +
  909. // Added for initialize_itable_for_klass to handle exceptions
  910. // Just the classes from defining class loaders
  911. void Dictionary::classes_do(void f(klassOop, TRAPS), TRAPS) {
  912. @@ -433,6 +448,33 @@
  913. add_entry(index, entry);
  914. }
  915. +// DCEVM: Updates the klass entry to point to the new klassOop. Necessary only for class redefinition.
  916. +bool Dictionary::update_klass(int index, unsigned int hash, Symbol* name, Handle loader, KlassHandle k, KlassHandle old_class) {
  917. +
  918. + // There are several entries for the same class in the dictionary: One extra entry for each parent classloader of the classloader of the class.
  919. + bool found = false;
  920. + for (int index = 0; index < table_size(); index++) {
  921. + for (DictionaryEntry* entry = bucket(index); entry != NULL; entry = entry->next()) {
  922. + if (entry->klass() == old_class()) {
  923. + entry->set_literal(k());
  924. + found = true;
  925. + }
  926. + }
  927. + }
  928. +
  929. + return found;
  930. +}
  931. +
  932. +// DCEVM: Undo previous updates to the system dictionary
  933. +void Dictionary::rollback_redefinition() {
  934. + for (int index = 0; index < table_size(); index++) {
  935. + for (DictionaryEntry* entry = bucket(index); entry != NULL; entry = entry->next()) {
  936. + if (entry->klass()->klass_part()->is_redefining()) {
  937. + entry->set_literal(entry->klass()->klass_part()->old_version());
  938. + }
  939. + }
  940. + }
  941. +}
  942. // This routine does not lock the system dictionary.
  943. //
  944. @@ -459,12 +501,22 @@
  945. return NULL;
  946. }
  947. +// DCEVM: return old version if we are not in the new universe?
  948. +klassOop Dictionary::intercept_for_version(klassOop k) {
  949. + if (k == NULL) return k;
  950. +
  951. + if (k->klass_part()->is_redefining() && !Thread::current()->pretend_new_universe()) {
  952. + return k->klass_part()->old_version();
  953. + }
  954. +
  955. + return k;
  956. +}
  957. klassOop Dictionary::find(int index, unsigned int hash, Symbol* name,
  958. Handle loader, Handle protection_domain, TRAPS) {
  959. DictionaryEntry* entry = get_entry(index, hash, name, loader);
  960. if (entry != NULL && entry->is_valid_protection_domain(protection_domain)) {
  961. - return entry->klass();
  962. + return intercept_for_version(entry->klass());
  963. } else {
  964. return NULL;
  965. }
  966. @@ -477,7 +529,7 @@
  967. assert (index == index_for(name, loader), "incorrect index?");
  968. DictionaryEntry* entry = get_entry(index, hash, name, loader);
  969. - return (entry != NULL) ? entry->klass() : (klassOop)NULL;
  970. + return intercept_for_version((entry != NULL) ? entry->klass() : (klassOop)NULL);
  971. }
  972. @@ -489,7 +541,7 @@
  973. assert (index == index_for(name, Handle()), "incorrect index?");
  974. DictionaryEntry* entry = get_entry(index, hash, name, Handle());
  975. - return (entry != NULL) ? entry->klass() : (klassOop)NULL;
  976. + return intercept_for_version((entry != NULL) ? entry->klass() : (klassOop)NULL);
  977. }
  978. diff -r 6c6a2299029a src/share/vm/classfile/dictionary.hpp
  979. --- a/src/share/vm/classfile/dictionary.hpp Sat Dec 14 11:51:15 2013 -0800
  980. +++ b/src/share/vm/classfile/dictionary.hpp Mon Apr 28 13:12:30 2014 -0700
  981. @@ -73,6 +73,10 @@
  982. void add_klass(Symbol* class_name, Handle class_loader,KlassHandle obj);
  983. + bool update_klass(int index, unsigned int hash, Symbol* name, Handle loader, KlassHandle k, KlassHandle old_class);
  984. +
  985. + void rollback_redefinition();
  986. +
  987. klassOop find_class(int index, unsigned int hash,
  988. Symbol* name, Handle loader);
  989. @@ -89,6 +93,7 @@
  990. void classes_do(void f(klassOop, TRAPS), TRAPS);
  991. void classes_do(void f(klassOop, oop));
  992. void classes_do(void f(klassOop, oop, TRAPS), TRAPS);
  993. + void classes_do(ObjectClosure *closure);
  994. void methods_do(void f(methodOop));
  995. @@ -105,6 +110,7 @@
  996. bool do_unloading(BoolObjectClosure* is_alive);
  997. // Protection domains
  998. + static klassOop intercept_for_version(klassOop k);
  999. klassOop find(int index, unsigned int hash, Symbol* name,
  1000. Handle loader, Handle protection_domain, TRAPS);
  1001. bool is_valid_protection_domain(int index, unsigned int hash,
  1002. diff -r 6c6a2299029a src/share/vm/classfile/javaClasses.cpp
  1003. --- a/src/share/vm/classfile/javaClasses.cpp Sat Dec 14 11:51:15 2013 -0800
  1004. +++ b/src/share/vm/classfile/javaClasses.cpp Mon Apr 28 13:12:30 2014 -0700
  1005. @@ -1798,7 +1798,7 @@
  1006. klassOop klass = SystemDictionary::reflect_Method_klass();
  1007. // This class is eagerly initialized during VM initialization, since we keep a refence
  1008. // to one of the methods
  1009. - assert(instanceKlass::cast(klass)->is_initialized(), "must be initialized");
  1010. + assert(instanceKlass::cast(klass)->is_initialized() || klass->klass_part()->old_version() != NULL, "must be initialized");
  1011. return instanceKlass::cast(klass)->allocate_instance_handle(CHECK_NH);
  1012. }
  1013. diff -r 6c6a2299029a src/share/vm/classfile/javaClasses.hpp
  1014. --- a/src/share/vm/classfile/javaClasses.hpp Sat Dec 14 11:51:15 2013 -0800
  1015. +++ b/src/share/vm/classfile/javaClasses.hpp Mon Apr 28 13:12:30 2014 -0700
  1016. @@ -213,7 +213,6 @@
  1017. class java_lang_Class : AllStatic {
  1018. friend class VMStructs;
  1019. -
  1020. private:
  1021. // The fake offsets are added by the class loader when java.lang.Class is loaded
  1022. diff -r 6c6a2299029a src/share/vm/classfile/loaderConstraints.cpp
  1023. --- a/src/share/vm/classfile/loaderConstraints.cpp Sat Dec 14 11:51:15 2013 -0800
  1024. +++ b/src/share/vm/classfile/loaderConstraints.cpp Mon Apr 28 13:12:30 2014 -0700
  1025. @@ -449,7 +449,7 @@
  1026. if (k != NULL) {
  1027. // We found the class in the system dictionary, so we should
  1028. // make sure that the klassOop matches what we already have.
  1029. - guarantee(k == probe->klass(), "klass should be in dictionary");
  1030. + guarantee(k == probe->klass()->klass_part()->newest_version(), "klass should be in dictionary");
  1031. } else {
  1032. // If we don't find the class in the system dictionary, it
  1033. // has to be in the placeholders table.
  1034. diff -r 6c6a2299029a src/share/vm/classfile/loaderConstraints.hpp
  1035. --- a/src/share/vm/classfile/loaderConstraints.hpp Sat Dec 14 11:51:15 2013 -0800
  1036. +++ b/src/share/vm/classfile/loaderConstraints.hpp Mon Apr 28 13:12:30 2014 -0700
  1037. @@ -106,7 +106,7 @@
  1038. klassOop klass() { return literal(); }
  1039. klassOop* klass_addr() { return literal_addr(); }
  1040. - void set_klass(klassOop k) { set_literal(k); }
  1041. + void set_klass(klassOop k) { set_literal(k); assert(k == NULL || !k->klass_part()->is_redefining(), "just checking"); }
  1042. LoaderConstraintEntry* next() {
  1043. return (LoaderConstraintEntry*)HashtableEntry<klassOop, mtClass>::next();
  1044. diff -r 6c6a2299029a src/share/vm/classfile/systemDictionary.cpp
  1045. --- a/src/share/vm/classfile/systemDictionary.cpp Sat Dec 14 11:51:15 2013 -0800
  1046. +++ b/src/share/vm/classfile/systemDictionary.cpp Mon Apr 28 13:12:30 2014 -0700
  1047. @@ -157,6 +157,7 @@
  1048. // can return a null klass
  1049. klass = handle_resolution_exception(class_name, class_loader, protection_domain, throw_error, k_h, THREAD);
  1050. }
  1051. + assert(klass == NULL || klass->klass_part()->is_newest_version() || klass->klass_part()->newest_version()->klass_part()->is_redefining(), "must be");
  1052. return klass;
  1053. }
  1054. @@ -199,7 +200,8 @@
  1055. // Forwards to resolve_instance_class_or_null
  1056. klassOop SystemDictionary::resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS) {
  1057. - assert(!THREAD->is_Compiler_thread(),
  1058. + // DCEVM: Check if this relaxing of the condition is correct? Test case hs203t004 failing otherwise.
  1059. + assert(!THREAD->is_Compiler_thread() || JvmtiThreadState::state_for(JavaThread::current())->get_class_being_redefined() != NULL,
  1060. err_msg("can not load classes with compiler thread: class=%s, classloader=%s",
  1061. class_name->as_C_string(),
  1062. class_loader.is_null() ? "null" : class_loader->klass()->klass_part()->name()->as_C_string()));
  1063. @@ -961,6 +963,7 @@
  1064. instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
  1065. class_loader,
  1066. protection_domain,
  1067. + KlassHandle(),
  1068. host_klass,
  1069. cp_patches,
  1070. parsed_name,
  1071. @@ -1022,7 +1025,14 @@
  1072. Handle protection_domain,
  1073. ClassFileStream* st,
  1074. bool verify,
  1075. + KlassHandle old_class,
  1076. TRAPS) {
  1077. + bool redefine_classes_locked = false;
  1078. + if (!Thread::current()->redefine_classes_mutex()->owned_by_self()) {
  1079. + Thread::current()->redefine_classes_mutex()->lock();
  1080. + redefine_classes_locked = true;
  1081. + }
  1082. +
  1083. // Classloaders that support parallelism, e.g. bootstrap classloader,
  1084. // or all classloaders with UnsyncloadClass do not acquire lock here
  1085. bool DoObjectLock = true;
  1086. @@ -1050,9 +1060,14 @@
  1087. instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
  1088. class_loader,
  1089. protection_domain,
  1090. + old_class,
  1091. parsed_name,
  1092. verify,
  1093. THREAD);
  1094. + if (!old_class.is_null() && !k.is_null()) {
  1095. + k->set_redefining(true);
  1096. + k->set_old_version(old_class());
  1097. + }
  1098. const char* pkg = "java/";
  1099. if (!HAS_PENDING_EXCEPTION &&
  1100. @@ -1087,13 +1102,18 @@
  1101. // Add class just loaded
  1102. // If a class loader supports parallel classloading handle parallel define requests
  1103. // find_or_define_instance_class may return a different instanceKlass
  1104. - if (is_parallelCapable(class_loader)) {
  1105. + // (tw) TODO: for class redefinition the parallel version does not work, check if this is a problem?
  1106. + if (is_parallelCapable(class_loader) && old_class.is_null()) {
  1107. k = find_or_define_instance_class(class_name, class_loader, k, THREAD);
  1108. } else {
  1109. - define_instance_class(k, THREAD);
  1110. + define_instance_class(k, old_class, THREAD);
  1111. }
  1112. }
  1113. + if (redefine_classes_locked) {
  1114. + Thread::current()->redefine_classes_mutex()->unlock();
  1115. + }
  1116. +
  1117. // If parsing the class file or define_instance_class failed, we
  1118. // need to remove the placeholder added on our behalf. But we
  1119. // must make sure parsed_name is valid first (it won't be if we had
  1120. @@ -1122,7 +1142,7 @@
  1121. MutexLocker mu(SystemDictionary_lock, THREAD);
  1122. klassOop check = find_class(parsed_name, class_loader);
  1123. - assert(check == k(), "should be present in the dictionary");
  1124. + assert((check == k() && !k->is_redefining()) || (k->is_redefining() && check == k->old_version()), "should be present in the dictionary");
  1125. klassOop check2 = find_class(h_name, h_loader);
  1126. assert(check == check2, "name inconsistancy in SystemDictionary");
  1127. @@ -1349,7 +1369,11 @@
  1128. }
  1129. }
  1130. -void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) {
  1131. +void SystemDictionary::rollback_redefinition() {
  1132. + dictionary()->rollback_redefinition();
  1133. +}
  1134. +
  1135. +void SystemDictionary::define_instance_class(instanceKlassHandle k, KlassHandle old_class, TRAPS) {
  1136. Handle class_loader_h(THREAD, k->class_loader());
  1137. @@ -1376,13 +1400,23 @@
  1138. Symbol* name_h = k->name();
  1139. unsigned int d_hash = dictionary()->compute_hash(name_h, class_loader_h);
  1140. int d_index = dictionary()->hash_to_index(d_hash);
  1141. - check_constraints(d_index, d_hash, k, class_loader_h, true, CHECK);
  1142. +
  1143. + // DCEVM: Update version of the klassOop in the system dictionary
  1144. + // TODO: Check for thread safety!
  1145. + if (!old_class.is_null()) {
  1146. + bool ok = dictionary()->update_klass(d_index, d_hash, name_h, class_loader_h, k, old_class);
  1147. + assert (ok, "must have found old class and updated!");
  1148. + }
  1149. + check_constraints(d_index, d_hash, k, class_loader_h, old_class.is_null(), CHECK);
  1150. +
  1151. + if(!old_class.is_null() && TraceRedefineClasses >= 3){ tty->print_cr("Class has been updated!"); }
  1152. // Register class just loaded with class loader (placed in Vector)
  1153. // Note we do this before updating the dictionary, as this can
  1154. // fail with an OutOfMemoryError (if it does, we will *not* put this
  1155. // class in the dictionary and will not update the class hierarchy).
  1156. - if (k->class_loader() != NULL) {
  1157. + // (tw) Only register if not redefining a class.
  1158. + if (k->class_loader() != NULL && old_class.is_null()) {
  1159. methodHandle m(THREAD, Universe::loader_addClass_method());
  1160. JavaValue result(T_VOID);
  1161. JavaCallArguments args(class_loader_h);
  1162. @@ -1408,8 +1442,9 @@
  1163. }
  1164. k->eager_initialize(THREAD);
  1165. + // (tw) Only notify jvmti if not redefining a class.
  1166. // notify jvmti
  1167. - if (JvmtiExport::should_post_class_load()) {
  1168. + if (JvmtiExport::should_post_class_load() && old_class.is_null()) {
  1169. assert(THREAD->is_Java_thread(), "thread->is_Java_thread()");
  1170. JvmtiExport::post_class_load((JavaThread *) THREAD, k());
  1171. @@ -1482,7 +1517,7 @@
  1172. }
  1173. }
  1174. - define_instance_class(k, THREAD);
  1175. + define_instance_class(k, KlassHandle(), THREAD);
  1176. Handle linkage_exception = Handle(); // null handle
  1177. @@ -1612,6 +1647,14 @@
  1178. Universe::flush_dependents_on(k);
  1179. }
  1180. +// (tw) Remove from hierarchy - Undo add_to_hierarchy.
  1181. +void SystemDictionary::remove_from_hierarchy(instanceKlassHandle k) {
  1182. + assert(k.not_null(), "just checking");
  1183. +
  1184. + k->remove_from_sibling_list();
  1185. +
  1186. + // TODO: Remove from interfaces.
  1187. +}
  1188. // ----------------------------------------------------------------------------
  1189. // GC support
  1190. @@ -1701,7 +1744,8 @@
  1191. }
  1192. -void SystemDictionary::preloaded_oops_do(OopClosure* f) {
  1193. +// (tw) Iterate over all pre-loaded classes in the dictionary.
  1194. +void SystemDictionary::preloaded_classes_do(OopClosure *f) {
  1195. for (int k = (int)FIRST_WKID; k < (int)WKID_LIMIT; k++) {
  1196. f->do_oop((oop*) &_well_known_klasses[k]);
  1197. }
  1198. @@ -1715,6 +1759,23 @@
  1199. }
  1200. }
  1201. + // TODO: Check if we need to call FilterFieldsMap
  1202. +}
  1203. +
  1204. +void SystemDictionary::preloaded_oops_do(OopClosure* f) {
  1205. + for (int k = (int)FIRST_WKID; k < (int)WKID_LIMIT; k++) {
  1206. + f->do_oop((oop*) &_well_known_klasses[k]);
  1207. + }
  1208. +
  1209. + {
  1210. + for (int i = 0; i < T_VOID+1; i++) {
  1211. + if (_box_klasses[i] != NULL) {
  1212. + assert(i >= T_BOOLEAN, "checking");
  1213. + f->do_oop((oop*) &_box_klasses[i]);
  1214. + }
  1215. + }
  1216. + }
  1217. +
  1218. // The basic type mirrors would have already been processed in
  1219. // Universe::oops_do(), via a call to shared_oops_do(), so should
  1220. // not be processed again.
  1221. @@ -1733,6 +1794,11 @@
  1222. dictionary()->classes_do(f);
  1223. }
  1224. +// (tw) Iterate over all classes in the dictionary.
  1225. +void SystemDictionary::classes_do(ObjectClosure *closure) {
  1226. + dictionary()->classes_do(closure);
  1227. +}
  1228. +
  1229. // Added for initialize_itable_for_klass
  1230. // Just the classes from defining class loaders
  1231. // Don't iterate over placeholders
  1232. @@ -1869,7 +1935,9 @@
  1233. // Preload ref klasses and set reference types
  1234. instanceKlass::cast(WK_KLASS(Reference_klass))->set_reference_type(REF_OTHER);
  1235. - instanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));
  1236. +
  1237. + // (tw) This is now done in parseClassFile in order to support class redefinition
  1238. + // instanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));
  1239. initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(PhantomReference_klass), scan, CHECK);
  1240. instanceKlass::cast(WK_KLASS(SoftReference_klass))->set_reference_type(REF_SOFT);
  1241. @@ -1955,7 +2023,11 @@
  1242. // also holds array classes
  1243. assert(check->klass_part()->oop_is_instance(), "noninstance in systemdictionary");
  1244. - if ((defining == true) || (k() != check)) {
  1245. + if ((defining == true) && ((k() != check) && k->old_version() != check)) {
  1246. + ResourceMark rm(Thread::current());
  1247. + 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());
  1248. + k()->print();
  1249. + check->print();
  1250. linkage_error = "loader (instance of %s): attempted duplicate class "
  1251. "definition for name: \"%s\"";
  1252. } else {
  1253. diff -r 6c6a2299029a src/share/vm/classfile/systemDictionary.hpp
  1254. --- a/src/share/vm/classfile/systemDictionary.hpp Sat Dec 14 11:51:15 2013 -0800
  1255. +++ b/src/share/vm/classfile/systemDictionary.hpp Mon Apr 28 13:12:30 2014 -0700
  1256. @@ -268,7 +268,7 @@
  1257. // Resolve from stream (called by jni_DefineClass and JVM_DefineClass)
  1258. static klassOop resolve_from_stream(Symbol* class_name, Handle class_loader,
  1259. Handle protection_domain,
  1260. - ClassFileStream* st, bool verify, TRAPS);
  1261. + ClassFileStream* st, bool verify, KlassHandle old_class, TRAPS);
  1262. // Lookup an already loaded class. If not found NULL is returned.
  1263. static klassOop find(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS);
  1264. @@ -309,6 +309,8 @@
  1265. // Iterate over all klasses in dictionary
  1266. // Just the classes from defining class loaders
  1267. static void classes_do(void f(klassOop));
  1268. + static void classes_do(ObjectClosure *closure);
  1269. + static void preloaded_classes_do(OopClosure *closure);
  1270. // Added for initialize_itable_for_klass to handle exceptions
  1271. static void classes_do(void f(klassOop, TRAPS), TRAPS);
  1272. // All classes, and their class loaders
  1273. @@ -415,6 +417,8 @@
  1274. initialize_wk_klasses_until((WKID) limit, start_id, THREAD);
  1275. }
  1276. + static void rollback_redefinition();
  1277. +
  1278. public:
  1279. #define WK_KLASS_DECLARE(name, symbol, option) \
  1280. static klassOop name() { return check_klass_##option(_well_known_klasses[WK_KLASS_ENUM_NAME(name)]); }
  1281. @@ -596,7 +600,7 @@
  1282. // after waiting, but before reentering SystemDictionary_lock
  1283. // to preserve lock order semantics.
  1284. static void double_lock_wait(Handle lockObject, TRAPS);
  1285. - static void define_instance_class(instanceKlassHandle k, TRAPS);
  1286. + static void define_instance_class(instanceKlassHandle k, KlassHandle old_class, TRAPS);
  1287. static instanceKlassHandle find_or_define_instance_class(Symbol* class_name,
  1288. Handle class_loader,
  1289. instanceKlassHandle k, TRAPS);
  1290. @@ -615,12 +619,17 @@
  1291. // Setup link to hierarchy
  1292. static void add_to_hierarchy(instanceKlassHandle k, TRAPS);
  1293. +public:
  1294. +
  1295. + // Remove link to hierarchy
  1296. + static void remove_from_hierarchy(instanceKlassHandle k);
  1297. +
  1298. +private:
  1299. // event based tracing
  1300. static void post_class_load_event(TracingTime start_time, instanceKlassHandle k,
  1301. Handle initiating_loader);
  1302. static void post_class_unload_events(BoolObjectClosure* is_alive);
  1303. -private:
  1304. // We pass in the hashtable index so we can calculate it outside of
  1305. // the SystemDictionary_lock.
  1306. diff -r 6c6a2299029a src/share/vm/classfile/verifier.cpp
  1307. --- a/src/share/vm/classfile/verifier.cpp Sat Dec 14 11:51:15 2013 -0800
  1308. +++ b/src/share/vm/classfile/verifier.cpp Mon Apr 28 13:12:30 2014 -0700
  1309. @@ -106,7 +106,7 @@
  1310. return !need_verify;
  1311. }
  1312. -bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, TRAPS) {
  1313. +bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, bool may_use_old_verifier, TRAPS) {
  1314. HandleMark hm;
  1315. ResourceMark rm(THREAD);
  1316. @@ -117,7 +117,8 @@
  1317. const char* klassName = klass->external_name();
  1318. bool can_failover = FailOverToOldVerifier &&
  1319. - klass->major_version() < NOFAILOVER_MAJOR_VERSION;
  1320. + klass->major_version() < NOFAILOVER_MAJOR_VERSION &&
  1321. + may_use_old_verifier;
  1322. // If the class should be verified, first see if we can use the split
  1323. // verifier. If not, or if verification fails and FailOverToOldVerifier
  1324. @@ -138,6 +139,7 @@
  1325. tty->print_cr(
  1326. "Fail over class verification to old verifier for: %s", klassName);
  1327. }
  1328. + assert(may_use_old_verifier, "");
  1329. exception_name = inference_verify(
  1330. klass, message_buffer, message_buffer_len, THREAD);
  1331. }
  1332. @@ -145,6 +147,7 @@
  1333. exception_message = split_verifier.exception_message();
  1334. }
  1335. } else {
  1336. + assert(may_use_old_verifier, "");
  1337. exception_name = inference_verify(
  1338. klass, message_buffer, message_buffer_len, THREAD);
  1339. }
  1340. @@ -159,6 +162,9 @@
  1341. }
  1342. tty->print_cr("End class verification for: %s", klassName);
  1343. }
  1344. + } else if (TraceClassInitialization) {
  1345. + // (tw) Output not verified classes
  1346. + tty->print_cr("Class %s was not verified", klassName);
  1347. }
  1348. if (HAS_PENDING_EXCEPTION) {
  1349. @@ -210,7 +216,7 @@
  1350. // NOTE: this is called too early in the bootstrapping process to be
  1351. // guarded by Universe::is_gte_jdk14x_version()/UseNewReflection.
  1352. (refl_magic_klass == NULL ||
  1353. - !klass->is_subtype_of(refl_magic_klass) ||
  1354. + !(klass->is_subtype_of(refl_magic_klass) || klass->is_subtype_of(refl_magic_klass->klass_part()->newest_version())) ||
  1355. VerifyReflectionBytecodes)
  1356. );
  1357. }
  1358. @@ -517,7 +523,7 @@
  1359. ClassVerifier::ClassVerifier(
  1360. instanceKlassHandle klass, TRAPS)
  1361. - : _thread(THREAD), _exception_type(NULL), _message(NULL), _klass(klass) {
  1362. + : _thread(THREAD), _exception_type(NULL), _message(NULL), _klass(klass->newest_version()), _klass_to_verify(klass) {
  1363. _this_type = VerificationType::reference_type(klass->name());
  1364. // Create list to hold symbols in reference area.
  1365. _symbols = new GrowableArray<Symbol*>(100, 0, NULL);
  1366. @@ -547,7 +553,7 @@
  1367. _klass->external_name());
  1368. }
  1369. - objArrayHandle methods(THREAD, _klass->methods());
  1370. + objArrayHandle methods(THREAD, _klass_to_verify->methods());
  1371. int num_methods = methods->length();
  1372. for (int index = 0; index < num_methods; index++) {
  1373. @@ -2444,7 +2450,10 @@
  1374. VerificationType stack_object_type =
  1375. current_frame->pop_stack(ref_class_type, CHECK_VERIFY(this));
  1376. if (current_type() != stack_object_type) {
  1377. - assert(cp->cache() == NULL, "not rewritten yet");
  1378. +
  1379. + // (tw) TODO: Check if relaxing the following assertion is correct. For class redefinition we might call the verifier twice.
  1380. + //assert(cp->cache() == NULL, "not rewritten yet");
  1381. +
  1382. Symbol* ref_class_name =
  1383. cp->klass_name_at(cp->klass_ref_index_at(index));
  1384. // See the comments in verify_field_instructions() for
  1385. diff -r 6c6a2299029a src/share/vm/classfile/verifier.hpp
  1386. --- a/src/share/vm/classfile/verifier.hpp Sat Dec 14 11:51:15 2013 -0800
  1387. +++ b/src/share/vm/classfile/verifier.hpp Mon Apr 28 13:12:30 2014 -0700
  1388. @@ -47,7 +47,7 @@
  1389. * Otherwise, no exception is thrown and the return indicates the
  1390. * error.
  1391. */
  1392. - static bool verify(instanceKlassHandle klass, Mode mode, bool should_verify_class, TRAPS);
  1393. + static bool verify(instanceKlassHandle klass, Mode mode, bool should_verify_class, bool may_use_old_verifier, TRAPS);
  1394. // Return false if the class is loaded by the bootstrap loader,
  1395. // or if defineClass was called requesting skipping verification
  1396. @@ -256,7 +256,10 @@
  1397. ErrorContext _error_context; // contains information about an error
  1398. +public:
  1399. void verify_method(methodHandle method, TRAPS);
  1400. +
  1401. +private:
  1402. char* generate_code_data(methodHandle m, u4 code_length, TRAPS);
  1403. void verify_exception_handler_table(u4 code_length, char* code_data,
  1404. int& min, int& max, TRAPS);
  1405. @@ -329,6 +332,7 @@
  1406. VerificationType object_type() const;
  1407. + instanceKlassHandle _klass_to_verify;
  1408. instanceKlassHandle _klass; // the class being verified
  1409. methodHandle _method; // current method being verified
  1410. VerificationType _this_type; // the verification type of the current class
  1411. diff -r 6c6a2299029a src/share/vm/classfile/vmSymbols.hpp
  1412. --- a/src/share/vm/classfile/vmSymbols.hpp Sat Dec 14 11:51:15 2013 -0800
  1413. +++ b/src/share/vm/classfile/vmSymbols.hpp Mon Apr 28 13:12:30 2014 -0700
  1414. @@ -138,6 +138,10 @@
  1415. template(tag_annotation_default, "AnnotationDefault") \
  1416. template(tag_enclosing_method, "EnclosingMethod") \
  1417. template(tag_bootstrap_methods, "BootstrapMethods") \
  1418. + template(tag_static_field_redefinition_policy, "StaticFieldRedefinitionPolicy") \
  1419. + template(tag_field_redefinition_policy, "FieldRedefinitionPolicy") \
  1420. + template(tag_method_redefinition_policy, "MethodRedefinitionPolicy") \
  1421. + template(tag_code_sections, "CodeSections") \
  1422. \
  1423. /* exception klasses: at least all exceptions thrown by the VM have entries here */ \
  1424. template(java_lang_ArithmeticException, "java/lang/ArithmeticException") \
  1425. @@ -377,6 +381,10 @@
  1426. template(oop_size_name, "oop_size") \
  1427. template(static_oop_field_count_name, "static_oop_field_count") \
  1428. \
  1429. + /* mutator in case of class redefinition */ \
  1430. + template(static_transformer_name, "$staticTransformer") \
  1431. + template(transformer_name, "$transformer") \
  1432. + \
  1433. /* non-intrinsic name/signature pairs: */ \
  1434. template(register_method_name, "register") \
  1435. do_alias(register_method_signature, object_void_signature) \
  1436. diff -r 6c6a2299029a src/share/vm/compiler/compileBroker.cpp
  1437. --- a/src/share/vm/compiler/compileBroker.cpp Sat Dec 14 11:51:15 2013 -0800
  1438. +++ b/src/share/vm/compiler/compileBroker.cpp Mon Apr 28 13:12:30 2014 -0700
  1439. @@ -1181,6 +1181,14 @@
  1440. int comp_level,
  1441. methodHandle hot_method, int hot_count,
  1442. const char* comment, Thread* THREAD) {
  1443. + JavaThread* thread = JavaThread::current();
  1444. + if (thread->is_Compiler_thread() && thread->as_CompilerThread()->should_bailout()) {
  1445. + return NULL; // FIXME: DCEVM: should we do something else?
  1446. + }
  1447. + if (instanceKlass::cast(method->method_holder())->is_not_initialized()) {
  1448. + return NULL; // FIXME: DCEVM: how should we avoid this?
  1449. + }
  1450. +
  1451. // make sure arguments make sense
  1452. assert(method->method_holder()->klass_part()->oop_is_instance(), "not an instance method");
  1453. assert(osr_bci == InvocationEntryBci || (0 <= osr_bci && osr_bci < method->code_size()), "bci out of range");
  1454. @@ -1260,6 +1268,7 @@
  1455. }
  1456. // RedefineClasses() has replaced this method; just return
  1457. + // (tw) This is important for the new version of hotswapping: Old code will only execute properly in the interpreter!
  1458. if (method->is_old()) {
  1459. return NULL;
  1460. }
  1461. @@ -1592,6 +1601,8 @@
  1462. // Never compile a method if breakpoints are present in it
  1463. if (method()->number_of_breakpoints() == 0) {
  1464. + thread->compilation_mutex()->lock();
  1465. + thread->set_should_bailout(false);
  1466. // Compile the method.
  1467. if ((UseCompiler || AlwaysCompileLoopMethods) && CompileBroker::should_compile_new_jobs()) {
  1468. #ifdef COMPILER1
  1469. @@ -1615,6 +1626,7 @@
  1470. // After compilation is disabled, remove remaining methods from queue
  1471. method->clear_queued_for_compilation();
  1472. }
  1473. + thread->compilation_mutex()->unlock();
  1474. }
  1475. }
  1476. }
  1477. @@ -2164,3 +2176,15 @@
  1478. st->cr();
  1479. #endif
  1480. }
  1481. +
  1482. +// (tw) Clean up compiler interface after a class redefinition step
  1483. +void CompileBroker::cleanup_after_redefinition() {
  1484. + int num_threads = _method_threads->length();
  1485. +
  1486. + ciObjectFactory::sort_ci_objects(ciObjectFactory::_shared_ci_objects);
  1487. + for (int i=0; i<num_threads; i++) {
  1488. + if (_method_threads->at(i)->env() != NULL && _method_threads->at(i)->env() != (ciEnv *)badAddress) {
  1489. + _method_threads->at(i)->env()->cleanup_after_redefinition();
  1490. + }
  1491. + }
  1492. +}
  1493. diff -r 6c6a2299029a src/share/vm/compiler/compileBroker.hpp
  1494. --- a/src/share/vm/compiler/compileBroker.hpp Sat Dec 14 11:51:15 2013 -0800
  1495. +++ b/src/share/vm/compiler/compileBroker.hpp Mon Apr 28 13:12:30 2014 -0700
  1496. @@ -408,6 +408,7 @@
  1497. static void print_compiler_threads_on(outputStream* st);
  1498. + static void cleanup_after_redefinition();
  1499. static int get_total_compile_count() { return _total_compile_count; }
  1500. static int get_total_bailout_count() { return _total_bailout_count; }
  1501. static int get_total_invalidated_count() { return _total_invalidated_count; }
  1502. diff -r 6c6a2299029a src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
  1503. --- a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp Sat Dec 14 11:51:15 2013 -0800
  1504. +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp Mon Apr 28 13:12:30 2014 -0700
  1505. @@ -162,6 +162,13 @@
  1506. }
  1507. }
  1508. +
  1509. +HeapWord* CompactibleFreeListSpace::forward_compact_top(size_t size,
  1510. + CompactPoint* cp, HeapWord* compact_top) {
  1511. + ShouldNotReachHere();
  1512. + return NULL;
  1513. +}
  1514. +
  1515. // Like CompactibleSpace forward() but always calls cross_threshold() to
  1516. // update the block offset table. Removed initialize_threshold call because
  1517. // CFLS does not use a block offset array for contiguous spaces.
  1518. diff -r 6c6a2299029a src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
  1519. --- a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp Sat Dec 14 11:51:15 2013 -0800
  1520. +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp Mon Apr 28 13:12:30 2014 -0700
  1521. @@ -149,6 +149,7 @@
  1522. // Support for compacting cms
  1523. HeapWord* cross_threshold(HeapWord* start, HeapWord* end);
  1524. + HeapWord* forward_compact_top(size_t size, CompactPoint* cp, HeapWord* compact_top);
  1525. HeapWord* forward(oop q, size_t size, CompactPoint* cp, HeapWord* compact_top);
  1526. // Initialization helpers.
  1527. diff -r 6c6a2299029a src/share/vm/gc_implementation/shared/markSweep.cpp
  1528. --- a/src/share/vm/gc_implementation/shared/markSweep.cpp Sat Dec 14 11:51:15 2013 -0800
  1529. +++ b/src/share/vm/gc_implementation/shared/markSweep.cpp Mon Apr 28 13:12:30 2014 -0700
  1530. @@ -32,6 +32,8 @@
  1531. #include "oops/objArrayKlass.inline.hpp"
  1532. #include "oops/oop.inline.hpp"
  1533. +GrowableArray<oop>* MarkSweep::_rescued_oops = NULL;
  1534. +
  1535. Stack<oop, mtGC> MarkSweep::_marking_stack;
  1536. Stack<DataLayout*, mtGC> MarkSweep::_revisit_mdo_stack;
  1537. Stack<Klass*, mtGC> MarkSweep::_revisit_klass_stack;
  1538. @@ -357,3 +359,86 @@
  1539. }
  1540. #endif
  1541. +
  1542. +// (tw) Copy the rescued objects to their destination address after compaction.
  1543. +void MarkSweep::copy_rescued_objects_back() {
  1544. +
  1545. + if (_rescued_oops != NULL) {
  1546. +
  1547. + for (int i=0; i<_rescued_oops->length(); i++) {
  1548. + oop rescued_obj = _rescued_oops->at(i);
  1549. +
  1550. + int size = rescued_obj->size();
  1551. + oop new_obj = rescued_obj->forwardee();
  1552. +
  1553. + if (rescued_obj->blueprint()->new_version() != NULL) {
  1554. + MarkSweep::update_fields(rescued_obj, new_obj);
  1555. + } else {
  1556. + Copy::aligned_disjoint_words((HeapWord*)rescued_obj, (HeapWord*)new_obj, size);
  1557. + }
  1558. +
  1559. + FREE_RESOURCE_ARRAY(HeapWord, rescued_obj, size);
  1560. +
  1561. + new_obj->init_mark();
  1562. + assert(new_obj->is_oop(), "must be a valid oop");
  1563. + }
  1564. + _rescued_oops->clear();
  1565. + _rescued_oops = NULL;
  1566. + }
  1567. +}
  1568. +
  1569. +// (tw) Update instances of a class whose fields changed.
  1570. +void MarkSweep::update_fields(oop q, oop new_location) {
  1571. +
  1572. + assert(q->blueprint()->new_version() != NULL, "class of old object must have new version");
  1573. +
  1574. + klassOop old_klass_oop = q->klass();
  1575. + klassOop new_klass_oop = q->blueprint()->new_version();
  1576. +
  1577. + instanceKlass *old_klass = instanceKlass::cast(old_klass_oop);
  1578. + instanceKlass *new_klass = instanceKlass::cast(new_klass_oop);
  1579. +
  1580. + int size = q->size_given_klass(old_klass);
  1581. + int new_size = q->size_given_klass(new_klass);
  1582. +
  1583. + oop tmp_obj = q;
  1584. +
  1585. + if (new_klass_oop->klass_part()->is_copying_backwards()) {
  1586. + if (((HeapWord *)q >= (HeapWord *)new_location && (HeapWord *)q < (HeapWord *)new_location + new_size) ||
  1587. + ((HeapWord *)new_location >= (HeapWord *)q && (HeapWord *)new_location < (HeapWord *)q + size)) {
  1588. + tmp_obj = (oop)resource_allocate_bytes(size * HeapWordSize);
  1589. + Copy::aligned_disjoint_words((HeapWord*)q, (HeapWord*)tmp_obj, size);
  1590. + }
  1591. + }
  1592. +
  1593. + int *cur = new_klass_oop->klass_part()->update_information();
  1594. +
  1595. + tmp_obj->set_klass_no_check(new_klass_oop);
  1596. +
  1597. + if (cur == NULL) {
  1598. + assert(size == new_size, "just checking");
  1599. + Copy::conjoint_words(((HeapWord *)tmp_obj), ((HeapWord *)new_location), size);
  1600. + } else {
  1601. + int destOffset = 0;
  1602. + while (*cur != 0) {
  1603. + if (*cur > 0) {
  1604. + int size = *cur;
  1605. + cur++;
  1606. + int offset = *cur;
  1607. + Copy::conjoint_jbytes(((char *)tmp_obj) + offset, ((char *)new_location) + destOffset, size);
  1608. + destOffset += size;
  1609. + cur++;
  1610. + } else {
  1611. + assert(*cur < 0, "");
  1612. + int skip = -*cur;
  1613. + Copy::fill_to_bytes(((char*)new_location) + destOffset, skip, 0);
  1614. + destOffset += skip;
  1615. + cur++;
  1616. + }
  1617. + }
  1618. + }
  1619. +
  1620. + if (tmp_obj != q) {
  1621. + FREE_RESOURCE_ARRAY(HeapWord, tmp_obj, size);
  1622. + }
  1623. +}
  1624. diff -r 6c6a2299029a src/share/vm/gc_implementation/shared/markSweep.hpp
  1625. --- a/src/share/vm/gc_implementation/shared/markSweep.hpp Sat Dec 14 11:51:15 2013 -0800
  1626. +++ b/src/share/vm/gc_implementation/shared/markSweep.hpp Mon Apr 28 13:12:30 2014 -0700
  1627. @@ -117,8 +117,12 @@
  1628. friend class AdjustPointerClosure;
  1629. friend class KeepAliveClosure;
  1630. friend class VM_MarkSweep;
  1631. + friend class GenMarkSweep;
  1632. friend void marksweep_init();
  1633. +public:
  1634. + static GrowableArray<oop>* _rescued_oops;
  1635. +
  1636. //
  1637. // Vars
  1638. //
  1639. @@ -208,6 +212,8 @@
  1640. template <class T> static inline void mark_and_push(T* p);
  1641. static inline void push_objarray(oop obj, size_t index);
  1642. + static void copy_rescued_objects_back();
  1643. + static void update_fields(oop q, oop new_location);
  1644. static void follow_stack(); // Empty marking stack.
  1645. static void preserve_mark(oop p, markOop mark);
  1646. diff -r 6c6a2299029a src/share/vm/interpreter/interpreterRuntime.cpp
  1647. --- a/src/share/vm/interpreter/interpreterRuntime.cpp Sat Dec 14 11:51:15 2013 -0800
  1648. +++ b/src/share/vm/interpreter/interpreterRuntime.cpp Mon Apr 28 13:12:30 2014 -0700
  1649. @@ -402,7 +402,7 @@
  1650. assert(h_exception.not_null(), "NULL exceptions should be handled by athrow");
  1651. assert(h_exception->is_oop(), "just checking");
  1652. // Check that exception is a subclass of Throwable, otherwise we have a VerifyError
  1653. - if (!(h_exception->is_a(SystemDictionary::Throwable_klass()))) {
  1654. + if (!(h_exception->is_a(SystemDictionary::Throwable_klass()->klass_part()->newest_version())) && !(h_exception->is_a(SystemDictionary::Throwable_klass()))) {
  1655. if (ExitVMOnVerifyError) vm_exit(-1);
  1656. ShouldNotReachHere();
  1657. }
  1658. @@ -656,6 +656,82 @@
  1659. JvmtiExport::post_raw_breakpoint(thread, method, bcp);
  1660. IRT_END
  1661. +// (tw) Correctly resolve method when running old code.
  1662. +IRT_ENTRY(void, InterpreterRuntime::forward_method(JavaThread *thread))
  1663. + {
  1664. + MonitorLockerEx ml(RedefinitionSync_lock);
  1665. + while (Threads::wait_at_instrumentation_entry()) {
  1666. + ml.wait();
  1667. + }
  1668. + }
  1669. + frame f = last_frame(thread);
  1670. + methodOop m = f.interpreter_frame_method();
  1671. + methodOop forward_method = m->forward_method();
  1672. + if (forward_method != NULL) {
  1673. + int bci = f.interpreter_frame_bci();
  1674. +
  1675. + if (TraceRedefineClasses >= 3) {
  1676. + 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));
  1677. + }
  1678. +
  1679. + int next_bci = bci - 1;
  1680. + // First try bci before NOP.
  1681. + if (!m->is_in_code_section(next_bci)) {
  1682. + // Try bci after NOP.
  1683. + next_bci = bci + 1;
  1684. + if (!m->is_in_code_section(next_bci)) return;
  1685. + }
  1686. +
  1687. + int new_bci = m->calculate_forward_bci(next_bci, forward_method);
  1688. + if (TraceRedefineClasses >= 2) {
  1689. + 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);
  1690. + }
  1691. + RegisterMap reg_map(thread);
  1692. + vframe* vf = vframe::new_vframe(&f, &reg_map, thread);
  1693. + interpretedVFrame *iframe = (interpretedVFrame *)vf;
  1694. + iframe->set_method(forward_method, new_bci - 1);
  1695. + }
  1696. +IRT_END
  1697. +
  1698. +// (tw) Correctly resolve method when running old code.
  1699. +IRT_ENTRY(void, InterpreterRuntime::find_correct_method(JavaThread *thread, oopDesc* receiverOop, int vTableIndex))
  1700. + // extract receiver from the outgoing argument list if necessary
  1701. + Handle receiver(thread, receiverOop);
  1702. +
  1703. + // TODO: Check for invokeinterface!
  1704. + Bytecodes::Code bytecode = Bytecodes::_invokevirtual;
  1705. +
  1706. + int method_holder_revision_number = method(thread)->method_holder()->klass_part()->revision_number();
  1707. + klassOop klass = receiverOop->klass();
  1708. + while (klass->klass_part()->revision_number() > method_holder_revision_number) {
  1709. + klass = klass->klass_part()->old_version();
  1710. + }
  1711. +
  1712. + // TODO: Check for correctness if different vtable indices in different versions?
  1713. +
  1714. + methodOop method = ((instanceKlass *)klass->klass_part())->method_at_vtable(vTableIndex);
  1715. + thread->set_vm_result(method);
  1716. +IRT_END
  1717. +
  1718. +// Correctly resolve interface method when running old code.
  1719. +IRT_ENTRY(void, InterpreterRuntime::find_correct_interface_method(JavaThread *thread, oopDesc* receiverOop, oopDesc* interface_klass, int vTableIndex))
  1720. +
  1721. + // extract receiver from the outgoing argument list if necessary
  1722. + Handle receiver(thread, receiverOop);
  1723. +
  1724. + // TODO: Check for invokeinterface!
  1725. + Bytecodes::Code bytecode = Bytecodes::_invokevirtual;
  1726. +
  1727. + int method_holder_revision_number = method(thread)->method_holder()->klass_part()->revision_number();
  1728. + klassOop klass = receiverOop->klass();
  1729. + while (klass->klass_part()->revision_number() > method_holder_revision_number) {
  1730. + klass = klass->klass_part()->old_version();
  1731. + }
  1732. +
  1733. + methodOop method = ((instanceKlass *)klass->klass_part())->method_at_itable((klassOop)interface_klass, vTableIndex, THREAD);
  1734. + thread->set_vm_result(method);
  1735. +IRT_END
  1736. +
  1737. IRT_ENTRY(void, InterpreterRuntime::resolve_invoke(JavaThread* thread, Bytecodes::Code bytecode)) {
  1738. // extract receiver from the outgoing argument list if necessary
  1739. Handle receiver(thread, NULL);
  1740. @@ -684,6 +760,10 @@
  1741. if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
  1742. int retry_count = 0;
  1743. while (info.resolved_method()->is_old()) {
  1744. + // (tw) If we are executing an old method, this is OK!
  1745. + if (method(thread)->is_old()) {
  1746. + break;
  1747. + }
  1748. // It is very unlikely that method is redefined more than 100 times
  1749. // in the middle of resolve. If it is looping here more than 100 times
  1750. // means then there could be a bug here.
  1751. diff -r 6c6a2299029a src/share/vm/interpreter/interpreterRuntime.hpp
  1752. --- a/src/share/vm/interpreter/interpreterRuntime.hpp Sat Dec 14 11:51:15 2013 -0800
  1753. +++ b/src/share/vm/interpreter/interpreterRuntime.hpp Mon Apr 28 13:12:30 2014 -0700
  1754. @@ -140,6 +140,9 @@
  1755. static void post_method_entry(JavaThread *thread);
  1756. static void post_method_exit (JavaThread *thread);
  1757. static int interpreter_contains(address pc);
  1758. + static void forward_method(JavaThread *thread);
  1759. + static void find_correct_method(JavaThread *thread, oopDesc* receiver, int vTableIndex);
  1760. + static void find_correct_interface_method(JavaThread *thread, oopDesc* receiver, oopDesc* interface_klass, int vTableIndex);
  1761. // Native signature handlers
  1762. static void prepare_native_call(JavaThread* thread, methodOopDesc* method);
  1763. diff -r 6c6a2299029a src/share/vm/interpreter/linkResolver.cpp
  1764. --- a/src/share/vm/interpreter/linkResolver.cpp Sat Dec 14 11:51:15 2013 -0800
  1765. +++ b/src/share/vm/interpreter/linkResolver.cpp Mon Apr 28 13:12:30 2014 -0700
  1766. @@ -153,8 +153,8 @@
  1767. // Klass resolution
  1768. void LinkResolver::check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS) {
  1769. - if (!Reflection::verify_class_access(ref_klass->as_klassOop(),
  1770. - sel_klass->as_klassOop(),
  1771. + if (!Reflection::verify_class_access(ref_klass->as_klassOop()->klass_part()->newest_version(),
  1772. + sel_klass->as_klassOop()->klass_part()->newest_version(),
  1773. true)) {
  1774. ResourceMark rm(THREAD);
  1775. Exceptions::fthrow(
  1776. @@ -338,7 +338,7 @@
  1777. // We'll check for the method name first, as that's most likely
  1778. // to be false (so we'll short-circuit out of these tests).
  1779. if (sel_method->name() == vmSymbols::clone_name() &&
  1780. - sel_klass() == SystemDictionary::Object_klass() &&
  1781. + sel_klass()->klass_part()->newest_version() == SystemDictionary::Object_klass()->klass_part()->newest_version() &&
  1782. resolved_klass->oop_is_array()) {
  1783. // We need to change "protected" to "public".
  1784. assert(flags.is_protected(), "clone not protected?");
  1785. @@ -404,6 +404,156 @@
  1786. }
  1787. }
  1788. +
  1789. +void LinkResolver::lookup_method(methodHandle& resolved_method, KlassHandle resolved_klass,
  1790. + Symbol* method_name, Symbol* method_signature, bool is_interface, KlassHandle current_klass, TRAPS) {
  1791. +
  1792. + // Interface method lookup?
  1793. + if (is_interface) {
  1794. +
  1795. + // lookup method in this interface or its super, java.lang.Object
  1796. + lookup_instance_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1797. +
  1798. + if (resolved_method.is_null()) {
  1799. + // lookup method in all the super-interfaces
  1800. + lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1801. + }
  1802. +
  1803. + // Other methods
  1804. + } else {
  1805. + Handle nested_exception;
  1806. +
  1807. + // 2. lookup method in resolved klass and its super klasses
  1808. + lookup_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1809. +
  1810. + if (resolved_method.is_null()) { // not found in the class hierarchy
  1811. + // 3. lookup method in all the interfaces implemented by the resolved klass
  1812. + lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1813. +
  1814. + if (resolved_method.is_null()) {
  1815. + // JSR 292: see if this is an implicitly generated method MethodHandle.linkToVirtual(*...), etc
  1816. + lookup_polymorphic_method(resolved_method, resolved_klass, method_name, method_signature,
  1817. + current_klass, (Handle*)NULL, (Handle*)NULL, THREAD);
  1818. + if (HAS_PENDING_EXCEPTION) {
  1819. + nested_exception = Handle(THREAD, PENDING_EXCEPTION);
  1820. + CLEAR_PENDING_EXCEPTION;
  1821. + }
  1822. + }
  1823. + }
  1824. + }
  1825. +}
  1826. +
  1827. +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) {
  1828. +
  1829. + // First attempt unversioned
  1830. + sel_klass = KlassHandle(Thread::current(), instanceKlass::cast(resolved_klass())->find_field(field_name, field_sig, &fd));
  1831. +
  1832. +
  1833. + if (!current_klass.is_null() && !current_klass->is_newest_version()) {
  1834. +
  1835. + // 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).
  1836. + int redefinition_policy = current_klass->new_version()->klass_part()->field_redefinition_policy();
  1837. + if (is_static) {
  1838. + redefinition_policy = current_klass->new_version()->klass_part()->static_field_redefinition_policy();
  1839. + }
  1840. +
  1841. + assert(redefinition_policy != Klass::StaticCheck, "if the policy is static check, then we can never reach here");
  1842. +
  1843. + if (redefinition_policy != Klass::DynamicCheck) {
  1844. +
  1845. + if (redefinition_policy == Klass::AccessOldMembers) {
  1846. + // Forget looked up fields
  1847. + sel_klass = KlassHandle(Thread::current(), (oop)NULL);
  1848. + }
  1849. +
  1850. + assert(redefinition_policy == Klass::AccessOldMembers || redefinition_policy == Klass::AccessDeletedMembers, "");
  1851. +
  1852. + if (sel_klass.is_null() || fd.is_static() != is_static /* access old static field field is changed from static to non-static */) {
  1853. +
  1854. + // Select correct version for resolved klass.
  1855. + find_correct_resolved_klass(resolved_klass, current_klass);
  1856. +
  1857. + sel_klass = KlassHandle(Thread::current(), instanceKlass::cast(resolved_klass())->find_field(field_name, field_sig, &fd));
  1858. +
  1859. + // FIXME: idubrov
  1860. + //if (sel_klass.is_null()) {
  1861. + // TRACE_RC2("Trying to resolve field (%s) in old universe failed => exception is the correct behaviour", field_name->as_C_string());
  1862. + //} else {
  1863. + // assert(sel_klass->new_version() != NULL, "must be old class!");
  1864. + // TRACE_RC2("Resolved a field in the old universe (%s)!", field_name->as_C_string());
  1865. + //}
  1866. + }
  1867. + }
  1868. + }
  1869. +}
  1870. +
  1871. +void LinkResolver::lookup_correct_method(methodHandle& resolved_method, KlassHandle resolved_klass, KlassHandle current_klass,
  1872. + Symbol* method_name, Symbol* method_signature, bool is_interface, TRAPS) {
  1873. +
  1874. + // First attempt unversioned
  1875. + lookup_method(resolved_method, resolved_klass, method_name, method_signature, is_interface, current_klass, CHECK);
  1876. +
  1877. + // (tw) Are we in an old method that wants to see a different view on the world?
  1878. + if (!current_klass.is_null() && !current_klass->is_newest_version()) {
  1879. +
  1880. + // 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).
  1881. + int method_redefinition_policy = current_klass->new_version()->klass_part()->method_redefinition_policy();
  1882. + assert(method_redefinition_policy != Klass::StaticCheck, "if the policy is static check, then we can never reach here");
  1883. +
  1884. + if (method_redefinition_policy != Klass::DynamicCheck) {
  1885. +
  1886. + // We do not throw the exception
  1887. + if (method_redefinition_policy == Klass::AccessOldMembers) {
  1888. + // Forget any new member lookup
  1889. + resolved_method = methodHandle(THREAD, NULL);
  1890. + }
  1891. +
  1892. + assert(method_redefinition_policy == Klass::AccessOldMembers || method_redefinition_policy == Klass::AccessDeletedMembers, "");
  1893. +
  1894. + if (resolved_method.is_null()) {
  1895. +
  1896. + // Select correct version for resolved klass.
  1897. + find_correct_resolved_klass(resolved_klass, current_klass);
  1898. +
  1899. + // Now do the lookup in a second attempt with a different resolved klass.
  1900. + lookup_method(resolved_method, resolved_klass, method_name, method_signature, is_interface, current_klass, CHECK);
  1901. +
  1902. + // FIXME: idubrov
  1903. + //IF_TRACE_RC2 {
  1904. + // ResourceMark rm(THREAD);
  1905. + // if (resolved_method.is_null()) {
  1906. + // TRACE_RC2("Trying to resolve method (%s) in old universe failed => exception is the correct behaviour", method_name->as_C_string());
  1907. + // } else {
  1908. + // assert(resolved_method->is_old(), "must be old method!");
  1909. + // TRACE_RC2("Resolved a method in the old universe (%s)!", resolved_method->name()->as_C_string());
  1910. + // }
  1911. + //}
  1912. + }
  1913. + }
  1914. + }
  1915. +
  1916. + if (resolved_method.is_null()) {
  1917. + // no method found
  1918. + ResourceMark rm(THREAD);
  1919. + THROW_MSG(vmSymbols::java_lang_NoSuchMethodError(),
  1920. + methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()),
  1921. + method_name,
  1922. + method_signature));
  1923. + }
  1924. +}
  1925. +
  1926. +void LinkResolver::find_correct_resolved_klass(KlassHandle &resolved_klass, KlassHandle &current_klass) {
  1927. + int current_klass_revision = current_klass->revision_number();
  1928. + int resolved_klass_revision = resolved_klass->revision_number();
  1929. + // FIXME: idubrov
  1930. + //TRACE_RC2("The two different revision numbers for interfaces: current=%d / resolved_callee=%d", current_klass_revision, resolved_klass_revision);
  1931. +
  1932. + while (resolved_klass->revision_number() > current_klass_revision) {
  1933. + assert(resolved_klass->old_version(), "must have old version");
  1934. + resolved_klass = KlassHandle(Thread::current(), resolved_klass->old_version());
  1935. + }
  1936. +}
  1937. +
  1938. void LinkResolver::resolve_method(methodHandle& resolved_method, KlassHandle resolved_klass,
  1939. Symbol* method_name, Symbol* method_signature,
  1940. KlassHandle current_klass, bool check_access, TRAPS) {
  1941. @@ -416,35 +566,8 @@
  1942. THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
  1943. }
  1944. - Handle nested_exception;
  1945. -
  1946. - // 2. lookup method in resolved klass and its super klasses
  1947. - lookup_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1948. -
  1949. - if (resolved_method.is_null()) { // not found in the class hierarchy
  1950. - // 3. lookup method in all the interfaces implemented by the resolved klass
  1951. - lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1952. -
  1953. - if (resolved_method.is_null()) {
  1954. - // JSR 292: see if this is an implicitly generated method MethodHandle.linkToVirtual(*...), etc
  1955. - lookup_polymorphic_method(resolved_method, resolved_klass, method_name, method_signature,
  1956. - current_klass, (Handle*)NULL, (Handle*)NULL, THREAD);
  1957. - if (HAS_PENDING_EXCEPTION) {
  1958. - nested_exception = Handle(THREAD, PENDING_EXCEPTION);
  1959. - CLEAR_PENDING_EXCEPTION;
  1960. - }
  1961. - }
  1962. -
  1963. - if (resolved_method.is_null()) {
  1964. - // 4. method lookup failed
  1965. - ResourceMark rm(THREAD);
  1966. - THROW_MSG_CAUSE(vmSymbols::java_lang_NoSuchMethodError(),
  1967. - methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()),
  1968. - method_name,
  1969. - method_signature),
  1970. - nested_exception);
  1971. - }
  1972. - }
  1973. + // 2. and 3. and 4. lookup method in resolved klass and its super klasses
  1974. + lookup_correct_method(resolved_method, resolved_klass, current_klass, method_name, method_signature, false, CHECK);
  1975. // 5. check if method is concrete
  1976. if (resolved_method->is_abstract() && !resolved_klass->is_abstract()) {
  1977. @@ -512,20 +635,7 @@
  1978. }
  1979. // lookup method in this interface or its super, java.lang.Object
  1980. - lookup_instance_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1981. -
  1982. - if (resolved_method.is_null()) {
  1983. - // lookup method in all the super-interfaces
  1984. - lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1985. - if (resolved_method.is_null()) {
  1986. - // no method found
  1987. - ResourceMark rm(THREAD);
  1988. - THROW_MSG(vmSymbols::java_lang_NoSuchMethodError(),
  1989. - methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()),
  1990. - method_name,
  1991. - method_signature));
  1992. - }
  1993. - }
  1994. + lookup_correct_method(resolved_method, resolved_klass, current_klass, method_name, method_signature, true, CHECK);
  1995. if (check_access) {
  1996. HandleMark hm(THREAD);
  1997. @@ -612,9 +722,14 @@
  1998. THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string());
  1999. }
  2000. + KlassHandle ref_klass(THREAD, pool->pool_holder()->klass_part());
  2001. +
  2002. // Resolve instance field
  2003. fieldDescriptor fd; // find_field initializes fd if found
  2004. - KlassHandle sel_klass(THREAD, instanceKlass::cast(resolved_klass())->find_field(field, sig, &fd));
  2005. +
  2006. + KlassHandle sel_klass;
  2007. + lookup_correct_field(fd, sel_klass, resolved_klass, ref_klass, field, sig, is_static);
  2008. +
  2009. // check if field exists; i.e., if a klass containing the field def has been selected
  2010. if (sel_klass.is_null()){
  2011. ResourceMark rm(THREAD);
  2012. @@ -622,7 +737,6 @@
  2013. }
  2014. // check access
  2015. - KlassHandle ref_klass(THREAD, pool->pool_holder());
  2016. check_field_accessability(ref_klass, resolved_klass, sel_klass, fd, CHECK);
  2017. // check for errors
  2018. @@ -634,7 +748,7 @@
  2019. }
  2020. // Final fields can only be accessed from its own class.
  2021. - if (is_put && fd.access_flags().is_final() && sel_klass() != pool->pool_holder()) {
  2022. + if (is_put && fd.access_flags().is_final() && sel_klass() != pool->pool_holder()->klass_part()->active_version() && sel_klass() != pool->pool_holder()) {
  2023. THROW(vmSymbols::java_lang_IllegalAccessError());
  2024. }
  2025. @@ -839,7 +953,7 @@
  2026. bool check_access, bool check_null_and_abstract, TRAPS) {
  2027. methodHandle resolved_method;
  2028. linktime_resolve_virtual_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK);
  2029. - runtime_resolve_virtual_method(result, resolved_method, resolved_klass, recv, receiver_klass, check_null_and_abstract, CHECK);
  2030. + runtime_resolve_virtual_method(result, resolved_method, resolved_klass, recv, receiver_klass, current_klass, check_null_and_abstract, CHECK);
  2031. }
  2032. // throws linktime exceptions
  2033. @@ -869,6 +983,7 @@
  2034. KlassHandle resolved_klass,
  2035. Handle recv,
  2036. KlassHandle recv_klass,
  2037. + KlassHandle current_klass,
  2038. bool check_null_and_abstract,
  2039. TRAPS) {
  2040. @@ -917,7 +1032,40 @@
  2041. // recv_klass might be an arrayKlassOop but all vtables start at
  2042. // the same place. The cast is to avoid virtual call and assertion.
  2043. instanceKlass* inst = (instanceKlass*)recv_klass()->klass_part();
  2044. +
  2045. + // (tw) The type of the virtual method call and the type of the receiver do not need to
  2046. + // have anything in common, as the receiver type could've been hotswapped.
  2047. + // Does not always work (method could be resolved with correct dynamic type and later
  2048. + // be called at the same place with a wrong dynamic type).
  2049. + // (tw) TODO: Need to handle the static type vs dynamic type issue more generally.
  2050. +
  2051. + // The vTable must be based on the view of the world of the resolved method
  2052. + klassOop method_holder = resolved_method->method_holder();
  2053. +
  2054. + if (method_holder->klass_part()->new_version() != NULL) {
  2055. + // We are executing in old code
  2056. + // FIXME: idubrov
  2057. + //TRACE_RC2("Calling a method in old code");
  2058. + while (method_holder->klass_part()->revision_number() < inst->revision_number()) {
  2059. + inst = (instanceKlass *)(inst->old_version()->klass_part());
  2060. + }
  2061. + }
  2062. +
  2063. + if (inst->is_subtype_of(method_holder)) {
  2064. selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index));
  2065. + } else {
  2066. +
  2067. + tty->print_cr("Failure:");
  2068. + inst->as_klassOop()->print();
  2069. + inst->super()->print();
  2070. + juint off = inst->super_check_offset();
  2071. + klassOop sup = *(klassOop*)( (address)inst->as_klassOop() + off );
  2072. + sup->print();
  2073. + method_holder->print();
  2074. +
  2075. + bool b = inst->is_subtype_of(method_holder);
  2076. + 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!");
  2077. + }
  2078. }
  2079. }
  2080. diff -r 6c6a2299029a src/share/vm/interpreter/linkResolver.hpp
  2081. --- a/src/share/vm/interpreter/linkResolver.hpp Sat Dec 14 11:51:15 2013 -0800
  2082. +++ b/src/share/vm/interpreter/linkResolver.hpp Mon Apr 28 13:12:30 2014 -0700
  2083. @@ -110,7 +110,11 @@
  2084. // It does all necessary link-time checks & throws exceptions if necessary.
  2085. class LinkResolver: AllStatic {
  2086. - private:
  2087. +private:
  2088. + static void lookup_method (methodHandle& result, KlassHandle resolved_klass, Symbol* name, Symbol* signature, bool is_interface, KlassHandle current_klass, TRAPS);
  2089. + 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);
  2090. + static void lookup_correct_method (methodHandle& result, KlassHandle resolved_klass, KlassHandle current_klass, Symbol* name, Symbol* signature, bool is_interface, TRAPS);
  2091. + static void find_correct_resolved_klass (KlassHandle &resolved_klass, KlassHandle &current_klass);
  2092. static void lookup_method_in_klasses (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
  2093. static void lookup_instance_method_in_klasses (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
  2094. static void lookup_method_in_interfaces (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
  2095. @@ -133,7 +137,7 @@
  2096. 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);
  2097. static void runtime_resolve_special_method (CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, KlassHandle current_klass, bool check_access, TRAPS);
  2098. - 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);
  2099. + 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);
  2100. 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);
  2101. static void check_field_accessability (KlassHandle ref_klass, KlassHandle resolved_klass, KlassHandle sel_klass, fieldDescriptor& fd, TRAPS);
  2102. diff -r 6c6a2299029a src/share/vm/interpreter/templateTable.hpp
  2103. --- a/src/share/vm/interpreter/templateTable.hpp Sat Dec 14 11:51:15 2013 -0800
  2104. +++ b/src/share/vm/interpreter/templateTable.hpp Mon Apr 28 13:12:30 2014 -0700
  2105. @@ -329,8 +329,8 @@
  2106. static void shouldnotreachhere();
  2107. // jvmti support
  2108. - static void jvmti_post_field_access(Register cache, Register index, bool is_static, bool has_tos);
  2109. - static void jvmti_post_field_mod(Register cache, Register index, bool is_static);
  2110. + static void jvmti_post_field_access(Register cache, Register index, int byte_no, bool is_static, bool has_tos);
  2111. + static void jvmti_post_field_mod(Register cache, Register index, int byte_no, bool is_static);
  2112. static void jvmti_post_fast_field_mod();
  2113. // debugging of TemplateGenerator
  2114. diff -r 6c6a2299029a src/share/vm/memory/genMarkSweep.cpp
  2115. --- a/src/share/vm/memory/genMarkSweep.cpp Sat Dec 14 11:51:15 2013 -0800
  2116. +++ b/src/share/vm/memory/genMarkSweep.cpp Mon Apr 28 13:12:30 2014 -0700
  2117. @@ -421,6 +421,7 @@
  2118. // in the same order in phase2, phase3 and phase4. We don't quite do that
  2119. // here (perm_gen first rather than last), so we tell the validate code
  2120. // to use a higher index (saved from phase2) when verifying perm_gen.
  2121. + assert(_rescued_oops == NULL, "must be empty before processing");
  2122. GenCollectedHeap* gch = GenCollectedHeap::heap();
  2123. Generation* pg = gch->perm_gen();
  2124. @@ -433,10 +434,14 @@
  2125. VALIDATE_MARK_SWEEP_ONLY(reset_live_oop_tracking(false));
  2126. + MarkSweep::copy_rescued_objects_back();
  2127. +
  2128. GenCompactClosure blk;
  2129. gch->generation_iterate(&blk, true);
  2130. VALIDATE_MARK_SWEEP_ONLY(compaction_complete());
  2131. + MarkSweep::copy_rescued_objects_back();
  2132. +
  2133. pg->post_compact(); // Shared spaces verification.
  2134. }
  2135. diff -r 6c6a2299029a src/share/vm/memory/permGen.cpp
  2136. --- a/src/share/vm/memory/permGen.cpp Sat Dec 14 11:51:15 2013 -0800
  2137. +++ b/src/share/vm/memory/permGen.cpp Mon Apr 28 13:12:30 2014 -0700
  2138. @@ -57,7 +57,12 @@
  2139. for (;;) {
  2140. {
  2141. - MutexLocker ml(Heap_lock);
  2142. + // (tw) Only lock when not at a safepoint (necessary to use the split verifier from the VmThread)
  2143. + Monitor *lock = Heap_lock;
  2144. + if (SafepointSynchronize::is_at_safepoint()) {
  2145. + lock = NULL;
  2146. + }
  2147. + MutexLockerEx ml(lock);
  2148. if ((obj = gen->allocate(size, false)) != NULL) {
  2149. return obj;
  2150. }
  2151. diff -r 6c6a2299029a src/share/vm/memory/space.cpp
  2152. --- a/src/share/vm/memory/space.cpp Sat Dec 14 11:51:15 2013 -0800
  2153. +++ b/src/share/vm/memory/space.cpp Mon Apr 28 13:12:30 2014 -0700
  2154. @@ -378,6 +378,31 @@
  2155. _compaction_top = bottom();
  2156. }
  2157. +// (tw) Calculates the compact_top that will be used for placing the next object with the giving size on the heap.
  2158. +HeapWord* CompactibleSpace::forward_compact_top(size_t size,
  2159. +CompactPoint* cp, HeapWord* compact_top) {
  2160. + // First check if we should switch compaction space
  2161. + assert(this == cp->space, "'this' should be current compaction space.");
  2162. + size_t compaction_max_size = pointer_delta(end(), compact_top);
  2163. + while (size > compaction_max_size) {
  2164. + // switch to next compaction space
  2165. + cp->space->set_compaction_top(compact_top);
  2166. + cp->space = cp->space->next_compaction_space();
  2167. + if (cp->space == NULL) {
  2168. + cp->gen = GenCollectedHeap::heap()->prev_gen(cp->gen);
  2169. + assert(cp->gen != NULL, "compaction must succeed");
  2170. + cp->space = cp->gen->first_compaction_space();
  2171. + assert(cp->space != NULL, "generation must have a first compaction space");
  2172. + }
  2173. + compact_top = cp->space->bottom();
  2174. + cp->space->set_compaction_top(compact_top);
  2175. + cp->threshold = cp->space->initialize_threshold();
  2176. + compaction_max_size = pointer_delta(cp->space->end(), compact_top);
  2177. + }
  2178. +
  2179. + return compact_top;
  2180. +}
  2181. +
  2182. HeapWord* CompactibleSpace::forward(oop q, size_t size,
  2183. CompactPoint* cp, HeapWord* compact_top) {
  2184. // q is alive
  2185. @@ -401,7 +426,7 @@
  2186. }
  2187. // store the forwarding pointer into the mark word
  2188. - if ((HeapWord*)q != compact_top) {
  2189. + if ((HeapWord*)q != compact_top || (size_t)q->size() != size) {
  2190. q->forward_to(oop(compact_top));
  2191. assert(q->is_gc_marked(), "encoding the pointer should preserve the mark");
  2192. } else {
  2193. @@ -449,7 +474,208 @@
  2194. // Faster object search.
  2195. void ContiguousSpace::prepare_for_compaction(CompactPoint* cp) {
  2196. - SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size);
  2197. + if (!Universe::is_redefining_gc_run()) {
  2198. + SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size);
  2199. + return;
  2200. + }
  2201. +
  2202. + /* Compute the new addresses for the live objects and store it in the mark
  2203. + * Used by universe::mark_sweep_phase2()
  2204. + */
  2205. + HeapWord* compact_top; /* This is where we are currently compacting to. */
  2206. +
  2207. + /* We're sure to be here before any objects are compacted into this
  2208. + * space, so this is a good time to initialize this:
  2209. + */
  2210. + set_compaction_top(bottom());
  2211. +
  2212. + if (cp->space == NULL) {
  2213. + assert(cp->gen != NULL, "need a generation");
  2214. + assert(cp->threshold == NULL, "just checking");
  2215. + assert(cp->gen->first_compaction_space() == this, "just checking");
  2216. + cp->space = cp->gen->first_compaction_space();
  2217. + compact_top = cp->space->bottom();
  2218. + cp->space->set_compaction_top(compact_top);
  2219. + cp->threshold = cp->space->initialize_threshold();
  2220. + } else {
  2221. + compact_top = cp->space->compaction_top();
  2222. + }
  2223. +
  2224. + /* We allow some amount of garbage towards the bottom of the space, so
  2225. + * we don't start compacting before there is a significant gain to be made.
  2226. + * Occasionally, we want to ensure a full compaction, which is determined
  2227. + * by the MarkSweepAlwaysCompactCount parameter.
  2228. + */
  2229. + int invocations = SharedHeap::heap()->perm_gen()->stat_record()->invocations;
  2230. + bool skip_dead = (MarkSweepAlwaysCompactCount < 1)
  2231. + ||((invocations % MarkSweepAlwaysCompactCount) != 0);
  2232. +
  2233. + size_t allowed_deadspace = 0;
  2234. + if (skip_dead) {
  2235. + int ratio = (int)allowed_dead_ratio();
  2236. + allowed_deadspace = (capacity() * ratio / 100) / HeapWordSize;
  2237. + }
  2238. +
  2239. + HeapWord* q = bottom();
  2240. + HeapWord* t = end();
  2241. +
  2242. + HeapWord* end_of_live= q; /* One byte beyond the last byte of the last
  2243. + live object. */
  2244. + HeapWord* first_dead = end();/* The first dead object. */
  2245. + LiveRange* liveRange = NULL; /* The current live range, recorded in the
  2246. + first header of preceding free area. */
  2247. + _first_dead = first_dead;
  2248. +
  2249. + const intx interval = PrefetchScanIntervalInBytes;
  2250. +
  2251. + while (q < t) {
  2252. + assert(!block_is_obj(q) ||
  2253. + oop(q)->mark()->is_marked() || oop(q)->mark()->is_unlocked() ||
  2254. + oop(q)->mark()->has_bias_pattern(),
  2255. + "these are the only valid states during a mark sweep");
  2256. + if (block_is_obj(q) && oop(q)->is_gc_marked()) {
  2257. + /* prefetch beyond q */
  2258. + Prefetch::write(q, interval);
  2259. + /* size_t size = oop(q)->size(); changing this for cms for perm gen */
  2260. + size_t size = block_size(q);
  2261. +
  2262. + // DCEVM: begin
  2263. + //////////////////////////////////////////////////////////////////////////
  2264. + size_t forward_size = size;
  2265. +
  2266. + // Compute the forward sizes and leave out objects whose position could
  2267. + // possibly overlap other objects.
  2268. +
  2269. + // DCEVM: There is a new version of the class of q => different size
  2270. + if (oop(q)->blueprint()->new_version() != NULL && oop(q)->blueprint()->new_version()->klass_part()->update_information() != NULL) {
  2271. +
  2272. + size_t new_size = oop(q)->size_given_klass(oop(q)->blueprint()->new_version()->klass_part());
  2273. + assert(size != new_size || oop(q)->is_perm(), "instances without changed size have to be updated prior to GC run");
  2274. + forward_size = new_size;
  2275. + }
  2276. +
  2277. + compact_top = cp->space->forward_compact_top(forward_size, cp, compact_top);
  2278. +
  2279. + bool rescueing = false;
  2280. + if (rescueing = must_rescue(oop(q), oop(compact_top))) {
  2281. + if (MarkSweep::_rescued_oops == NULL) {
  2282. + MarkSweep::_rescued_oops = new GrowableArray<oop>(128);
  2283. + }
  2284. + // FIXME: idubrov
  2285. + //TRACE_RC5("rescue obj %d klass=%s", MarkSweep::_rescued_oops->length(), oop(q)->klass()->klass_part()->name()->as_C_string());
  2286. + MarkSweep::_rescued_oops->append(oop(q));
  2287. + } else {
  2288. + compact_top = cp->space->forward(oop(q), forward_size, cp, compact_top);
  2289. + }
  2290. +
  2291. + if ((size != forward_size || rescueing) && q < first_dead) {
  2292. + // (tw) This object moves => first_dead must be set to here!
  2293. + first_dead = q;
  2294. + }
  2295. + //////////////////////////////////////////////////////////////////////////
  2296. + q += size;
  2297. + end_of_live = q;
  2298. + } else {
  2299. + /* run over all the contiguous dead objects */
  2300. + HeapWord* end = q;
  2301. + do {
  2302. + /* prefetch beyond end */
  2303. + Prefetch::write(end, interval);
  2304. + end += block_size(end);
  2305. + } while (end < t && (!block_is_obj(end) || !oop(end)->is_gc_marked()));
  2306. +
  2307. + /* see if we might want to pretend this object is alive so that
  2308. + * we don't have to compact quite as often.
  2309. + */
  2310. + if (allowed_deadspace > 0 && q == compact_top) {
  2311. + size_t sz = pointer_delta(end, q);
  2312. + if (insert_deadspace(allowed_deadspace, q, sz)) {
  2313. + compact_top = cp->space->forward(oop(q), sz, cp, compact_top);
  2314. + q = end;
  2315. + end_of_live = end;
  2316. + continue;
  2317. + }
  2318. + }
  2319. +
  2320. + /* otherwise, it really is a free region. */
  2321. +
  2322. + /* for the previous LiveRange, record the end of the live objects. */
  2323. + if (liveRange) {
  2324. + liveRange->set_end(q);
  2325. + }
  2326. +
  2327. + /* record the current LiveRange object.
  2328. + * liveRange->start() is overlaid on the mark word.
  2329. + */
  2330. + liveRange = (LiveRange*)q;
  2331. + liveRange->set_start(end);
  2332. + liveRange->set_end(end);
  2333. +
  2334. + /* see if this is the first dead region. */
  2335. + if (q < first_dead) {
  2336. + first_dead = q;
  2337. + }
  2338. +
  2339. + /* move on to the next object */
  2340. + q = end;
  2341. + }
  2342. + }
  2343. +
  2344. + //////////////////////////////////////////////////////////////////////////
  2345. + // Compute the forwarding addresses for the objects that need to be
  2346. + // rescued.
  2347. + // TODO: empty the _rescued_oops after ALL spaces are compacted!
  2348. + if (MarkSweep::_rescued_oops != NULL) {
  2349. + // FIXME: idubrov
  2350. + //TRACE_RC2("Calculating new forward sizes for %d objects!", MarkSweep::_rescued_oops->length());
  2351. +
  2352. + for (int i=0; i<MarkSweep::_rescued_oops->length(); i++) {
  2353. + oop q = MarkSweep::_rescued_oops->at(i);
  2354. +
  2355. + /* size_t size = oop(q)->size(); changing this for cms for perm gen */
  2356. + size_t size = block_size((HeapWord*)q);
  2357. +
  2358. + size_t forward_size = size;
  2359. +
  2360. + // (tw) There is a new version of the class of q => different size
  2361. + if (oop(q)->blueprint()->new_version() != NULL) {
  2362. +
  2363. + size_t new_size = oop(q)->size_given_klass(oop(q)->blueprint()->new_version()->klass_part());
  2364. + assert(size != new_size || oop(q)->is_perm(), "instances without changed size have to be updated prior to GC run");
  2365. + forward_size = new_size;
  2366. + }
  2367. +
  2368. + compact_top = cp->space->forward(oop(q), forward_size, cp, compact_top);
  2369. + assert(compact_top <= t, "must not write over end of space!");
  2370. + }
  2371. + MarkSweep::_rescued_oops->clear();
  2372. + MarkSweep::_rescued_oops = NULL;
  2373. + }
  2374. + //////////////////////////////////////////////////////////////////////////
  2375. +
  2376. + assert(q == t, "just checking");
  2377. + if (liveRange != NULL) {
  2378. + liveRange->set_end(q);
  2379. + }
  2380. + _end_of_live = end_of_live;
  2381. + if (end_of_live < first_dead) {
  2382. + first_dead = end_of_live;
  2383. + }
  2384. + _first_dead = first_dead;
  2385. +
  2386. +// FIXME: idubrov
  2387. +// if (_first_dead > top()) {
  2388. +// _first_dead = top();
  2389. +// }
  2390. +//
  2391. +// if (_end_of_live > top()) {
  2392. +// _end_of_live = top();
  2393. +// }
  2394. + assert(_first_dead <= top(), "Must be smaller equal");
  2395. + assert(_end_of_live <= top(), "Must be smaller equal");
  2396. +
  2397. + /* save the compaction_top of the compaction space. */
  2398. + cp->space->set_compaction_top(compact_top);
  2399. }
  2400. void Space::adjust_pointers() {
  2401. @@ -490,17 +716,313 @@
  2402. assert(q == t, "just checking");
  2403. }
  2404. +
  2405. +#ifdef ASSERT
  2406. +
  2407. +int CompactibleSpace::space_index(oop obj) {
  2408. + GenCollectedHeap* heap = GenCollectedHeap::heap();
  2409. +
  2410. + if (heap->is_in_permanent(obj)) {
  2411. + return -1;
  2412. + }
  2413. +
  2414. + int index = 0;
  2415. + for (int i = heap->n_gens() - 1; i >= 0; i--) {
  2416. + Generation* gen = heap->get_gen(i);
  2417. + CompactibleSpace* space = gen->first_compaction_space();
  2418. + while (space != NULL) {
  2419. + if (space->is_in_reserved(obj)) {
  2420. + return index;
  2421. + }
  2422. + space = space->next_compaction_space();
  2423. + index++;
  2424. + }
  2425. + }
  2426. +
  2427. + tty->print_cr("could not compute space_index for %08xh", obj);
  2428. + index = 0;
  2429. + for (int i = heap->n_gens() - 1; i >= 0; i--) {
  2430. + Generation* gen = heap->get_gen(i);
  2431. + tty->print_cr(" generation %s: %08xh - %08xh", gen->name(), gen->reserved().start(), gen->reserved().end());
  2432. +
  2433. + CompactibleSpace* space = gen->first_compaction_space();
  2434. + while (space != NULL) {
  2435. + tty->print_cr(" %2d space %08xh - %08xh", index, space->bottom(), space->end());
  2436. + space = space->next_compaction_space();
  2437. + index++;
  2438. + }
  2439. + }
  2440. +
  2441. + ShouldNotReachHere();
  2442. + return 0;
  2443. +}
  2444. +#endif
  2445. +
  2446. +bool CompactibleSpace::must_rescue(oop old_obj, oop new_obj) {
  2447. +
  2448. + assert(is_in_reserved(old_obj), "old_obj must be in this space");
  2449. +
  2450. + if (old_obj->is_perm()) {
  2451. + // This object is in perm gen; check for invariant obj->klass() <= obj
  2452. + if (oop(old_obj)->blueprint()->new_version() != NULL) {
  2453. + return true;
  2454. + }
  2455. + }
  2456. +
  2457. + int size = old_obj->size();
  2458. + int original_size = size;
  2459. + if (oop(old_obj)->blueprint()->is_redefining()) {
  2460. + assert(oop(old_obj)->blueprint()->old_version() != NULL, "must not be null");
  2461. + original_size = oop(old_obj)->size_given_klass(oop(old_obj)->blueprint()->old_version()->klass_part());
  2462. + } else if (oop(old_obj)->blueprint()->new_version() != NULL) {
  2463. + size = oop(old_obj)->size_given_klass(oop(old_obj)->blueprint()->new_version()->klass_part());
  2464. + }
  2465. +
  2466. + bool normalComparison = (old_obj + original_size < new_obj + size);
  2467. +
  2468. + if (is_in_reserved(new_obj)) {
  2469. + // Old and new address are in same space, so just compare the address.
  2470. + // Must rescue if object moves towards the top of the space.
  2471. + assert(space_index(old_obj) == space_index(new_obj), "old_obj and new_obj must be in same space");
  2472. + return normalComparison;
  2473. +
  2474. + } else {
  2475. +
  2476. + assert(space_index(old_obj) != space_index(new_obj), "old_obj and new_obj must be in different spaces");
  2477. +
  2478. + Generation* tenured_gen = GenCollectedHeap::heap()->get_gen(1);
  2479. + if (tenured_gen->is_in_reserved(new_obj)) {
  2480. + // Must never rescue when moving from the new into the old generation.
  2481. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(old_obj), "old_obj must be in DefNewGeneration");
  2482. + assert(space_index(old_obj) > space_index(new_obj), "must be");
  2483. + return false;
  2484. +
  2485. + } else if (tenured_gen->is_in_reserved(old_obj)) {
  2486. + // Must always rescue when moving from the old into the new generation.
  2487. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(new_obj), "new_obj must be in DefNewGeneration");
  2488. + assert(space_index(old_obj) < space_index(new_obj), "must be");
  2489. + return true;
  2490. +
  2491. + } else {
  2492. + // In the new generation, eden is located before the from space, so a
  2493. + // simple pointer comparison is sufficient.
  2494. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(old_obj), "old_obj must be in DefNewGeneration");
  2495. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(new_obj), "new_obj must be in DefNewGeneration");
  2496. + assert((normalComparison) == (space_index(old_obj) < space_index(new_obj)), "slow and fast computation must yield same result");
  2497. + return normalComparison;
  2498. + }
  2499. + }
  2500. +}
  2501. +
  2502. +oop CompactibleSpace::rescue(oop old_obj) {
  2503. + assert(must_rescue(old_obj, old_obj->forwardee()), "do not call otherwise");
  2504. +
  2505. + int size = old_obj->size();
  2506. + oop rescued_obj = (oop)resource_allocate_bytes(size * HeapWordSize);
  2507. + Copy::aligned_disjoint_words((HeapWord*)old_obj, (HeapWord*)rescued_obj, size);
  2508. +
  2509. + if (MarkSweep::_rescued_oops == NULL) {
  2510. + MarkSweep::_rescued_oops = new GrowableArray<oop>(128);
  2511. + }
  2512. +
  2513. + MarkSweep::_rescued_oops->append(rescued_obj);
  2514. + return rescued_obj;
  2515. +}
  2516. +
  2517. void CompactibleSpace::adjust_pointers() {
  2518. // Check first is there is any work to do.
  2519. if (used() == 0) {
  2520. return; // Nothing to do.
  2521. }
  2522. + /* adjust all the interior pointers to point at the new locations of objects
  2523. + * Used by MarkSweep::mark_sweep_phase3() */
  2524. - SCAN_AND_ADJUST_POINTERS(adjust_obj_size);
  2525. + HeapWord* q = bottom();
  2526. + HeapWord* t = _end_of_live; /* Established by "prepare_for_compaction". */
  2527. +
  2528. + assert(_first_dead <= _end_of_live, "Stands to reason, no?");
  2529. +
  2530. + debug_only(HeapWord* prev_q = NULL);
  2531. + debug_only(HeapWord* prev_prev_q = NULL);
  2532. + debug_only(HeapWord* prev_prev_prev_q = NULL);
  2533. + if (q < t && _first_dead > q &&
  2534. + !oop(q)->is_gc_marked()) {
  2535. + /* we have a chunk of the space which hasn't moved and we've
  2536. + * reinitialized the mark word during the previous pass, so we can't
  2537. + * use is_gc_marked for the traversal. */
  2538. + HeapWord* end = _first_dead;
  2539. +
  2540. + while (q < end) {
  2541. + /* I originally tried to conjoin "block_start(q) == q" to the
  2542. + * assertion below, but that doesn't work, because you can't
  2543. + * accurately traverse previous objects to get to the current one
  2544. + * after their pointers (including pointers into permGen) have been
  2545. + * updated, until the actual compaction is done. dld, 4/00 */
  2546. + assert(block_is_obj(q),
  2547. + "should be at block boundaries, and should be looking at objs");
  2548. +
  2549. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::track_interior_pointers(oop(q)));
  2550. +
  2551. + /* point all the oops to the new location */
  2552. + size_t size = oop(q)->adjust_pointers();
  2553. + size = adjust_obj_size(size);
  2554. +
  2555. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::check_interior_pointers());
  2556. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::validate_live_oop(oop(q), size));
  2557. +
  2558. + debug_only(prev_prev_prev_q = prev_prev_q);
  2559. + debug_only(prev_prev_q = prev_q);
  2560. + debug_only(prev_q = q);
  2561. + q += size;
  2562. + }
  2563. +
  2564. + // (tw) first_dead can be live object!
  2565. + q = _first_dead;
  2566. +
  2567. +// if (_first_dead == t) {
  2568. +// q = t;
  2569. +// } else {
  2570. +// /* $$$ This is funky. Using this to read the previously written
  2571. +// * LiveRange. See also use below. */
  2572. +// q = (HeapWord*)oop(_first_dead)->mark()->decode_pointer();
  2573. +// }
  2574. + }
  2575. +
  2576. + const intx interval = PrefetchScanIntervalInBytes;
  2577. +
  2578. + debug_only(prev_q = NULL);
  2579. + debug_only(prev_prev_q = NULL);
  2580. + debug_only(prev_prev_prev_q = NULL);
  2581. + while (q < t) {
  2582. + /* prefetch beyond q */
  2583. + Prefetch::write(q, interval);
  2584. + if (oop(q)->is_gc_marked()) {
  2585. + /* q is alive */
  2586. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::track_interior_pointers(oop(q)));
  2587. + /* point all the oops to the new location */
  2588. + size_t size = oop(q)->adjust_pointers();
  2589. + size = adjust_obj_size(size);
  2590. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::check_interior_pointers());
  2591. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::validate_live_oop(oop(q), size));
  2592. + debug_only(prev_prev_prev_q = prev_prev_q);
  2593. + debug_only(prev_prev_q = prev_q);
  2594. + debug_only(prev_q = q);
  2595. + q += size;
  2596. + } else {
  2597. + /* q is not a live object, so its mark should point at the next
  2598. + * live object */
  2599. + debug_only(prev_prev_prev_q = prev_prev_q);
  2600. + debug_only(prev_prev_q = prev_q);
  2601. + debug_only(prev_q = q);
  2602. + q = (HeapWord*) oop(q)->mark()->decode_pointer();
  2603. + assert(q > prev_q, "we should be moving forward through memory");
  2604. + }
  2605. + }
  2606. +
  2607. + assert(q == t, "just checking");
  2608. }
  2609. void CompactibleSpace::compact() {
  2610. - SCAN_AND_COMPACT(obj_size);
  2611. +
  2612. + if(!Universe::is_redefining_gc_run()) {
  2613. + SCAN_AND_COMPACT(obj_size);
  2614. + return;
  2615. + }
  2616. +
  2617. + /* Copy all live objects to their new location
  2618. + * Used by MarkSweep::mark_sweep_phase4() */
  2619. +
  2620. + HeapWord* q = bottom();
  2621. + HeapWord* const t = _end_of_live;
  2622. + debug_only(HeapWord* prev_q = NULL);
  2623. +
  2624. + if (q < t && _first_dead > q &&
  2625. + !oop(q)->is_gc_marked()) {
  2626. + debug_only(
  2627. + /* we have a chunk of the space which hasn't moved and we've reinitialized
  2628. + * the mark word during the previous pass, so we can't use is_gc_marked for
  2629. + * the traversal. */
  2630. + HeapWord* const end = _first_dead;
  2631. +
  2632. + while (q < end) {
  2633. + size_t size = obj_size(q); // FIXME: idubrov oop(q)->size();
  2634. + assert(!oop(q)->is_gc_marked(),
  2635. + "should be unmarked (special dense prefix handling)");
  2636. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::live_oop_moved_to(q, size, q));
  2637. + debug_only(prev_q = q);
  2638. + q += size;
  2639. + }
  2640. + ) /* debug_only */
  2641. + // (tw) first_dead can be live object!
  2642. + q = _first_dead;
  2643. +
  2644. + //if (_first_dead == t) {
  2645. + // q = t;
  2646. + //} else {
  2647. + ///* $$$ Funky */
  2648. + //q = (HeapWord*) oop(_first_dead)->mark()->decode_pointer();
  2649. + //}
  2650. + }
  2651. +
  2652. + const intx scan_interval = PrefetchScanIntervalInBytes;
  2653. + const intx copy_interval = PrefetchCopyIntervalInBytes;
  2654. + while (q < t) {
  2655. + if (!oop(q)->is_gc_marked()) {
  2656. + /* mark is pointer to next marked oop */
  2657. + debug_only(prev_q = q);
  2658. + q = (HeapWord*) oop(q)->mark()->decode_pointer();
  2659. + assert(q > prev_q, "we should be moving forward through memory");
  2660. + } else {
  2661. + /* prefetch beyond q */
  2662. + Prefetch::read(q, scan_interval);
  2663. +
  2664. + /* size and destination */
  2665. + size_t size = obj_size(q);
  2666. + HeapWord* compaction_top = (HeapWord*)oop(q)->forwardee();
  2667. +
  2668. + if (must_rescue(oop(q), oop(q)->forwardee())) {
  2669. + oop dest_obj = rescue(oop(q));
  2670. + debug_only(Copy::fill_to_words(q, size, 0));
  2671. + } else {
  2672. +
  2673. + /* prefetch beyond compaction_top */
  2674. + Prefetch::write(compaction_top, copy_interval);
  2675. +
  2676. + /* copy object and reinit its mark */
  2677. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::live_oop_moved_to(q, size,
  2678. + compaction_top));
  2679. + assert(q != compaction_top || oop(q)->blueprint()->new_version() != NULL, "everything in this pass should be moving");
  2680. +
  2681. + if (oop(q)->blueprint()->new_version() != NULL) {
  2682. + MarkSweep::update_fields(oop(q), oop(compaction_top));
  2683. + } else {
  2684. + Copy::aligned_conjoint_words(q, compaction_top, size);
  2685. + }
  2686. + oop(compaction_top)->init_mark();
  2687. + assert(oop(compaction_top)->klass() != NULL, "should have a class");
  2688. + }
  2689. +
  2690. + debug_only(prev_q = q);
  2691. + q += size;
  2692. + }
  2693. + }
  2694. +
  2695. + /* Let's remember if we were empty before we did the compaction. */
  2696. + bool was_empty = used_region().is_empty();
  2697. + /* Reset space after compaction is complete */
  2698. + reset_after_compaction();
  2699. + /* We do this clear, below, since it has overloaded meanings for some */
  2700. + /* space subtypes. For example, OffsetTableContigSpace's that were */
  2701. + /* compacted into will have had their offset table thresholds updated */
  2702. + /* continuously, but those that weren't need to have their thresholds */
  2703. + /* re-initialized. Also mangles unused area for debugging. */
  2704. + if (used_region().is_empty()) {
  2705. + if (!was_empty) clear(SpaceDecorator::Mangle);
  2706. + } else {
  2707. + if (ZapUnusedHeapArea) mangle_unused_area();
  2708. + }
  2709. +
  2710. + //SCAN_AND_COMPACT(obj_size);
  2711. }
  2712. void Space::print_short() const { print_short_on(tty); }
  2713. diff -r 6c6a2299029a src/share/vm/memory/space.hpp
  2714. --- a/src/share/vm/memory/space.hpp Sat Dec 14 11:51:15 2013 -0800
  2715. +++ b/src/share/vm/memory/space.hpp Mon Apr 28 13:12:30 2014 -0700
  2716. @@ -445,6 +445,9 @@
  2717. // indicates when the next such action should be taken.
  2718. virtual void prepare_for_compaction(CompactPoint* cp);
  2719. // MarkSweep support phase3
  2720. + DEBUG_ONLY(int space_index(oop obj));
  2721. + bool must_rescue(oop old_obj, oop new_obj);
  2722. + oop rescue(oop old_obj);
  2723. virtual void adjust_pointers();
  2724. // MarkSweep support phase4
  2725. virtual void compact();
  2726. @@ -475,6 +478,10 @@
  2727. virtual HeapWord* forward(oop q, size_t size, CompactPoint* cp,
  2728. HeapWord* compact_top);
  2729. + // (tw)
  2730. + virtual HeapWord* forward_compact_top(size_t size, CompactPoint* cp,
  2731. + HeapWord* compact_top);
  2732. +
  2733. // Return a size with adjusments as required of the space.
  2734. virtual size_t adjust_object_size_v(size_t size) const { return size; }
  2735. diff -r 6c6a2299029a src/share/vm/memory/universe.cpp
  2736. --- a/src/share/vm/memory/universe.cpp Sat Dec 14 11:51:15 2013 -0800
  2737. +++ b/src/share/vm/memory/universe.cpp Mon Apr 28 13:12:30 2014 -0700
  2738. @@ -100,6 +100,8 @@
  2739. #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
  2740. #endif
  2741. +bool Universe::_is_redefining_gc_run = false;
  2742. +
  2743. // Known objects
  2744. klassOop Universe::_boolArrayKlassObj = NULL;
  2745. klassOop Universe::_byteArrayKlassObj = NULL;
  2746. @@ -204,6 +206,38 @@
  2747. f(systemObjArrayKlassObj());
  2748. }
  2749. +// DCEVM: This method should iterate all pointers that are not within heap objects.
  2750. +void Universe::root_oops_do(OopClosure *oopClosure) {
  2751. +
  2752. + class AlwaysTrueClosure: public BoolObjectClosure {
  2753. + public:
  2754. + void do_object(oop p) { ShouldNotReachHere(); }
  2755. + bool do_object_b(oop p) { return true; }
  2756. + };
  2757. + AlwaysTrueClosure always_true;
  2758. +
  2759. + // General strong roots
  2760. + Universe::oops_do(oopClosure);
  2761. + JNIHandles::oops_do(oopClosure);
  2762. + Threads::oops_do(oopClosure, NULL);
  2763. + ObjectSynchronizer::oops_do(oopClosure);
  2764. + FlatProfiler::oops_do(oopClosure);
  2765. + //Management::oops_do(oopClosure); // DCEVM: TODO: Check if this is correct?
  2766. + JvmtiExport::oops_do(oopClosure);
  2767. + // SO_AllClasses
  2768. + SystemDictionary::oops_do(oopClosure);
  2769. +
  2770. + // Now adjust pointers in remaining weak roots. (All of which should
  2771. + // have been cleared if they pointed to non-surviving objects.)
  2772. + // Global (weak) JNI handles
  2773. + JNIHandles::weak_oops_do(&always_true, oopClosure);
  2774. +
  2775. + CodeCache::oops_do(oopClosure);
  2776. + StringTable::oops_do(oopClosure);
  2777. + //ref_processor()->weak_oops_do(&oopClosure); // DCEVM: TODO: Check if this is correct?
  2778. + //PSScavenge::reference_processor()->weak_oops_do(&oopClosure); // DCEVM: TODO: Check if this is correct?
  2779. +}
  2780. +
  2781. void Universe::oops_do(OopClosure* f, bool do_all) {
  2782. f->do_oop((oop*) &_int_mirror);
  2783. diff -r 6c6a2299029a src/share/vm/memory/universe.hpp
  2784. --- a/src/share/vm/memory/universe.hpp Sat Dec 14 11:51:15 2013 -0800
  2785. +++ b/src/share/vm/memory/universe.hpp Mon Apr 28 13:12:30 2014 -0700
  2786. @@ -127,6 +127,8 @@
  2787. friend class SystemDictionary;
  2788. friend class VMStructs;
  2789. friend class CompactingPermGenGen;
  2790. + friend class Space;
  2791. + friend class ContiguousSpace;
  2792. friend class VM_PopulateDumpSharedSpace;
  2793. friend jint universe_init();
  2794. @@ -258,7 +260,18 @@
  2795. static void compute_verify_oop_data();
  2796. + static bool _is_redefining_gc_run;
  2797. +
  2798. public:
  2799. +
  2800. + static bool is_redefining_gc_run() {
  2801. + return _is_redefining_gc_run;
  2802. + }
  2803. +
  2804. + static void set_redefining_gc_run(bool b) {
  2805. + _is_redefining_gc_run = b;
  2806. + }
  2807. +
  2808. // Known classes in the VM
  2809. static klassOop boolArrayKlassObj() { return _boolArrayKlassObj; }
  2810. static klassOop byteArrayKlassObj() { return _byteArrayKlassObj; }
  2811. @@ -403,6 +416,8 @@
  2812. // Iteration
  2813. + static void root_oops_do(OopClosure *f);
  2814. +
  2815. // Apply "f" to the addresses of all the direct heap pointers maintained
  2816. // as static fields of "Universe".
  2817. static void oops_do(OopClosure* f, bool do_all = false);
  2818. @@ -419,6 +434,7 @@
  2819. // Debugging
  2820. static bool verify_in_progress() { return _verify_in_progress; }
  2821. + static void set_verify_in_progress(bool b) { _verify_in_progress = b; }
  2822. static void verify(bool silent, VerifyOption option);
  2823. static void verify(bool silent) {
  2824. verify(silent, VerifyOption_Default /* option */);
  2825. diff -r 6c6a2299029a src/share/vm/oops/arrayKlass.cpp
  2826. --- a/src/share/vm/oops/arrayKlass.cpp Sat Dec 14 11:51:15 2013 -0800
  2827. +++ b/src/share/vm/oops/arrayKlass.cpp Mon Apr 28 13:12:30 2014 -0700
  2828. @@ -129,9 +129,9 @@
  2829. bool arrayKlass::compute_is_subtype_of(klassOop k) {
  2830. // An array is a subtype of Serializable, Clonable, and Object
  2831. - return k == SystemDictionary::Object_klass()
  2832. - || k == SystemDictionary::Cloneable_klass()
  2833. - || k == SystemDictionary::Serializable_klass();
  2834. + return k->klass_part()->newest_version() == SystemDictionary::Object_klass()->klass_part()->newest_version()
  2835. + || k->klass_part()->newest_version() == SystemDictionary::Cloneable_klass()->klass_part()->newest_version()
  2836. + || k->klass_part()->newest_version() == SystemDictionary::Serializable_klass()->klass_part()->newest_version();
  2837. }
  2838. diff -r 6c6a2299029a src/share/vm/oops/constMethodKlass.cpp
  2839. --- a/src/share/vm/oops/constMethodKlass.cpp Sat Dec 14 11:51:15 2013 -0800
  2840. +++ b/src/share/vm/oops/constMethodKlass.cpp Mon Apr 28 13:12:30 2014 -0700
  2841. @@ -102,6 +102,7 @@
  2842. constMethodOop cm = constMethodOop(obj);
  2843. MarkSweep::mark_and_push(cm->adr_constants());
  2844. MarkSweep::mark_and_push(cm->adr_stackmap_data());
  2845. + MarkSweep::mark_and_push(cm->adr_code_section_table());
  2846. // Performance tweak: We skip iterating over the klass pointer since we
  2847. // know that Universe::constMethodKlassObj never moves.
  2848. }
  2849. @@ -113,6 +114,7 @@
  2850. constMethodOop cm_oop = constMethodOop(obj);
  2851. PSParallelCompact::mark_and_push(cm, cm_oop->adr_constants());
  2852. PSParallelCompact::mark_and_push(cm, cm_oop->adr_stackmap_data());
  2853. + PSParallelCompact::mark_and_push(cm, cm_oop->adr_code_section_table());
  2854. // Performance tweak: We skip iterating over the klass pointer since we
  2855. // know that Universe::constMethodKlassObj never moves.
  2856. }
  2857. @@ -123,6 +125,7 @@
  2858. constMethodOop cm = constMethodOop(obj);
  2859. blk->do_oop(cm->adr_constants());
  2860. blk->do_oop(cm->adr_stackmap_data());
  2861. + blk->do_oop(cm->adr_code_section_table());
  2862. // Get size before changing pointers.
  2863. // Don't call size() or oop_size() since that is a virtual call.
  2864. int size = cm->object_size();
  2865. @@ -138,6 +141,8 @@
  2866. if (mr.contains(adr)) blk->do_oop(adr);
  2867. adr = cm->adr_stackmap_data();
  2868. if (mr.contains(adr)) blk->do_oop(adr);
  2869. + adr = cm->adr_code_section_table();
  2870. + if (mr.contains(adr)) blk->do_oop(adr);
  2871. // Get size before changing pointers.
  2872. // Don't call size() or oop_size() since that is a virtual call.
  2873. int size = cm->object_size();
  2874. @@ -152,6 +157,7 @@
  2875. constMethodOop cm = constMethodOop(obj);
  2876. MarkSweep::adjust_pointer(cm->adr_constants());
  2877. MarkSweep::adjust_pointer(cm->adr_stackmap_data());
  2878. + MarkSweep::adjust_pointer(cm->adr_code_section_table());
  2879. // Get size before changing pointers.
  2880. // Don't call size() or oop_size() since that is a virtual call.
  2881. int size = cm->object_size();
  2882. diff -r 6c6a2299029a src/share/vm/oops/constMethodOop.hpp
  2883. --- a/src/share/vm/oops/constMethodOop.hpp Sat Dec 14 11:51:15 2013 -0800
  2884. +++ b/src/share/vm/oops/constMethodOop.hpp Mon Apr 28 13:12:30 2014 -0700
  2885. @@ -129,7 +129,7 @@
  2886. public:
  2887. oop* oop_block_beg() const { return adr_constants(); }
  2888. - oop* oop_block_end() const { return adr_stackmap_data() + 1; }
  2889. + oop* oop_block_end() const { return adr_code_section_table() + 1; }
  2890. private:
  2891. //
  2892. @@ -141,6 +141,9 @@
  2893. // Raw stackmap data for the method
  2894. typeArrayOop _stackmap_data;
  2895. + // (tw) Table mapping code sections for method forward points.
  2896. + typeArrayOop _code_section_table;
  2897. +
  2898. //
  2899. // End of the oop block.
  2900. //
  2901. @@ -195,6 +198,28 @@
  2902. }
  2903. bool has_stackmap_table() const { return _stackmap_data != NULL; }
  2904. + // code section table
  2905. + typeArrayOop code_section_table() const { return _code_section_table; }
  2906. + void set_code_section_table(typeArrayOop e) { oop_store_without_check((oop*) &_code_section_table, (oop) e); }
  2907. + bool has_code_section_table() const { return code_section_table() != NULL && code_section_table()->length() > 0; }
  2908. + static const int ValuesPerCodeSectionEntry = 3;
  2909. + int code_section_entries() const {
  2910. + if (!has_code_section_table()) return 0;
  2911. + return _code_section_table->length() / ValuesPerCodeSectionEntry;
  2912. + }
  2913. +
  2914. + int code_section_new_index_at(int index) const {
  2915. + return _code_section_table->short_at(index * ValuesPerCodeSectionEntry);
  2916. + }
  2917. +
  2918. + int code_section_original_index_at(int index) const {
  2919. + return _code_section_table->short_at(index * ValuesPerCodeSectionEntry + 1);
  2920. + }
  2921. +
  2922. + int code_section_length_at(int index) const {
  2923. + return _code_section_table->short_at(index * ValuesPerCodeSectionEntry + 2);
  2924. + }
  2925. +
  2926. void init_fingerprint() {
  2927. const uint64_t initval = CONST64(0x8000000000000000);
  2928. _fingerprint = initval;
  2929. @@ -301,6 +326,7 @@
  2930. // Garbage collection support
  2931. oop* adr_constants() const { return (oop*)&_constants; }
  2932. oop* adr_stackmap_data() const { return (oop*)&_stackmap_data; }
  2933. + oop* adr_code_section_table() const { return (oop*)&_code_section_table; }
  2934. bool is_conc_safe() { return _is_conc_safe; }
  2935. void set_is_conc_safe(bool v) { _is_conc_safe = v; }
  2936. diff -r 6c6a2299029a src/share/vm/oops/cpCacheOop.cpp
  2937. --- a/src/share/vm/oops/cpCacheOop.cpp Sat Dec 14 11:51:15 2013 -0800
  2938. +++ b/src/share/vm/oops/cpCacheOop.cpp Mon Apr 28 13:12:30 2014 -0700
  2939. @@ -37,9 +37,15 @@
  2940. // Implememtation of ConstantPoolCacheEntry
  2941. +void ConstantPoolCacheEntry::copy_from(ConstantPoolCacheEntry *other) {
  2942. + _flags = other->_flags; // flags
  2943. +}
  2944. +
  2945. void ConstantPoolCacheEntry::initialize_entry(int index) {
  2946. assert(0 < index && index < 0x10000, "sanity check");
  2947. _indices = index;
  2948. + _f1 = NULL;
  2949. + _f2 = 0;
  2950. assert(constant_pool_index() == index, "");
  2951. }
  2952. @@ -162,7 +168,8 @@
  2953. int vtable_index) {
  2954. assert(!is_secondary_entry(), "");
  2955. assert(method->interpreter_entry() != NULL, "should have been set at this point");
  2956. - assert(!method->is_obsolete(), "attempt to write obsolete method to cpCache");
  2957. + // (tw) No longer valid assert
  2958. + //assert(!method->is_obsolete(), "attempt to write obsolete method to cpCache");
  2959. int byte_no = -1;
  2960. bool change_to_virtual = false;
  2961. @@ -183,6 +190,7 @@
  2962. set_method_flags(as_TosState(method->result_type()),
  2963. ( 1 << is_vfinal_shift) |
  2964. ((method->is_final_method() ? 1 : 0) << is_final_shift) |
  2965. + ((method->is_old() ? 1 : 0) << is_old_method_shift) |
  2966. ((change_to_virtual ? 1 : 0) << is_forced_virtual_shift),
  2967. method()->size_of_parameters());
  2968. set_f2_as_vfinal_method(method());
  2969. @@ -190,9 +198,13 @@
  2970. assert(vtable_index >= 0, "valid index");
  2971. assert(!method->is_final_method(), "sanity");
  2972. set_method_flags(as_TosState(method->result_type()),
  2973. + ((method->is_old() ? 1 : 0) << is_old_method_shift) |
  2974. ((change_to_virtual ? 1 : 0) << is_forced_virtual_shift),
  2975. method()->size_of_parameters());
  2976. set_f2(vtable_index);
  2977. +
  2978. + // (tw) save method holder in f1 for virtual calls
  2979. + set_f1(method());
  2980. }
  2981. byte_no = 2;
  2982. break;
  2983. @@ -206,7 +218,8 @@
  2984. // Once is_vfinal is set, it must stay that way, lest we get a dangling oop.
  2985. set_method_flags(as_TosState(method->result_type()),
  2986. ((is_vfinal() ? 1 : 0) << is_vfinal_shift) |
  2987. - ((method->is_final_method() ? 1 : 0) << is_final_shift),
  2988. + ((method->is_final_method() ? 1 : 0) << is_final_shift) |
  2989. + ((method->is_old() ? 1 : 0) << is_old_method_shift),
  2990. method()->size_of_parameters());
  2991. set_f1(method());
  2992. byte_no = 1;
  2993. @@ -259,7 +272,7 @@
  2994. set_f1(interf);
  2995. set_f2(index);
  2996. set_method_flags(as_TosState(method->result_type()),
  2997. - 0, // no option bits
  2998. + ((method->is_old() ? 1 : 0) << is_old_method_shift),
  2999. method()->size_of_parameters());
  3000. set_bytecode_1(Bytecodes::_invokeinterface);
  3001. }
  3002. @@ -520,27 +533,12 @@
  3003. // If this constantPoolCacheEntry refers to old_method then update it
  3004. // to refer to new_method.
  3005. bool ConstantPoolCacheEntry::adjust_method_entry(methodOop old_method,
  3006. - methodOop new_method, bool * trace_name_printed) {
  3007. + methodOop new_method) {
  3008. if (is_vfinal()) {
  3009. - // virtual and final so _f2 contains method ptr instead of vtable index
  3010. - if (f2_as_vfinal_method() == old_method) {
  3011. - // match old_method so need an update
  3012. - // NOTE: can't use set_f2_as_vfinal_method as it asserts on different values
  3013. - _f2 = (intptr_t)new_method;
  3014. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  3015. - if (!(*trace_name_printed)) {
  3016. - // RC_TRACE_MESG macro has an embedded ResourceMark
  3017. - RC_TRACE_MESG(("adjust: name=%s",
  3018. - Klass::cast(old_method->method_holder())->external_name()));
  3019. - *trace_name_printed = true;
  3020. - }
  3021. - // RC_TRACE macro has an embedded ResourceMark
  3022. - RC_TRACE(0x00400000, ("cpc vf-entry update: %s(%s)",
  3023. - new_method->name()->as_C_string(),
  3024. - new_method->signature()->as_C_string()));
  3025. - }
  3026. -
  3027. + // virtual and final so f2() contains method ptr instead of vtable index
  3028. + if (f2_as_vfinal_method() != NULL && f2_as_vfinal_method()->method_holder()->klass_part()->new_version()) {
  3029. + initialize_entry(constant_pool_index());
  3030. return true;
  3031. }
  3032. @@ -548,84 +546,27 @@
  3033. return false;
  3034. }
  3035. - if ((oop)_f1 == NULL) {
  3036. - // NULL f1() means this is a virtual entry so bail out
  3037. - // We are assuming that the vtable index does not need change.
  3038. + // (tw) check how to update interface methods!
  3039. + if (bytecode_1() == Bytecodes::_invokevirtual || bytecode_2() == Bytecodes::_invokevirtual) {
  3040. +
  3041. + if(f1_as_method()->method_holder()->klass_part()->new_version()) {
  3042. + initialize_entry(constant_pool_index());
  3043. + return true;
  3044. + }
  3045. +
  3046. return false;
  3047. }
  3048. if ((oop)_f1 == old_method) {
  3049. _f1 = new_method;
  3050. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  3051. - if (!(*trace_name_printed)) {
  3052. - // RC_TRACE_MESG macro has an embedded ResourceMark
  3053. - RC_TRACE_MESG(("adjust: name=%s",
  3054. - Klass::cast(old_method->method_holder())->external_name()));
  3055. - *trace_name_printed = true;
  3056. - }
  3057. - // RC_TRACE macro has an embedded ResourceMark
  3058. - RC_TRACE(0x00400000, ("cpc entry update: %s(%s)",
  3059. - new_method->name()->as_C_string(),
  3060. - new_method->signature()->as_C_string()));
  3061. - }
  3062. -
  3063. return true;
  3064. + } else if(_f1 != NULL && (bytecode_1() != Bytecodes::_invokeinterface && f1_as_method()->method_holder()->klass_part()->new_version())) {
  3065. + initialize_entry(constant_pool_index());
  3066. }
  3067. return false;
  3068. }
  3069. -// a constant pool cache entry should never contain old or obsolete methods
  3070. -bool ConstantPoolCacheEntry::check_no_old_or_obsolete_entries() {
  3071. - if (is_vfinal()) {
  3072. - // virtual and final so _f2 contains method ptr instead of vtable index
  3073. - methodOop m = (methodOop)_f2;
  3074. - // Return false if _f2 refers to an old or an obsolete method.
  3075. - // _f2 == NULL || !m->is_method() are just as unexpected here.
  3076. - return (m != NULL && m->is_method() && !m->is_old() && !m->is_obsolete());
  3077. - } else if ((oop)_f1 == NULL || !((oop)_f1)->is_method()) {
  3078. - // _f1 == NULL || !_f1->is_method() are OK here
  3079. - return true;
  3080. - }
  3081. -
  3082. - methodOop m = (methodOop)_f1;
  3083. - // return false if _f1 refers to an old or an obsolete method
  3084. - return (!m->is_old() && !m->is_obsolete());
  3085. -}
  3086. -
  3087. -bool ConstantPoolCacheEntry::is_interesting_method_entry(klassOop k) {
  3088. - if (!is_method_entry()) {
  3089. - // not a method entry so not interesting by default
  3090. - return false;
  3091. - }
  3092. -
  3093. - methodOop m = NULL;
  3094. - if (is_vfinal()) {
  3095. - // virtual and final so _f2 contains method ptr instead of vtable index
  3096. - m = f2_as_vfinal_method();
  3097. - } else if (is_f1_null()) {
  3098. - // NULL _f1 means this is a virtual entry so also not interesting
  3099. - return false;
  3100. - } else {
  3101. - oop f1 = _f1; // _f1 is volatile
  3102. - if (!f1->is_method()) {
  3103. - // _f1 can also contain a klassOop for an interface
  3104. - return false;
  3105. - }
  3106. - m = f1_as_method();
  3107. - }
  3108. -
  3109. - assert(m != NULL && m->is_method(), "sanity check");
  3110. - if (m == NULL || !m->is_method() || (k != NULL && m->method_holder() != k)) {
  3111. - // robustness for above sanity checks or method is not in
  3112. - // the interesting class
  3113. - return false;
  3114. - }
  3115. -
  3116. - // the method is in the interesting class so the entry is interesting
  3117. - return true;
  3118. -}
  3119. -
  3120. void ConstantPoolCacheEntry::print(outputStream* st, int index) const {
  3121. // print separator
  3122. if (index == 0) st->print_cr(" -------------");
  3123. @@ -663,60 +604,18 @@
  3124. }
  3125. }
  3126. -// RedefineClasses() API support:
  3127. -// If any entry of this constantPoolCache points to any of
  3128. -// old_methods, replace it with the corresponding new_method.
  3129. -void constantPoolCacheOopDesc::adjust_method_entries(methodOop* old_methods, methodOop* new_methods,
  3130. - int methods_length, bool * trace_name_printed) {
  3131. -
  3132. - if (methods_length == 0) {
  3133. - // nothing to do if there are no methods
  3134. - return;
  3135. - }
  3136. -
  3137. - // get shorthand for the interesting class
  3138. - klassOop old_holder = old_methods[0]->method_holder();
  3139. +void constantPoolCacheOopDesc::adjust_entries(methodOop* old_methods, methodOop* new_methods,
  3140. + int methods_length) {
  3141. for (int i = 0; i < length(); i++) {
  3142. - if (!entry_at(i)->is_interesting_method_entry(old_holder)) {
  3143. - // skip uninteresting methods
  3144. - continue;
  3145. - }
  3146. -
  3147. - // The constantPoolCache contains entries for several different
  3148. - // things, but we only care about methods. In fact, we only care
  3149. - // about methods in the same class as the one that contains the
  3150. - // old_methods. At this point, we have an interesting entry.
  3151. -
  3152. - for (int j = 0; j < methods_length; j++) {
  3153. - methodOop old_method = old_methods[j];
  3154. - methodOop new_method = new_methods[j];
  3155. -
  3156. - if (entry_at(i)->adjust_method_entry(old_method, new_method,
  3157. - trace_name_printed)) {
  3158. - // current old_method matched this entry and we updated it so
  3159. - // break out and get to the next interesting entry if there one
  3160. - break;
  3161. - }
  3162. + if (entry_at(i)->is_field_entry()) {
  3163. + // (tw) TODO: Update only field offsets and modify only constant pool entries that
  3164. + // point to changed fields
  3165. + entry_at(i)->initialize_entry(entry_at(i)->constant_pool_index());
  3166. + } else if(entry_at(i)->is_method_entry()) {
  3167. + entry_at(i)->adjust_method_entry(NULL, NULL);
  3168. }
  3169. }
  3170. }
  3171. -// the constant pool cache should never contain old or obsolete methods
  3172. -bool constantPoolCacheOopDesc::check_no_old_or_obsolete_entries() {
  3173. - for (int i = 1; i < length(); i++) {
  3174. - if (entry_at(i)->is_interesting_method_entry(NULL) &&
  3175. - !entry_at(i)->check_no_old_or_obsolete_entries()) {
  3176. - return false;
  3177. - }
  3178. - }
  3179. - return true;
  3180. -}
  3181. -void constantPoolCacheOopDesc::dump_cache() {
  3182. - for (int i = 1; i < length(); i++) {
  3183. - if (entry_at(i)->is_interesting_method_entry(NULL)) {
  3184. - entry_at(i)->print(tty, i);
  3185. - }
  3186. - }
  3187. -}
  3188. diff -r 6c6a2299029a src/share/vm/oops/cpCacheOop.hpp
  3189. --- a/src/share/vm/oops/cpCacheOop.hpp Sat Dec 14 11:51:15 2013 -0800
  3190. +++ b/src/share/vm/oops/cpCacheOop.hpp Mon Apr 28 13:12:30 2014 -0700
  3191. @@ -136,7 +136,8 @@
  3192. void set_bytecode_2(Bytecodes::Code code);
  3193. void set_f1(oop f1) {
  3194. oop existing_f1 = _f1; // read once
  3195. - assert(existing_f1 == NULL || existing_f1 == f1, "illegal field change");
  3196. + // (tw) need to relax assertion for redefinition
  3197. + // assert(existing_f1 == NULL || existing_f1 == f1, "illegal field change");
  3198. oop_store(&_f1, f1);
  3199. }
  3200. void release_set_f1(oop f1);
  3201. @@ -167,6 +168,7 @@
  3202. tos_state_mask = right_n_bits(tos_state_bits),
  3203. tos_state_shift = BitsPerInt - tos_state_bits, // see verify_tos_state_shift below
  3204. // misc. option bits; can be any bit position in [16..27]
  3205. + is_old_method_shift = 19,
  3206. is_vfinal_shift = 20,
  3207. is_volatile_shift = 21,
  3208. is_final_shift = 22,
  3209. @@ -200,6 +202,8 @@
  3210. void initialize_entry(int original_index); // initialize primary entry
  3211. void initialize_secondary_entry(int main_index); // initialize secondary entry
  3212. + void copy_from(ConstantPoolCacheEntry *other);
  3213. +
  3214. void set_field( // sets entry to resolved field state
  3215. Bytecodes::Code get_code, // the bytecode used for reading the field
  3216. Bytecodes::Code put_code, // the bytecode used for writing the field
  3217. @@ -361,10 +365,7 @@
  3218. // trace_name_printed is set to true if the current call has
  3219. // printed the klass name so that other routines in the adjust_*
  3220. // group don't print the klass name.
  3221. - bool adjust_method_entry(methodOop old_method, methodOop new_method,
  3222. - bool * trace_name_printed);
  3223. - bool check_no_old_or_obsolete_entries();
  3224. - bool is_interesting_method_entry(klassOop k);
  3225. + bool adjust_method_entry(methodOop old_method, methodOop new_method);
  3226. // Debugging & Printing
  3227. void print (outputStream* st, int index) const;
  3228. @@ -485,16 +486,9 @@
  3229. return (base_offset() + ConstantPoolCacheEntry::size_in_bytes() * index);
  3230. }
  3231. - // RedefineClasses() API support:
  3232. - // If any entry of this constantPoolCache points to any of
  3233. - // old_methods, replace it with the corresponding new_method.
  3234. - // trace_name_printed is set to true if the current call has
  3235. - // printed the klass name so that other routines in the adjust_*
  3236. - // group don't print the klass name.
  3237. - void adjust_method_entries(methodOop* old_methods, methodOop* new_methods,
  3238. - int methods_length, bool * trace_name_printed);
  3239. - bool check_no_old_or_obsolete_entries();
  3240. - void dump_cache();
  3241. + // (tw) Update method and field references
  3242. + void adjust_entries(methodOop* old_methods, methodOop* new_methods,
  3243. + int methods_length);
  3244. };
  3245. #endif // SHARE_VM_OOPS_CPCACHEOOP_HPP
  3246. diff -r 6c6a2299029a src/share/vm/oops/instanceKlass.cpp
  3247. --- a/src/share/vm/oops/instanceKlass.cpp Sat Dec 14 11:51:15 2013 -0800
  3248. +++ b/src/share/vm/oops/instanceKlass.cpp Mon Apr 28 13:12:30 2014 -0700
  3249. @@ -250,12 +250,118 @@
  3250. }
  3251. +void instanceKlass::initialize_redefined_class() {
  3252. + RC_TRACE(0x00000400, ("initializing redefined class %s",
  3253. + name()->as_C_string()));
  3254. +
  3255. + assert(!is_initialized(), "");
  3256. + assert(this->old_version() != NULL, "");
  3257. + assert(is_linked(), "must be linked before");
  3258. +
  3259. +
  3260. + instanceKlassHandle this_oop(Thread::current(), this->as_klassOop());
  3261. + class UpdateStaticFieldClosure : public FieldClosure {
  3262. +
  3263. + private:
  3264. + instanceKlassHandle this_oop;
  3265. +
  3266. + public:
  3267. + UpdateStaticFieldClosure(instanceKlassHandle this_oop) {
  3268. + this->this_oop = this_oop;
  3269. + }
  3270. +
  3271. + virtual void do_field(fieldDescriptor* fd) {
  3272. + fieldDescriptor result;
  3273. + bool found = ((instanceKlass *)(this_oop->old_version()->klass_part()))->find_local_field(fd->name(), fd->signature(), &result);
  3274. +
  3275. + if (found && result.is_static()) {
  3276. + int old_offset = result.offset();
  3277. + assert(result.field_type() == fd->field_type(), "Old and new field type does not match");
  3278. +
  3279. + oop new_location = this_oop()->java_mirror();
  3280. + oop old_location = this_oop->old_version()->java_mirror();
  3281. + int offset = fd->offset();
  3282. + RC_TRACE(0x00000400, ("Copying static field value for field '%s' old_offset=%d new_offset=%d",
  3283. + fd->name()->as_C_string(), old_offset, offset));
  3284. +
  3285. + oop cur_oop;
  3286. +
  3287. + switch(result.field_type()) {
  3288. +
  3289. + // Found static field with same name and type in the old klass => copy value from old to new klass
  3290. +
  3291. + case T_BOOLEAN:
  3292. + new_location->bool_field_put(offset, old_location->bool_field(old_offset));
  3293. + DEBUG_ONLY(old_location->byte_field_put(old_offset, 0));
  3294. + break;
  3295. +
  3296. + case T_CHAR:
  3297. + new_location->char_field_put(offset, old_location->char_field(old_offset));
  3298. + DEBUG_ONLY(old_location->char_field_put(old_offset, 0));
  3299. + break;
  3300. +
  3301. + case T_FLOAT:
  3302. + new_location->float_field_put(offset, old_location->float_field(old_offset));
  3303. + DEBUG_ONLY(old_location->float_field_put(old_offset, 0));
  3304. + break;
  3305. +
  3306. + case T_DOUBLE:
  3307. + new_location->double_field_put(offset, old_location->double_field(old_offset));
  3308. + DEBUG_ONLY(old_location->double_field_put(old_offset, 0));
  3309. + break;
  3310. +
  3311. + case T_BYTE:
  3312. + new_location->byte_field_put(offset, old_location->byte_field(old_offset));
  3313. + DEBUG_ONLY(old_location->byte_field_put(old_offset, 0));
  3314. + break;
  3315. +
  3316. + case T_SHORT:
  3317. + new_location->short_field_put(offset, old_location->short_field(old_offset));
  3318. + DEBUG_ONLY(old_location->short_field_put(old_offset, 0));
  3319. + break;
  3320. +
  3321. + case T_INT:
  3322. + new_location->int_field_put(offset, old_location->int_field(old_offset));
  3323. + DEBUG_ONLY(old_location->int_field_put(old_offset, 0));
  3324. + break;
  3325. +
  3326. + case T_LONG:
  3327. + new_location->long_field_put(offset, old_location->long_field(old_offset));
  3328. + DEBUG_ONLY(old_location->long_field_put(old_offset, 0));
  3329. + break;
  3330. +
  3331. + case T_OBJECT:
  3332. + case T_ARRAY:
  3333. + cur_oop = old_location->obj_field(old_offset);
  3334. + new_location->obj_field_put_raw(offset, cur_oop);
  3335. + old_location->obj_field_put_raw(old_offset, NULL);
  3336. + break;
  3337. +
  3338. + default:
  3339. + ShouldNotReachHere();
  3340. + }
  3341. + } else {
  3342. + RC_TRACE(0x00000200, ("New static field %s has_initial_value=%d",
  3343. + fd->name()->as_C_string(), (int)(fd->has_initial_value())));
  3344. + // field not found
  3345. + // (tw) TODO: Probably this call is not necessary here!
  3346. + // FIXME: idubrov
  3347. + //ClassFileParser::initialize_static_field(fd, Thread::current());
  3348. + }
  3349. + }
  3350. + };
  3351. +
  3352. + UpdateStaticFieldClosure cl(this_oop);
  3353. + this->do_local_static_fields(&cl);
  3354. +}
  3355. +
  3356. +
  3357. bool instanceKlass::verify_code(
  3358. instanceKlassHandle this_oop, bool throw_verifyerror, TRAPS) {
  3359. // 1) Verify the bytecodes
  3360. Verifier::Mode mode =
  3361. throw_verifyerror ? Verifier::ThrowException : Verifier::NoException;
  3362. - return Verifier::verify(this_oop, mode, this_oop->should_verify_class(), CHECK_false);
  3363. + return Verifier::verify(this_oop, mode, this_oop->should_verify_class(), true, CHECK_false);
  3364. }
  3365. @@ -362,7 +468,13 @@
  3366. jt->get_thread_stat()->perf_recursion_counts_addr(),
  3367. jt->get_thread_stat()->perf_timers_addr(),
  3368. PerfClassTraceTime::CLASS_VERIFY);
  3369. - bool verify_ok = verify_code(this_oop, throw_verifyerror, THREAD);
  3370. + if (this_oop->is_redefining()) {
  3371. + Thread::current()->set_pretend_new_universe(true);
  3372. + }
  3373. + bool verify_ok = verify_code(this_oop, throw_verifyerror, THREAD);
  3374. + if (this_oop->is_redefining()) {
  3375. + Thread::current()->set_pretend_new_universe(false);
  3376. + }
  3377. if (!verify_ok) {
  3378. return false;
  3379. }
  3380. @@ -400,7 +512,8 @@
  3381. }
  3382. #endif
  3383. this_oop->set_init_state(linked);
  3384. - if (JvmtiExport::should_post_class_prepare()) {
  3385. + // (tw) Must check for old version in order to prevent infinite loops.
  3386. + if (JvmtiExport::should_post_class_prepare() && this_oop->old_version() == NULL /* JVMTI deadlock otherwise */) {
  3387. Thread *thread = THREAD;
  3388. assert(thread->is_Java_thread(), "thread->is_Java_thread()");
  3389. JvmtiExport::post_class_prepare((JavaThread *) thread, this_oop());
  3390. @@ -673,6 +786,18 @@
  3391. return false;
  3392. }
  3393. +bool instanceKlass::implements_interface_any_version(klassOop k) const {
  3394. + k = k->klass_part()->newest_version();
  3395. + if (this->newest_version() == k) return true;
  3396. + assert(Klass::cast(k)->is_interface(), "should be an interface class");
  3397. + for (int i = 0; i < transitive_interfaces()->length(); i++) {
  3398. + if (((klassOop)transitive_interfaces()->obj_at(i))->klass_part()->newest_version() == k) {
  3399. + return true;
  3400. + }
  3401. + }
  3402. + return false;
  3403. +}
  3404. +
  3405. objArrayOop instanceKlass::allocate_objArray(int n, int length, TRAPS) {
  3406. if (length < 0) THROW_0(vmSymbols::java_lang_NegativeArraySizeException());
  3407. if (length > arrayOopDesc::max_array_length(T_OBJECT)) {
  3408. @@ -801,7 +926,25 @@
  3409. }
  3410. void instanceKlass::call_class_initializer_impl(instanceKlassHandle this_oop, TRAPS) {
  3411. +
  3412. + ResourceMark rm(THREAD);
  3413. methodHandle h_method(THREAD, this_oop->class_initializer());
  3414. +
  3415. + if (this_oop->revision_number() != -1){
  3416. + methodOop m = NULL;
  3417. + if (AllowAdvancedClassRedefinition) {
  3418. + m = this_oop->find_method(vmSymbols::static_transformer_name(), vmSymbols::void_method_signature());
  3419. + }
  3420. + methodHandle method(m);
  3421. + if (method() != NULL && method()->is_static()) {
  3422. + RC_TRACE(0x00000200, ("Calling static transformer instead of static initializer"));
  3423. + h_method = method;
  3424. + } else if (!((instanceKlass*)this_oop->old_version()->klass_part())->is_not_initialized()) {
  3425. + // Only execute the static initializer, if it was not yet executed for the old version of the class.
  3426. + return;
  3427. + }
  3428. + }
  3429. +
  3430. assert(!this_oop->is_initialized(), "we cannot initialize twice");
  3431. if (TraceClassInitialization) {
  3432. tty->print("%d Initializing ", call_class_initializer_impl_counter++);
  3433. @@ -949,6 +1092,137 @@
  3434. }
  3435. }
  3436. +void instanceKlass::store_update_information(GrowableArray<int> &values) {
  3437. + int *arr = NEW_C_HEAP_ARRAY(int, values.length(), mtClass);
  3438. + for (int i=0; i<values.length(); i++) {
  3439. + arr[i] = values.at(i);
  3440. + }
  3441. + set_update_information(arr);
  3442. +}
  3443. +
  3444. +void instanceKlass::clear_update_information() {
  3445. + FREE_C_HEAP_ARRAY(int, update_information(), mtClass);
  3446. + set_update_information(NULL);
  3447. +}
  3448. +
  3449. +typedef Pair<int, klassOop> typeInfoPair;
  3450. +
  3451. +void instanceKlass::store_type_check_information(GrowableArray< Pair<int, klassOop> > &values) {
  3452. + Pair<int, klassOop> *arr = NEW_C_HEAP_ARRAY(typeInfoPair, values.length(), mtClass);
  3453. + for (int i=0; i<values.length(); i++) {
  3454. + arr[i] = values.at(i);
  3455. + }
  3456. + set_type_check_information(arr);
  3457. +}
  3458. +
  3459. +void instanceKlass::clear_type_check_information() {
  3460. + FREE_C_HEAP_ARRAY(typeInfoPair, type_check_information(), mtClass);
  3461. + set_type_check_information(NULL);
  3462. +}
  3463. +
  3464. +void instanceKlass::do_fields_evolution(FieldEvolutionClosure* cl) {
  3465. +
  3466. + assert (old_version() != NULL, "must have old version!");
  3467. +
  3468. + klassOop old_klass_oop = old_version();
  3469. + instanceKlass *old_klass = instanceKlass::cast(old_klass_oop);
  3470. + instanceKlass *new_klass = this;
  3471. +
  3472. + fieldDescriptor fd;
  3473. + fieldDescriptor old_fd;
  3474. +
  3475. + instanceKlass *cur_new_klass = new_klass;
  3476. + klassOop cur_new_klass_oop = this->as_klassOop();
  3477. +
  3478. + if (_fields_not_changed) {
  3479. +
  3480. + class MyFieldClosure : public FieldClosure {
  3481. +
  3482. + FieldEvolutionClosure *_cl;
  3483. + public:
  3484. + MyFieldClosure(FieldEvolutionClosure *cl) {_cl = cl; }
  3485. + virtual void do_field(fieldDescriptor* fd) {
  3486. + _cl->do_changed_field(fd, fd);
  3487. + }
  3488. + };
  3489. +
  3490. + MyFieldClosure mfc(cl);
  3491. + do_nonstatic_fields(&mfc);
  3492. + } else {
  3493. +
  3494. + _fields_not_changed = true;
  3495. + GrowableArray<fieldDescriptor> fds;
  3496. + while (true) {
  3497. + for (JavaFieldStream fs(cur_new_klass); !fs.done(); fs.next()) {
  3498. + fd.initialize(cur_new_klass_oop, fs.index());
  3499. + if (fd.is_static()) {
  3500. + continue;
  3501. + }
  3502. + fds.append(fd);
  3503. + }
  3504. +
  3505. + if (cur_new_klass->super() != NULL) {
  3506. + cur_new_klass_oop = cur_new_klass->super();
  3507. + cur_new_klass = instanceKlass::cast(cur_new_klass_oop);
  3508. + } else {
  3509. + break;
  3510. + }
  3511. + }
  3512. +
  3513. + GrowableArray<fieldDescriptor> sortedFds;
  3514. + while (fds.length() > 0) {
  3515. + int minOffset = 0x7fffffff;
  3516. + int minIndex = -1;
  3517. + for (int i=0; i<fds.length(); i++) {
  3518. + int curOffset = fds.adr_at(i)->offset();
  3519. + if (curOffset < minOffset) {
  3520. + minOffset = curOffset;
  3521. + minIndex = i;
  3522. + }
  3523. + }
  3524. +
  3525. + sortedFds.append(fds.at(minIndex));
  3526. + fds.remove_at(minIndex);
  3527. + }
  3528. +
  3529. +
  3530. + for (int i=0; i<sortedFds.length(); i++) {
  3531. + fieldDescriptor &fd = *sortedFds.adr_at(i);
  3532. +
  3533. + char found = 0;
  3534. + instanceKlass *cur_old_klass = old_klass;
  3535. + klassOop cur_old_klass_oop = old_klass_oop;
  3536. + while (true) {
  3537. + for (JavaFieldStream fs(cur_old_klass); !fs.done(); fs.next()) {
  3538. + old_fd.initialize(cur_old_klass_oop, fs.index());
  3539. + if (old_fd.is_static()) {
  3540. + continue;
  3541. + }
  3542. + if (old_fd.name() == fd.name() && old_fd.signature() == fd.signature()) {
  3543. + found = 1;
  3544. + break;
  3545. + }
  3546. + }
  3547. + if (!found && cur_old_klass->super()) {
  3548. + cur_old_klass_oop = cur_old_klass->super();
  3549. + cur_old_klass = instanceKlass::cast(cur_old_klass_oop);
  3550. + } else {
  3551. + break;
  3552. + }
  3553. + }
  3554. +
  3555. + if (found) {
  3556. + if (old_fd.offset() != fd.offset()) {
  3557. + _fields_not_changed = false;
  3558. + }
  3559. + cl->do_changed_field(&old_fd, &fd);
  3560. + } else {
  3561. + _fields_not_changed = false;
  3562. + cl->do_new_field(&fd);
  3563. + }
  3564. + }
  3565. + }
  3566. +}
  3567. void instanceKlass::do_local_static_fields(FieldClosure* cl) {
  3568. for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
  3569. @@ -1368,6 +1642,20 @@
  3570. return id;
  3571. }
  3572. +bool instanceKlass::update_jmethod_id(methodOop method, jmethodID newMethodID) {
  3573. + size_t idnum = (size_t)method->method_idnum();
  3574. + jmethodID* jmeths = methods_jmethod_ids_acquire();
  3575. + size_t length; // length assigned as debugging crumb
  3576. + jmethodID id = NULL;
  3577. + if (jmeths != NULL && // If there is a cache
  3578. + (length = (size_t)jmeths[0]) > idnum) { // and if it is long enough,
  3579. + jmeths[idnum+1] = newMethodID; // Set the id (may be NULL)
  3580. + return true;
  3581. + }
  3582. +
  3583. + return false;
  3584. +}
  3585. +
  3586. // Cache an itable index
  3587. void instanceKlass::set_cached_itable_index(size_t idnum, int index) {
  3588. @@ -1527,6 +1815,13 @@
  3589. last = b;
  3590. b = b->next();
  3591. }
  3592. +
  3593. + // (tw) Hack as dependencies get wrong version of klassOop
  3594. + if(this->old_version() != NULL) {
  3595. + ((instanceKlass *)this->old_version()->klass_part())->remove_dependent_nmethod(nm);
  3596. + return;
  3597. + }
  3598. +
  3599. #ifdef ASSERT
  3600. tty->print_cr("### %s can't find dependent nmethod:", this->external_name());
  3601. nm->print();
  3602. @@ -2382,6 +2677,9 @@
  3603. klassOop mirrored_klass = java_lang_Class::as_klassOop(obj);
  3604. st->print(BULLET"fake entry for mirror: ");
  3605. mirrored_klass->print_value_on(st);
  3606. + if (mirrored_klass != NULL) {
  3607. + 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());
  3608. + }
  3609. st->cr();
  3610. st->print(BULLET"fake entry resolved_constructor: ");
  3611. methodOop ctor = java_lang_Class::resolved_constructor(obj);
  3612. diff -r 6c6a2299029a src/share/vm/oops/instanceKlass.hpp
  3613. --- a/src/share/vm/oops/instanceKlass.hpp Sat Dec 14 11:51:15 2013 -0800
  3614. +++ b/src/share/vm/oops/instanceKlass.hpp Mon Apr 28 13:12:30 2014 -0700
  3615. @@ -101,6 +101,22 @@
  3616. virtual void do_field(fieldDescriptor* fd) = 0;
  3617. };
  3618. +// (tw) Iterates over the fields of the old and new class
  3619. +class FieldEvolutionClosure : public StackObj {
  3620. +public:
  3621. + virtual void do_new_field(fieldDescriptor* fd) = 0;
  3622. + virtual void do_old_field(fieldDescriptor* fd) = 0;
  3623. + virtual void do_changed_field(fieldDescriptor* old_fd, fieldDescriptor *new_fd) = 0;
  3624. +};
  3625. +
  3626. +// (tw) Iterates over the methods of the old and new class
  3627. +class MethodEvolutionClosure : public StackObj {
  3628. +public:
  3629. + virtual void do_new_method(methodOop oop) = 0;
  3630. + virtual void do_old_method(methodOop oop) = 0;
  3631. + virtual void do_changed_method(methodOop oldOop, methodOop newOop) = 0;
  3632. +};
  3633. +
  3634. #ifndef PRODUCT
  3635. // Print fields.
  3636. // If "obj" argument to constructor is NULL, prints static fields, otherwise prints non-static fields.
  3637. @@ -285,6 +301,11 @@
  3638. // _idnum_allocated_count.
  3639. u1 _init_state; // state of class
  3640. + // (tw) Field that allows for a short-path when calculating updated fields for the second time and
  3641. + // no fields changed. Testing performance impact with this, can be removed later when the update
  3642. + // information is cached.
  3643. + bool _fields_not_changed;
  3644. +
  3645. u1 _reference_type; // reference type
  3646. // embedded Java vtable follows here
  3647. @@ -452,6 +473,7 @@
  3648. // initialization (virtuals from Klass)
  3649. bool should_be_initialized() const; // means that initialize should be called
  3650. void initialize(TRAPS);
  3651. + void initialize_redefined_class();
  3652. void link_class(TRAPS);
  3653. bool link_class_or_fail(TRAPS); // returns false on failure
  3654. void unlink_class();
  3655. @@ -629,6 +651,7 @@
  3656. static void get_jmethod_id_length_value(jmethodID* cache, size_t idnum,
  3657. size_t *length_p, jmethodID* id_p);
  3658. jmethodID jmethod_id_or_null(methodOop method);
  3659. + bool update_jmethod_id(methodOop method, jmethodID newMethodID);
  3660. // cached itable index support
  3661. void set_cached_itable_index(size_t idnum, int index);
  3662. @@ -711,6 +734,7 @@
  3663. // subclass/subinterface checks
  3664. bool implements_interface(klassOop k) const;
  3665. + bool implements_interface_any_version(klassOop k) const;
  3666. // Access to the implementor of an interface.
  3667. klassOop implementor() const
  3668. @@ -760,6 +784,12 @@
  3669. void do_local_static_fields(FieldClosure* cl);
  3670. void do_nonstatic_fields(FieldClosure* cl); // including inherited fields
  3671. void do_local_static_fields(void f(fieldDescriptor*, TRAPS), TRAPS);
  3672. + void do_fields_evolution(FieldEvolutionClosure *cl);
  3673. + void store_update_information(GrowableArray<int> &values);
  3674. + void clear_update_information();
  3675. + void store_type_check_information(GrowableArray< Pair<int, klassOop> > &values);
  3676. + void clear_type_check_information();
  3677. +
  3678. void methods_do(void f(methodOop method));
  3679. void array_klasses_do(void f(klassOop k));
  3680. diff -r 6c6a2299029a src/share/vm/oops/instanceKlassKlass.cpp
  3681. --- a/src/share/vm/oops/instanceKlassKlass.cpp Sat Dec 14 11:51:15 2013 -0800
  3682. +++ b/src/share/vm/oops/instanceKlassKlass.cpp Mon Apr 28 13:12:30 2014 -0700
  3683. @@ -480,6 +480,28 @@
  3684. instanceKlass* ik = instanceKlass::cast(klassOop(obj));
  3685. klassKlass::oop_print_on(obj, st);
  3686. + // (tw) Output revision number and revision numbers of older / newer and oldest / newest version of this class.
  3687. +
  3688. + st->print(BULLET"revision: %d", ik->revision_number());
  3689. +
  3690. + if (ik->new_version() != NULL) {
  3691. + st->print(" (newer=%d)", ik->new_version()->klass_part()->revision_number());
  3692. + }
  3693. +
  3694. + if (ik->newest_version() != ik->new_version() && ik->newest_version() != obj) {
  3695. + st->print(" (newest=%d)", ik->newest_version()->klass_part()->revision_number());
  3696. + }
  3697. +
  3698. + if (ik->old_version() != NULL) {
  3699. + st->print(" (old=%d)", ik->old_version()->klass_part()->revision_number());
  3700. + }
  3701. +
  3702. + if (ik->oldest_version() != ik->old_version() && ik->oldest_version() != obj) {
  3703. + st->print(" (oldest=%d)", ik->oldest_version()->klass_part()->revision_number());
  3704. + }
  3705. +
  3706. + st->cr();
  3707. +
  3708. st->print(BULLET"instance size: %d", ik->size_helper()); st->cr();
  3709. st->print(BULLET"klass size: %d", ik->object_size()); st->cr();
  3710. st->print(BULLET"access: "); ik->access_flags().print_on(st); st->cr();
  3711. @@ -663,7 +685,7 @@
  3712. }
  3713. guarantee(sib->as_klassOop()->is_klass(), "should be klass");
  3714. guarantee(sib->as_klassOop()->is_perm(), "should be in permspace");
  3715. - guarantee(sib->super() == super, "siblings should have same superklass");
  3716. + guarantee(sib->super() == super || super->klass_part()->newest_version() == SystemDictionary::Object_klass(), "siblings should have same superklass");
  3717. sib = sib->next_sibling();
  3718. }
  3719. diff -r 6c6a2299029a src/share/vm/oops/instanceRefKlass.cpp
  3720. --- a/src/share/vm/oops/instanceRefKlass.cpp Sat Dec 14 11:51:15 2013 -0800
  3721. +++ b/src/share/vm/oops/instanceRefKlass.cpp Mon Apr 28 13:12:30 2014 -0700
  3722. @@ -455,10 +455,13 @@
  3723. instanceKlass* ik = instanceKlass::cast(k);
  3724. // Check that we have the right class
  3725. - debug_only(static bool first_time = true);
  3726. - assert(k == SystemDictionary::Reference_klass() && first_time,
  3727. - "Invalid update of maps");
  3728. - debug_only(first_time = false);
  3729. +
  3730. + // (tw) Asserts no longer valid for class redefinition
  3731. + // debug_only(static bool first_time = true);
  3732. +
  3733. + //assert(k == SystemDictionary::Reference_klass() && first_time,
  3734. + // "Invalid update of maps");
  3735. + //debug_only(first_time = false);
  3736. assert(ik->nonstatic_oop_map_count() == 1, "just checking");
  3737. OopMapBlock* map = ik->start_of_nonstatic_oop_maps();
  3738. diff -r 6c6a2299029a src/share/vm/oops/klass.cpp
  3739. --- a/src/share/vm/oops/klass.cpp Sat Dec 14 11:51:15 2013 -0800
  3740. +++ b/src/share/vm/oops/klass.cpp Mon Apr 28 13:12:30 2014 -0700
  3741. @@ -55,6 +55,26 @@
  3742. return false;
  3743. }
  3744. +void Klass::update_supers_to_newest_version() {
  3745. +
  3746. + if (super() != NULL) set_super(super()->klass_part()->newest_version());
  3747. +
  3748. + for (uint i=0; i<primary_super_limit(); i++) {
  3749. + klassOop cur = _primary_supers[i];
  3750. + if (cur != NULL) {
  3751. + _primary_supers[i] = cur->klass_part()->newest_version();
  3752. + }
  3753. + }
  3754. +
  3755. + // Scan the array-of-objects
  3756. + int cnt = secondary_supers()->length();
  3757. + for (int i = 0; i < cnt; i++) {
  3758. + klassOop cur = (klassOop)secondary_supers()->obj_at(i);
  3759. + if (cur != NULL) {
  3760. + secondary_supers()->obj_at_put(i, cur->klass_part()->newest_version());
  3761. + }
  3762. + }
  3763. +}
  3764. bool Klass::search_secondary_supers(klassOop k) const {
  3765. // Put some extra logic here out-of-line, before the search proper.
  3766. // This cuts down the size of the inline method.
  3767. @@ -161,6 +181,16 @@
  3768. kl->set_alloc_size(0);
  3769. TRACE_INIT_ID(kl);
  3770. + kl->set_redefinition_flags(Klass::NoRedefinition);
  3771. + kl->set_redefining(false);
  3772. + kl->set_new_version(NULL);
  3773. + kl->set_old_version(NULL);
  3774. + kl->set_redefinition_index(-1);
  3775. + kl->set_revision_number(-1);
  3776. + kl->set_field_redefinition_policy(DynamicCheck);
  3777. + kl->set_static_field_redefinition_policy(AccessDeletedMembers);
  3778. + kl->set_method_redefinition_policy(AccessDeletedMembers);
  3779. +
  3780. kl->set_prototype_header(markOopDesc::prototype());
  3781. kl->set_biased_lock_revocation_count(0);
  3782. kl->set_last_biased_lock_bulk_revocation_time(0);
  3783. @@ -232,7 +262,7 @@
  3784. set_super(NULL);
  3785. oop_store_without_check((oop*) &_primary_supers[0], (oop) this->as_klassOop());
  3786. assert(super_depth() == 0, "Object must already be initialized properly");
  3787. - } else if (k != super() || k == SystemDictionary::Object_klass()) {
  3788. + } else if (k != super() || k->klass_part()->super() == NULL) {
  3789. assert(super() == NULL || super() == SystemDictionary::Object_klass(),
  3790. "initialize this only once to a non-trivial value");
  3791. set_super(k);
  3792. diff -r 6c6a2299029a src/share/vm/oops/klass.hpp
  3793. --- a/src/share/vm/oops/klass.hpp Sat Dec 14 11:51:15 2013 -0800
  3794. +++ b/src/share/vm/oops/klass.hpp Mon Apr 28 13:12:30 2014 -0700
  3795. @@ -170,6 +170,7 @@
  3796. void* operator new(size_t ignored, KlassHandle& klass, int size, TRAPS);
  3797. };
  3798. +template<class L, class R> class Pair;
  3799. class Klass : public Klass_vtbl {
  3800. friend class VMStructs;
  3801. @@ -222,6 +223,39 @@
  3802. oop* oop_block_beg() const { return adr_secondary_super_cache(); }
  3803. oop* oop_block_end() const { return adr_next_sibling() + 1; }
  3804. + // (tw) Different class redefinition flags of code evolution.
  3805. + enum RedefinitionFlags {
  3806. +
  3807. + // This class is not redefined at all!
  3808. + NoRedefinition,
  3809. +
  3810. + // There are changes to the class meta data.
  3811. + ModifyClass = 1,
  3812. +
  3813. + // The size of the class meta data changes.
  3814. + ModifyClassSize = ModifyClass << 1,
  3815. +
  3816. + // There are change to the instance format.
  3817. + ModifyInstances = ModifyClassSize << 1,
  3818. +
  3819. + // The size of instances changes.
  3820. + ModifyInstanceSize = ModifyInstances << 1,
  3821. +
  3822. + // A super type of this class is removed.
  3823. + RemoveSuperType = ModifyInstanceSize << 1,
  3824. +
  3825. + // This class (or one of its super classes) has an instance transformer method.
  3826. + HasInstanceTransformer = RemoveSuperType << 1,
  3827. + };
  3828. +
  3829. + // (tw) Different policies dealing with deleted fields / methods in old code.
  3830. + enum RedefinitionPolicy {
  3831. + StaticCheck,
  3832. + DynamicCheck,
  3833. + AccessDeletedMembers,
  3834. + AccessOldMembers
  3835. + };
  3836. +
  3837. protected:
  3838. //
  3839. // The oop block. All oop fields must be declared here and only oop fields
  3840. @@ -241,6 +275,10 @@
  3841. oop _java_mirror;
  3842. // Superclass
  3843. klassOop _super;
  3844. + // Old class
  3845. + klassOop _old_version;
  3846. + // New class
  3847. + klassOop _new_version;
  3848. // First subclass (NULL if none); _subklass->next_sibling() is next one
  3849. klassOop _subklass;
  3850. // Sibling link (or NULL); links all subklasses of a klass
  3851. @@ -253,6 +291,19 @@
  3852. jint _modifier_flags; // Processed access flags, for use by Class.getModifiers.
  3853. AccessFlags _access_flags; // Access flags. The class/interface distinction is stored here.
  3854. + // (tw) Non-oop fields for enhanced class redefinition
  3855. + jint _revision_number; // The revision number for redefined classes
  3856. + jint _redefinition_index; // Index of this class when performing the redefinition
  3857. + bool _subtype_changed;
  3858. + int _redefinition_flags; // Level of class redefinition
  3859. + bool _is_copying_backwards; // Does the class need to copy fields backwards? => possibly overwrite itself?
  3860. + int * _update_information; // Update information
  3861. + Pair<int, klassOop> * _type_check_information; // Offsets of object fields that need a type check
  3862. + char _method_redefinition_policy;
  3863. + char _field_redefinition_policy;
  3864. + char _static_field_redefinition_policy;
  3865. + bool _is_redefining;
  3866. +
  3867. #ifndef PRODUCT
  3868. int _verify_count; // to avoid redundant verifies
  3869. #endif
  3870. @@ -301,6 +352,99 @@
  3871. klassOop secondary_super_cache() const { return _secondary_super_cache; }
  3872. void set_secondary_super_cache(klassOop k) { oop_store_without_check((oop*) &_secondary_super_cache, (oop) k); }
  3873. + // BEGIN class redefinition utilities
  3874. +
  3875. + // double links between new and old version of a class
  3876. + klassOop old_version() const { return _old_version; }
  3877. + void set_old_version(klassOop klass) { assert(_old_version == NULL || klass == NULL, "Can only be set once!"); _old_version = klass; }
  3878. + klassOop new_version() const { return _new_version; }
  3879. + void set_new_version(klassOop klass) { assert(_new_version == NULL || klass == NULL, "Can only be set once!"); _new_version = klass; }
  3880. +
  3881. + // A subtype of this class is no longer a subtype
  3882. + bool has_subtype_changed() const { return _subtype_changed; }
  3883. + void set_subtype_changed(bool b) { assert(is_newest_version() || new_version()->klass_part()->is_newest_version(), "must be newest or second newest version");
  3884. + _subtype_changed = b; }
  3885. + // state of being redefined
  3886. + int redefinition_index() const { return _redefinition_index; }
  3887. + void set_redefinition_index(int index) { _redefinition_index = index; }
  3888. + void set_redefining(bool b) { _is_redefining = b; }
  3889. + bool is_redefining() const { return _is_redefining; }
  3890. + int redefinition_flags() const { return _redefinition_flags; }
  3891. + bool check_redefinition_flag(int flags) const { return (_redefinition_flags & flags) != 0; }
  3892. + void set_redefinition_flags(int flags) { _redefinition_flags = flags; }
  3893. + bool is_copying_backwards() const { return _is_copying_backwards; }
  3894. + void set_copying_backwards(bool b) { _is_copying_backwards = b; }
  3895. +
  3896. + // update information
  3897. + int *update_information() const { return _update_information; }
  3898. + void set_update_information(int *info) { _update_information = info; }
  3899. + Pair<int, klassOop> *type_check_information() const { return _type_check_information; }
  3900. + void set_type_check_information(Pair<int, klassOop> *info) { _type_check_information = info; }
  3901. +
  3902. + bool is_same_or_older_version(klassOop klass) const {
  3903. + if (Klass::cast(klass) == this) { return true; }
  3904. + else if (_old_version == NULL) { return false; }
  3905. + else { return _old_version->klass_part()->is_same_or_older_version(klass); }
  3906. + }
  3907. +
  3908. + // Revision number for redefined classes, -1 for originally loaded classes
  3909. + jint revision_number() const {
  3910. + return _revision_number;
  3911. + }
  3912. +
  3913. + bool was_redefined() const {
  3914. + return _revision_number != -1;
  3915. + }
  3916. +
  3917. + void set_revision_number(jint number) {
  3918. + _revision_number = number;
  3919. + }
  3920. +
  3921. + char method_redefinition_policy() {
  3922. + return _method_redefinition_policy;
  3923. + }
  3924. +
  3925. + void set_method_redefinition_policy(char v) {
  3926. + _method_redefinition_policy = v;
  3927. + }
  3928. +
  3929. + char field_redefinition_policy() {
  3930. + return _field_redefinition_policy;
  3931. + }
  3932. +
  3933. + void set_field_redefinition_policy(char v) {
  3934. + _field_redefinition_policy = v;
  3935. + }
  3936. +
  3937. + char static_field_redefinition_policy() {
  3938. + return _static_field_redefinition_policy;
  3939. + }
  3940. +
  3941. + void set_static_field_redefinition_policy(char v) {
  3942. + _static_field_redefinition_policy = v;
  3943. + }
  3944. +
  3945. + klassOop oldest_version() const {
  3946. + if (_old_version == NULL) { return this->as_klassOop(); }
  3947. + else { return _old_version->klass_part()->oldest_version(); };
  3948. + }
  3949. +
  3950. + klassOop newest_version() const {
  3951. + if (_new_version == NULL) { return this->as_klassOop(); }
  3952. + else { return _new_version->klass_part()->newest_version(); };
  3953. + }
  3954. +
  3955. + klassOop active_version() const {
  3956. + if (_new_version == NULL || _new_version->klass_part()->is_redefining()) { return this->as_klassOop(); assert(!this->is_redefining(), "just checking"); }
  3957. + else { return _new_version->klass_part()->active_version(); };
  3958. + }
  3959. +
  3960. + bool is_newest_version() const {
  3961. + return _new_version == NULL;
  3962. + }
  3963. +
  3964. + // END class redefinition utilities
  3965. +
  3966. objArrayOop secondary_supers() const { return _secondary_supers; }
  3967. void set_secondary_supers(objArrayOop k) { oop_store_without_check((oop*) &_secondary_supers, (oop) k); }
  3968. @@ -361,6 +505,8 @@
  3969. void set_next_sibling(klassOop s);
  3970. oop* adr_super() const { return (oop*)&_super; }
  3971. + oop* adr_old_version() const { return (oop*)&_old_version; }
  3972. + oop* adr_new_version() const { return (oop*)&_new_version; }
  3973. oop* adr_primary_supers() const { return (oop*)&_primary_supers[0]; }
  3974. oop* adr_secondary_super_cache() const { return (oop*)&_secondary_super_cache; }
  3975. oop* adr_secondary_supers()const { return (oop*)&_secondary_supers; }
  3976. @@ -490,6 +636,7 @@
  3977. return search_secondary_supers(k);
  3978. }
  3979. }
  3980. + void update_supers_to_newest_version();
  3981. bool search_secondary_supers(klassOop k) const;
  3982. // Find LCA in class hierarchy
  3983. @@ -816,6 +963,8 @@
  3984. inline oop klassOopDesc::java_mirror() const { return klass_part()->java_mirror(); }
  3985. +inline klassOop klassOopDesc::old_version() const { return klass_part()->old_version(); }
  3986. +inline klassOop klassOopDesc::new_version() const { return klass_part()->new_version(); }
  3987. #endif // SHARE_VM_OOPS_KLASS_HPP
  3988. diff -r 6c6a2299029a src/share/vm/oops/klassKlass.cpp
  3989. --- a/src/share/vm/oops/klassKlass.cpp Sat Dec 14 11:51:15 2013 -0800
  3990. +++ b/src/share/vm/oops/klassKlass.cpp Mon Apr 28 13:12:30 2014 -0700
  3991. @@ -68,6 +68,8 @@
  3992. Klass* k = Klass::cast(klassOop(obj));
  3993. // If we are alive it is valid to keep our superclass and subtype caches alive
  3994. MarkSweep::mark_and_push(k->adr_super());
  3995. + MarkSweep::mark_and_push(k->adr_old_version());
  3996. + MarkSweep::mark_and_push(k->adr_new_version());
  3997. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  3998. MarkSweep::mark_and_push(k->adr_primary_supers()+i);
  3999. MarkSweep::mark_and_push(k->adr_secondary_super_cache());
  4000. @@ -87,6 +89,8 @@
  4001. Klass* k = Klass::cast(klassOop(obj));
  4002. // If we are alive it is valid to keep our superclass and subtype caches alive
  4003. PSParallelCompact::mark_and_push(cm, k->adr_super());
  4004. + PSParallelCompact::mark_and_push(cm, k->adr_old_version());
  4005. + PSParallelCompact::mark_and_push(cm, k->adr_new_version());
  4006. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  4007. PSParallelCompact::mark_and_push(cm, k->adr_primary_supers()+i);
  4008. PSParallelCompact::mark_and_push(cm, k->adr_secondary_super_cache());
  4009. @@ -106,6 +110,8 @@
  4010. int size = oop_size(obj);
  4011. Klass* k = Klass::cast(klassOop(obj));
  4012. blk->do_oop(k->adr_super());
  4013. + blk->do_oop(k->adr_old_version());
  4014. + blk->do_oop(k->adr_new_version());
  4015. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  4016. blk->do_oop(k->adr_primary_supers()+i);
  4017. blk->do_oop(k->adr_secondary_super_cache());
  4018. @@ -134,6 +140,10 @@
  4019. oop* adr;
  4020. adr = k->adr_super();
  4021. if (mr.contains(adr)) blk->do_oop(adr);
  4022. + adr = k->adr_old_version();
  4023. + if (mr.contains(adr)) blk->do_oop(adr);
  4024. + adr = k->adr_new_version();
  4025. + if (mr.contains(adr)) blk->do_oop(adr);
  4026. for (juint i = 0; i < Klass::primary_super_limit(); i++) {
  4027. adr = k->adr_primary_supers()+i;
  4028. if (mr.contains(adr)) blk->do_oop(adr);
  4029. @@ -147,6 +157,8 @@
  4030. // The following are "weak links" in the perm gen and are
  4031. // treated specially in a later phase of a perm gen collection.
  4032. assert(oop(k)->is_perm(), "should be in perm");
  4033. + assert(oop(k->adr_old_version())->is_perm(), "should be in perm");
  4034. + assert(oop(k->adr_new_version())->is_perm(), "should be in perm");
  4035. assert(oop(k->adr_subklass())->is_perm(), "should be in perm");
  4036. assert(oop(k->adr_next_sibling())->is_perm(), "should be in perm");
  4037. if (blk->should_remember_klasses()
  4038. @@ -167,6 +179,8 @@
  4039. Klass* k = Klass::cast(klassOop(obj));
  4040. MarkSweep::adjust_pointer(k->adr_super());
  4041. + MarkSweep::adjust_pointer(k->adr_new_version());
  4042. + MarkSweep::adjust_pointer(k->adr_old_version());
  4043. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  4044. MarkSweep::adjust_pointer(k->adr_primary_supers()+i);
  4045. MarkSweep::adjust_pointer(k->adr_secondary_super_cache());
  4046. diff -r 6c6a2299029a src/share/vm/oops/klassOop.hpp
  4047. --- a/src/share/vm/oops/klassOop.hpp Sat Dec 14 11:51:15 2013 -0800
  4048. +++ b/src/share/vm/oops/klassOop.hpp Mon Apr 28 13:12:30 2014 -0700
  4049. @@ -41,8 +41,10 @@
  4050. // returns the Klass part containing dispatching behavior
  4051. Klass* klass_part() const { return (Klass*)((address)this + sizeof(klassOopDesc)); }
  4052. - // Convenience wrapper
  4053. + // Convenience wrappers
  4054. inline oop java_mirror() const;
  4055. + inline klassOop old_version() const;
  4056. + inline klassOop new_version() const;
  4057. private:
  4058. // These have no implementation since klassOop should never be accessed in this fashion
  4059. diff -r 6c6a2299029a src/share/vm/oops/klassVtable.cpp
  4060. --- a/src/share/vm/oops/klassVtable.cpp Sat Dec 14 11:51:15 2013 -0800
  4061. +++ b/src/share/vm/oops/klassVtable.cpp Mon Apr 28 13:12:30 2014 -0700
  4062. @@ -97,7 +97,8 @@
  4063. vtable_length = Universe::base_vtable_size();
  4064. }
  4065. - if (super == NULL && !Universe::is_bootstrapping() &&
  4066. + // (tw) TODO: Check if we can relax the condition on a fixed base vtable size
  4067. + /*if (super == NULL && !Universe::is_bootstrapping() &&
  4068. vtable_length != Universe::base_vtable_size()) {
  4069. // Someone is attempting to redefine java.lang.Object incorrectly. The
  4070. // only way this should happen is from
  4071. @@ -107,9 +108,9 @@
  4072. vtable_length = Universe::base_vtable_size();
  4073. }
  4074. assert(super != NULL || vtable_length == Universe::base_vtable_size(),
  4075. - "bad vtable size for class Object");
  4076. + "bad vtable size for class Object");*/
  4077. assert(vtable_length % vtableEntry::size() == 0, "bad vtable length");
  4078. - assert(vtable_length >= Universe::base_vtable_size(), "vtable too small");
  4079. + //assert(vtable_length >= Universe::base_vtable_size(), "vtable too small");
  4080. }
  4081. int klassVtable::index_of(methodOop m, int len) const {
  4082. @@ -657,20 +658,6 @@
  4083. return true;
  4084. }
  4085. -void klassVtable::dump_vtable() {
  4086. - tty->print_cr("vtable dump --");
  4087. - for (int i = 0; i < length(); i++) {
  4088. - methodOop m = unchecked_method_at(i);
  4089. - if (m != NULL) {
  4090. - tty->print(" (%5d) ", i);
  4091. - m->access_flags().print_on(tty);
  4092. - tty->print(" -- ");
  4093. - m->print_name(tty);
  4094. - tty->cr();
  4095. - }
  4096. - }
  4097. -}
  4098. -
  4099. // CDS/RedefineClasses support - clear vtables so they can be reinitialized
  4100. void klassVtable::clear_vtable() {
  4101. for (int i = 0; i < _length; i++) table()[i].clear();
  4102. @@ -1241,6 +1228,7 @@
  4103. void klassVtable::verify_against(outputStream* st, klassVtable* vt, int index) {
  4104. vtableEntry* vte = &vt->table()[index];
  4105. + if (vte->method() == NULL || table()[index].method() == NULL) return;
  4106. if (vte->method()->name() != table()[index].method()->name() ||
  4107. vte->method()->signature() != table()[index].method()->signature()) {
  4108. fatal("mismatched name/signature of vtable entries");
  4109. @@ -1260,6 +1248,8 @@
  4110. void vtableEntry::verify(klassVtable* vt, outputStream* st) {
  4111. NOT_PRODUCT(FlagSetting fs(IgnoreLockingAssertions, true));
  4112. + // (tw) TODO: Check: Does not hold?
  4113. + if (method() != NULL) {
  4114. assert(method() != NULL, "must have set method");
  4115. method()->verify();
  4116. // we sub_type, because it could be a miranda method
  4117. @@ -1267,7 +1257,13 @@
  4118. #ifndef PRODUCT
  4119. print();
  4120. #endif
  4121. - fatal(err_msg("vtableEntry " PTR_FORMAT ": method is from subclass", this));
  4122. + klassOop first_klass = vt->klass()();
  4123. + klassOop second_klass = method()->method_holder();
  4124. + // (tw) the following fatal does not work for old versions of classes
  4125. + if (first_klass->klass_part()->is_newest_version()) {
  4126. + //fatal1("vtableEntry %#lx: method is from subclass", this);
  4127. + }
  4128. + }
  4129. }
  4130. }
  4131. @@ -1275,7 +1271,7 @@
  4132. void vtableEntry::print() {
  4133. ResourceMark rm;
  4134. - tty->print("vtableEntry %s: ", method()->name()->as_C_string());
  4135. + tty->print("vtableEntry %s: ", (method() == NULL) ? "null" : method()->name()->as_C_string());
  4136. if (Verbose) {
  4137. tty->print("m %#lx ", (address)method());
  4138. }
  4139. @@ -1342,6 +1338,33 @@
  4140. tty->print_cr("%6d bytes total", total);
  4141. }
  4142. +bool klassVtable::check_no_old_entries() {
  4143. + // Check that there really is no entry
  4144. + for (int i = 0; i < length(); i++) {
  4145. + methodOop m = unchecked_method_at(i);
  4146. + if (m != NULL) {
  4147. + if (m->is_old() || !m->method_holder()->klass_part()->is_newest_version()) {
  4148. + return false;
  4149. + }
  4150. + }
  4151. + }
  4152. + return true;
  4153. +}
  4154. +
  4155. +void klassVtable::dump_vtable() {
  4156. + tty->print_cr("vtable dump --");
  4157. + for (int i = 0; i < length(); i++) {
  4158. + methodOop m = unchecked_method_at(i);
  4159. + if (m != NULL) {
  4160. + tty->print(" (%5d) ", i);
  4161. + m->access_flags().print_on(tty);
  4162. + tty->print(" -- ");
  4163. + m->print_name(tty);
  4164. + tty->cr();
  4165. + }
  4166. + }
  4167. +}
  4168. +
  4169. int klassItable::_total_classes; // Total no. of classes with itables
  4170. long klassItable::_total_size; // Total no. of bytes used for itables
  4171. diff -r 6c6a2299029a src/share/vm/oops/klassVtable.hpp
  4172. --- a/src/share/vm/oops/klassVtable.hpp Sat Dec 14 11:51:15 2013 -0800
  4173. +++ b/src/share/vm/oops/klassVtable.hpp Mon Apr 28 13:12:30 2014 -0700
  4174. @@ -100,6 +100,7 @@
  4175. int methods_length, bool * trace_name_printed);
  4176. bool check_no_old_or_obsolete_entries();
  4177. void dump_vtable();
  4178. + bool check_no_old_entries();
  4179. // Garbage collection
  4180. void oop_follow_contents();
  4181. diff -r 6c6a2299029a src/share/vm/oops/methodKlass.cpp
  4182. --- a/src/share/vm/oops/methodKlass.cpp Sat Dec 14 11:51:15 2013 -0800
  4183. +++ b/src/share/vm/oops/methodKlass.cpp Mon Apr 28 13:12:30 2014 -0700
  4184. @@ -93,6 +93,10 @@
  4185. m->set_adapter_entry(NULL);
  4186. m->clear_code(); // from_c/from_i get set to c2i/i2i
  4187. + m->set_forward_method(NULL);
  4188. + m->set_new_version(NULL);
  4189. + m->set_old_version(NULL);
  4190. +
  4191. if (access_flags.is_native()) {
  4192. m->clear_native_function();
  4193. m->set_signature_handler(NULL);
  4194. @@ -122,6 +126,9 @@
  4195. // Performance tweak: We skip iterating over the klass pointer since we
  4196. // know that Universe::methodKlassObj never moves.
  4197. MarkSweep::mark_and_push(m->adr_constMethod());
  4198. + MarkSweep::mark_and_push(m->adr_forward_method());
  4199. + MarkSweep::mark_and_push(m->adr_new_version());
  4200. + MarkSweep::mark_and_push(m->adr_old_version());
  4201. if (m->method_data() != NULL) {
  4202. MarkSweep::mark_and_push(m->adr_method_data());
  4203. }
  4204. @@ -135,6 +142,9 @@
  4205. // Performance tweak: We skip iterating over the klass pointer since we
  4206. // know that Universe::methodKlassObj never moves.
  4207. PSParallelCompact::mark_and_push(cm, m->adr_constMethod());
  4208. + PSParallelCompact::mark_and_push(cm, m->adr_forward_method());
  4209. + PSParallelCompact::mark_and_push(cm, m->adr_new_version());
  4210. + PSParallelCompact::mark_and_push(cm, m->adr_old_version());
  4211. #ifdef COMPILER2
  4212. if (m->method_data() != NULL) {
  4213. PSParallelCompact::mark_and_push(cm, m->adr_method_data());
  4214. @@ -152,6 +162,9 @@
  4215. // Performance tweak: We skip iterating over the klass pointer since we
  4216. // know that Universe::methodKlassObj never moves
  4217. blk->do_oop(m->adr_constMethod());
  4218. + blk->do_oop(m->adr_forward_method());
  4219. + blk->do_oop(m->adr_new_version());
  4220. + blk->do_oop(m->adr_old_version());
  4221. if (m->method_data() != NULL) {
  4222. blk->do_oop(m->adr_method_data());
  4223. }
  4224. @@ -170,6 +183,12 @@
  4225. oop* adr;
  4226. adr = m->adr_constMethod();
  4227. if (mr.contains(adr)) blk->do_oop(adr);
  4228. + adr = m->adr_new_version();
  4229. + if (mr.contains(adr)) blk->do_oop(adr);
  4230. + adr = m->adr_forward_method();
  4231. + if (mr.contains(adr)) blk->do_oop(adr);
  4232. + adr = m->adr_old_version();
  4233. + if (mr.contains(adr)) blk->do_oop(adr);
  4234. if (m->method_data() != NULL) {
  4235. adr = m->adr_method_data();
  4236. if (mr.contains(adr)) blk->do_oop(adr);
  4237. @@ -187,6 +206,9 @@
  4238. // Performance tweak: We skip iterating over the klass pointer since we
  4239. // know that Universe::methodKlassObj never moves.
  4240. MarkSweep::adjust_pointer(m->adr_constMethod());
  4241. + MarkSweep::adjust_pointer(m->adr_forward_method());
  4242. + MarkSweep::adjust_pointer(m->adr_new_version());
  4243. + MarkSweep::adjust_pointer(m->adr_old_version());
  4244. if (m->method_data() != NULL) {
  4245. MarkSweep::adjust_pointer(m->adr_method_data());
  4246. }
  4247. @@ -202,6 +224,9 @@
  4248. assert(obj->is_method(), "should be method");
  4249. methodOop m = methodOop(obj);
  4250. PSParallelCompact::adjust_pointer(m->adr_constMethod());
  4251. + PSParallelCompact::adjust_pointer(m->adr_forward_method());
  4252. + PSParallelCompact::adjust_pointer(m->adr_new_version());
  4253. + PSParallelCompact::adjust_pointer(m->adr_old_version());
  4254. #ifdef COMPILER2
  4255. if (m->method_data() != NULL) {
  4256. PSParallelCompact::adjust_pointer(m->adr_method_data());
  4257. @@ -222,7 +247,18 @@
  4258. methodOop m = methodOop(obj);
  4259. // get the effect of PrintOopAddress, always, for methods:
  4260. st->print_cr(" - this oop: "INTPTR_FORMAT, (intptr_t)m);
  4261. - st->print (" - method holder: "); m->method_holder()->print_value_on(st); st->cr();
  4262. + st->print (" - method holder: "); m->method_holder()->print_value_on(st);
  4263. +
  4264. + if (m->method_holder()->klass_part()->new_version() != NULL) {
  4265. + st->print(" (old)");
  4266. + }
  4267. + st->cr();
  4268. +
  4269. + st->print_cr(" - is obsolete: %d", (int)(m->is_obsolete()));
  4270. + st->print_cr(" - is old: %d", (int)(m->is_old()));
  4271. + st->print_cr(" - new version: "INTPTR_FORMAT" ", (address)(m->new_version()));
  4272. + st->print_cr(" - old version: "INTPTR_FORMAT" ", (address)(m->old_version()));
  4273. + st->print_cr(" - holder revision: %d", m->method_holder()->klass_part()->revision_number());
  4274. st->print (" - constants: "INTPTR_FORMAT" ", (address)m->constants());
  4275. m->constants()->print_value_on(st); st->cr();
  4276. st->print (" - access: 0x%x ", m->access_flags().as_int()); m->access_flags().print_on(st); st->cr();
  4277. diff -r 6c6a2299029a src/share/vm/oops/methodOop.cpp
  4278. --- a/src/share/vm/oops/methodOop.cpp Sat Dec 14 11:51:15 2013 -0800
  4279. +++ b/src/share/vm/oops/methodOop.cpp Mon Apr 28 13:12:30 2014 -0700
  4280. @@ -328,6 +328,70 @@
  4281. }
  4282. +bool methodOopDesc::is_in_code_section(int bci) {
  4283. + // There is no table => every bci is in the code section table.
  4284. + if (!constMethod()->has_code_section_table()) return true;
  4285. +
  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 length = m->code_section_length_at(i);
  4290. + if (bci >= new_index && bci < new_index + length) {
  4291. + // We are in a specified code section.
  4292. + return true;
  4293. + }
  4294. + }
  4295. +
  4296. + return false;
  4297. +}
  4298. +
  4299. +int methodOopDesc::calculate_forward_bci(int bci, methodOop new_method) {
  4300. + int original_bci = -1;
  4301. + if (constMethod()->has_code_section_table()) {
  4302. + assert(is_in_code_section(bci), "can only forward in section");
  4303. + // First calculate back to original bci.
  4304. + constMethodOop m = constMethod();
  4305. + for (int i = 0; i < m->code_section_entries(); ++i) {
  4306. + u2 new_index = m->code_section_new_index_at(i);
  4307. + u2 original_index = m->code_section_original_index_at(i);
  4308. + u2 length = m->code_section_length_at(i);
  4309. + if (bci >= new_index && bci < new_index + length) {
  4310. + // We are in a specified code section.
  4311. + original_bci = bci - new_index + original_index;
  4312. + break;
  4313. + }
  4314. + }
  4315. + assert (original_bci != -1, "must have been in code section");
  4316. + } else {
  4317. + // No code sections specified => we are in an original method.
  4318. + original_bci = bci;
  4319. + }
  4320. +
  4321. + // We know the original bci => match to new method.
  4322. + int new_bci = -1;
  4323. + if (new_method->constMethod()->has_code_section_table()) {
  4324. + // Map to new bci.
  4325. + constMethodOop m = new_method->constMethod();
  4326. + for (int i = 0; i < m->code_section_entries(); ++i) {
  4327. + u2 new_index = m->code_section_new_index_at(i);
  4328. + u2 original_index = m->code_section_original_index_at(i);
  4329. + u2 length = m->code_section_length_at(i);
  4330. + if (original_bci >= original_index && original_bci < original_index + length) {
  4331. + new_bci = original_bci - original_index + new_index;
  4332. + break;
  4333. + }
  4334. + }
  4335. + assert (new_bci != -1, "must have found new code section");
  4336. +
  4337. + } else {
  4338. + // We are in an original method.
  4339. + new_bci = original_bci;
  4340. + }
  4341. +
  4342. + return new_bci;
  4343. +}
  4344. +
  4345. +
  4346. int methodOopDesc::extra_stack_words() {
  4347. // not an inline function, to avoid a header dependency on Interpreter
  4348. return extra_stack_entries() * Interpreter::stackElementSize;
  4349. @@ -1061,6 +1125,9 @@
  4350. // Reset correct method/const method, method size, and parameter info
  4351. newm->set_constMethod(newcm);
  4352. + newm->set_forward_method(newm->forward_method());
  4353. + newm->set_new_version(newm->new_version());
  4354. + newm->set_old_version(newm->old_version());
  4355. newm->constMethod()->set_code_size(new_code_length);
  4356. newm->constMethod()->set_constMethod_size(new_const_method_size);
  4357. newm->set_method_size(new_method_size);
  4358. diff -r 6c6a2299029a src/share/vm/oops/methodOop.hpp
  4359. --- a/src/share/vm/oops/methodOop.hpp Sat Dec 14 11:51:15 2013 -0800
  4360. +++ b/src/share/vm/oops/methodOop.hpp Mon Apr 28 13:12:30 2014 -0700
  4361. @@ -114,6 +114,11 @@
  4362. AccessFlags _access_flags; // Access flags
  4363. int _vtable_index; // vtable index of this method (see VtableIndexFlag)
  4364. // note: can have vtables with >2**16 elements (because of inheritance)
  4365. + // (tw) Newer version of method available?
  4366. + methodOop _forward_method;
  4367. + methodOop _new_version;
  4368. + methodOop _old_version;
  4369. +
  4370. #ifdef CC_INTERP
  4371. int _result_index; // C++ interpreter needs for converting results to/from stack
  4372. #endif
  4373. @@ -175,6 +180,32 @@
  4374. int name_index() const { return constMethod()->name_index(); }
  4375. void set_name_index(int index) { constMethod()->set_name_index(index); }
  4376. + methodOop forward_method() const {return _forward_method; }
  4377. + void set_forward_method(methodOop m) { _forward_method = m; }
  4378. + bool has_forward_method() const { return forward_method() != NULL; }
  4379. + methodOop new_version() const {return _new_version; }
  4380. + void set_new_version(methodOop m) { _new_version = m; }
  4381. + methodOop newest_version() { if(_new_version == NULL) return this; else return new_version()->newest_version(); }
  4382. +
  4383. + methodOop old_version() const {return _old_version; };
  4384. + void set_old_version(methodOop m) {
  4385. + if (m == NULL) {
  4386. + _old_version = NULL;
  4387. + return;
  4388. + }
  4389. +
  4390. + assert(_old_version == NULL, "may only be set once");
  4391. + assert(this->code_size() == m->code_size(), "must have same code length");
  4392. + _old_version = m;
  4393. + }
  4394. +
  4395. + methodOop oldest_version() const {
  4396. + if(_old_version == NULL) return (methodOop)this;
  4397. + else {
  4398. + return old_version()->oldest_version();
  4399. + }
  4400. + }
  4401. +
  4402. // signature
  4403. Symbol* signature() const { return constants()->symbol_at(signature_index()); }
  4404. int signature_index() const { return constMethod()->signature_index(); }
  4405. @@ -670,6 +701,10 @@
  4406. // Inline cache support
  4407. void cleanup_inline_caches();
  4408. + // (tw) Method forwarding support.
  4409. + bool is_in_code_section(int bci);
  4410. + int calculate_forward_bci(int bci, methodOop new_method);
  4411. +
  4412. // Find if klass for method is loaded
  4413. bool is_klass_loaded_by_klass_index(int klass_index) const;
  4414. bool is_klass_loaded(int refinfo_index, bool must_be_resolved = false) const;
  4415. @@ -734,6 +769,9 @@
  4416. // Garbage collection support
  4417. oop* adr_constMethod() const { return (oop*)&_constMethod; }
  4418. + oop* adr_forward_method() const { return (oop*)&_forward_method; }
  4419. + oop* adr_new_version() const { return (oop*)&_new_version; }
  4420. + oop* adr_old_version() const { return (oop*)&_old_version; }
  4421. oop* adr_method_data() const { return (oop*)&_method_data; }
  4422. };
  4423. diff -r 6c6a2299029a src/share/vm/oops/oop.hpp
  4424. --- a/src/share/vm/oops/oop.hpp Sat Dec 14 11:51:15 2013 -0800
  4425. +++ b/src/share/vm/oops/oop.hpp Mon Apr 28 13:12:30 2014 -0700
  4426. @@ -95,6 +95,7 @@
  4427. narrowOop* compressed_klass_addr();
  4428. void set_klass(klassOop k);
  4429. + void set_klass_no_check(klassOop k);
  4430. // For klass field compression
  4431. int klass_gap() const;
  4432. @@ -135,6 +136,7 @@
  4433. bool is_array() const;
  4434. bool is_objArray() const;
  4435. bool is_klass() const;
  4436. + bool is_instanceKlass() const;
  4437. bool is_thread() const;
  4438. bool is_method() const;
  4439. bool is_constMethod() const;
  4440. diff -r 6c6a2299029a src/share/vm/oops/oop.inline.hpp
  4441. --- a/src/share/vm/oops/oop.inline.hpp Sat Dec 14 11:51:15 2013 -0800
  4442. +++ b/src/share/vm/oops/oop.inline.hpp Mon Apr 28 13:12:30 2014 -0700
  4443. @@ -123,6 +123,14 @@
  4444. }
  4445. }
  4446. +inline void oopDesc::set_klass_no_check(klassOop k) {
  4447. + if (UseCompressedOops) {
  4448. + oop_store_without_check(compressed_klass_addr(), (oop)k);
  4449. + } else {
  4450. + oop_store_without_check(klass_addr(), (oop) k);
  4451. + }
  4452. +}
  4453. +
  4454. inline int oopDesc::klass_gap() const {
  4455. return *(int*)(((intptr_t)this) + klass_gap_offset_in_bytes());
  4456. }
  4457. @@ -156,6 +164,7 @@
  4458. inline bool oopDesc::is_typeArray() const { return blueprint()->oop_is_typeArray(); }
  4459. inline bool oopDesc::is_javaArray() const { return blueprint()->oop_is_javaArray(); }
  4460. inline bool oopDesc::is_klass() const { return blueprint()->oop_is_klass(); }
  4461. +inline bool oopDesc::is_instanceKlass() const { return blueprint()->oop_is_instanceKlass(); }
  4462. inline bool oopDesc::is_thread() const { return blueprint()->oop_is_thread(); }
  4463. inline bool oopDesc::is_method() const { return blueprint()->oop_is_method(); }
  4464. inline bool oopDesc::is_constMethod() const { return blueprint()->oop_is_constMethod(); }
  4465. diff -r 6c6a2299029a src/share/vm/prims/jni.cpp
  4466. --- a/src/share/vm/prims/jni.cpp Sat Dec 14 11:51:15 2013 -0800
  4467. +++ b/src/share/vm/prims/jni.cpp Mon Apr 28 13:12:30 2014 -0700
  4468. @@ -406,7 +406,7 @@
  4469. }
  4470. }
  4471. klassOop k = SystemDictionary::resolve_from_stream(class_name, class_loader,
  4472. - Handle(), &st, true,
  4473. + Handle(), &st, true, KlassHandle(),
  4474. CHECK_NULL);
  4475. if (TraceClassResolution && k != NULL) {
  4476. diff -r 6c6a2299029a src/share/vm/prims/jvm.cpp
  4477. --- a/src/share/vm/prims/jvm.cpp Sat Dec 14 11:51:15 2013 -0800
  4478. +++ b/src/share/vm/prims/jvm.cpp Mon Apr 28 13:12:30 2014 -0700
  4479. @@ -872,7 +872,7 @@
  4480. Handle protection_domain (THREAD, JNIHandles::resolve(pd));
  4481. klassOop k = SystemDictionary::resolve_from_stream(class_name, class_loader,
  4482. protection_domain, &st,
  4483. - verify != 0,
  4484. + verify != 0, KlassHandle(),
  4485. CHECK_NULL);
  4486. if (TraceClassResolution && k != NULL) {
  4487. diff -r 6c6a2299029a src/share/vm/prims/jvmtiEnv.cpp
  4488. --- a/src/share/vm/prims/jvmtiEnv.cpp Sat Dec 14 11:51:15 2013 -0800
  4489. +++ b/src/share/vm/prims/jvmtiEnv.cpp Mon Apr 28 13:12:30 2014 -0700
  4490. @@ -290,7 +290,10 @@
  4491. class_definitions[index].klass = jcls;
  4492. }
  4493. VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_retransform);
  4494. - VMThread::execute(&op);
  4495. + {
  4496. + MutexLocker sd_mutex(RedefineClasses_lock);
  4497. + VMThread::execute(&op);
  4498. + }
  4499. return (op.check_error());
  4500. } /* end RetransformClasses */
  4501. @@ -299,9 +302,12 @@
  4502. // class_definitions - pre-checked for NULL
  4503. jvmtiError
  4504. JvmtiEnv::RedefineClasses(jint class_count, const jvmtiClassDefinition* class_definitions) {
  4505. -//TODO: add locking
  4506. +
  4507. VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_redefine);
  4508. - VMThread::execute(&op);
  4509. + {
  4510. + MutexLocker sd_mutex(RedefineClasses_lock);
  4511. + VMThread::execute(&op);
  4512. + }
  4513. return (op.check_error());
  4514. } /* end RedefineClasses */
  4515. diff -r 6c6a2299029a src/share/vm/prims/jvmtiExport.cpp
  4516. --- a/src/share/vm/prims/jvmtiExport.cpp Sat Dec 14 11:51:15 2013 -0800
  4517. +++ b/src/share/vm/prims/jvmtiExport.cpp Mon Apr 28 13:12:30 2014 -0700
  4518. @@ -2296,7 +2296,7 @@
  4519. // iterate over any code blob descriptors collected and post a
  4520. // DYNAMIC_CODE_GENERATED event to the profiler.
  4521. JvmtiDynamicCodeEventCollector::~JvmtiDynamicCodeEventCollector() {
  4522. - assert(!JavaThread::current()->owns_locks(), "all locks must be released to post deferred events");
  4523. + assert(!JavaThread::current()->owns_locks_but_redefine_classes_lock(), "all locks must be released to post deferred events");
  4524. // iterate over any code blob descriptors that we collected
  4525. if (_code_blobs != NULL) {
  4526. for (int i=0; i<_code_blobs->length(); i++) {
  4527. diff -r 6c6a2299029a src/share/vm/prims/jvmtiImpl.cpp
  4528. --- a/src/share/vm/prims/jvmtiImpl.cpp Sat Dec 14 11:51:15 2013 -0800
  4529. +++ b/src/share/vm/prims/jvmtiImpl.cpp Mon Apr 28 13:12:30 2014 -0700
  4530. @@ -286,6 +286,8 @@
  4531. void JvmtiBreakpoint::each_method_version_do(method_action meth_act) {
  4532. ((methodOopDesc*)_method->*meth_act)(_bci);
  4533. + // DCEVM: TODO: Check how we can implement this differently here!
  4534. +
  4535. // add/remove breakpoint to/from versions of the method that
  4536. // are EMCP. Directly or transitively obsolete methods are
  4537. // not saved in the PreviousVersionInfo.
  4538. diff -r 6c6a2299029a src/share/vm/prims/jvmtiRedefineClasses.cpp
  4539. --- a/src/share/vm/prims/jvmtiRedefineClasses.cpp Sat Dec 14 11:51:15 2013 -0800
  4540. +++ b/src/share/vm/prims/jvmtiRedefineClasses.cpp Mon Apr 28 13:12:30 2014 -0700
  4541. @@ -1,5 +1,5 @@
  4542. /*
  4543. - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
  4544. + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  4545. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4546. *
  4547. * This code is free software; you can redistribute it and/or modify it
  4548. @@ -30,498 +30,637 @@
  4549. #include "interpreter/rewriter.hpp"
  4550. #include "memory/gcLocker.hpp"
  4551. #include "memory/universe.inline.hpp"
  4552. +#include "memory/cardTableRS.hpp"
  4553. +#include "oops/klassVtable.hpp"
  4554. #include "oops/fieldStreams.hpp"
  4555. -#include "oops/klassVtable.hpp"
  4556. #include "prims/jvmtiImpl.hpp"
  4557. #include "prims/jvmtiRedefineClasses.hpp"
  4558. +#include "prims/jvmtiClassFileReconstituter.hpp"
  4559. #include "prims/methodComparator.hpp"
  4560. #include "runtime/deoptimization.hpp"
  4561. #include "runtime/relocator.hpp"
  4562. #include "utilities/bitMap.inline.hpp"
  4563. +#include "compiler/compileBroker.hpp"
  4564. objArrayOop VM_RedefineClasses::_old_methods = NULL;
  4565. objArrayOop VM_RedefineClasses::_new_methods = NULL;
  4566. -methodOop* VM_RedefineClasses::_matching_old_methods = NULL;
  4567. -methodOop* VM_RedefineClasses::_matching_new_methods = NULL;
  4568. -methodOop* VM_RedefineClasses::_deleted_methods = NULL;
  4569. -methodOop* VM_RedefineClasses::_added_methods = NULL;
  4570. +int* VM_RedefineClasses::_matching_old_methods = NULL;
  4571. +int* VM_RedefineClasses::_matching_new_methods = NULL;
  4572. +int* VM_RedefineClasses::_deleted_methods = NULL;
  4573. +int* VM_RedefineClasses::_added_methods = NULL;
  4574. int VM_RedefineClasses::_matching_methods_length = 0;
  4575. int VM_RedefineClasses::_deleted_methods_length = 0;
  4576. int VM_RedefineClasses::_added_methods_length = 0;
  4577. klassOop VM_RedefineClasses::_the_class_oop = NULL;
  4578. -
  4579. -VM_RedefineClasses::VM_RedefineClasses(jint class_count,
  4580. - const jvmtiClassDefinition *class_defs,
  4581. - JvmtiClassLoadKind class_load_kind) {
  4582. +// Holds the revision number of the current class redefinition
  4583. +int VM_RedefineClasses::_revision_number = -1;
  4584. +
  4585. +VM_RedefineClasses::VM_RedefineClasses(jint class_count, const jvmtiClassDefinition *class_defs, JvmtiClassLoadKind class_load_kind)
  4586. + : VM_GC_Operation(Universe::heap()->total_full_collections(), GCCause::_jvmti_force_gc) {
  4587. + RC_TIMER_START(_timer_total);
  4588. _class_count = class_count;
  4589. _class_defs = class_defs;
  4590. _class_load_kind = class_load_kind;
  4591. - _res = JVMTI_ERROR_NONE;
  4592. + _updated_oops = NULL;
  4593. + _result = JVMTI_ERROR_NONE;
  4594. }
  4595. +VM_RedefineClasses::~VM_RedefineClasses() {
  4596. + {
  4597. + MonitorLockerEx ml(RedefinitionSync_lock);
  4598. + Threads::set_wait_at_instrumentation_entry(false);
  4599. + ml.notify_all();
  4600. + }
  4601. +
  4602. + unlock_threads();
  4603. + RC_TIMER_STOP(_timer_total);
  4604. +
  4605. + if (TimeRedefineClasses) {
  4606. + tty->print_cr("Timing Prologue: %d", _timer_prologue.milliseconds());
  4607. + tty->print_cr("Timing Class Loading: %d", _timer_class_loading.milliseconds());
  4608. + tty->print_cr("Timing Waiting for Lock: %d", _timer_wait_for_locks.milliseconds());
  4609. + tty->print_cr("Timing Class Linking: %d", _timer_class_linking.milliseconds());
  4610. + tty->print_cr("Timing Check Type: %d", _timer_check_type.milliseconds());
  4611. + tty->print_cr("Timing Prepare Redefinition: %d", _timer_prepare_redefinition.milliseconds());
  4612. + tty->print_cr("Timing Redefinition GC: %d", _timer_redefinition.milliseconds());
  4613. + tty->print_cr("Timing Epilogue: %d", _timer_vm_op_epilogue.milliseconds());
  4614. + tty->print_cr("------------------------------------------------------------------");
  4615. + tty->print_cr("Total Time: %d", _timer_total.milliseconds());
  4616. + }
  4617. +}
  4618. +
  4619. +// Searches for all affected classes and performs a sorting such that a supertype is always before a subtype.
  4620. +jvmtiError VM_RedefineClasses::find_sorted_affected_classes(GrowableArray<instanceKlassHandle> *all_affected_klasses) {
  4621. +
  4622. + // Create array with all classes for which the redefine command was given
  4623. + GrowableArray<instanceKlassHandle> klasses_to_redefine;
  4624. + for (int i=0; i<_class_count; i++) {
  4625. + oop mirror = JNIHandles::resolve_non_null(_class_defs[i].klass);
  4626. + instanceKlassHandle klass_handle(Thread::current(), java_lang_Class::as_klassOop(mirror));
  4627. + klasses_to_redefine.append(klass_handle);
  4628. + assert(klass_handle->new_version() == NULL, "Must be new class");
  4629. + }
  4630. +
  4631. + // Find classes not directly redefined, but affected by a redefinition (because one of its supertypes is redefined)
  4632. + GrowableArray<instanceKlassHandle> affected_classes;
  4633. + FindAffectedKlassesClosure closure(&klasses_to_redefine, &affected_classes);
  4634. +
  4635. + // Trace affected classes
  4636. + if (RC_TRACE_ENABLED(0x00000001)) {
  4637. + RC_TRACE(0x00000001, ("Klasses affected: %d",
  4638. + affected_classes.length()));
  4639. + for (int i=0; i<affected_classes.length(); i++) {
  4640. + RC_TRACE(0x00000001, ("%s",
  4641. + affected_classes.at(i)->name()->as_C_string()));
  4642. + }
  4643. + }
  4644. +
  4645. + // Add the array of affected classes and the array of redefined classes to get a list of all classes that need a redefinition
  4646. + all_affected_klasses->appendAll(&klasses_to_redefine);
  4647. + all_affected_klasses->appendAll(&affected_classes);
  4648. +
  4649. + // Sort the affected klasses such that a supertype is always on a smaller array index than its subtype.
  4650. + jvmtiError result = do_topological_class_sorting(_class_defs, _class_count, &affected_classes, all_affected_klasses, Thread::current());
  4651. + if (RC_TRACE_ENABLED(0x00000001)) {
  4652. + RC_TRACE(0x00000001, ("Redefine order: "));
  4653. + for (int i=0; i<all_affected_klasses->length(); i++) {
  4654. + RC_TRACE(0x00000001, ("%s",
  4655. + all_affected_klasses->at(i)->name()->as_C_string()));
  4656. + }
  4657. + }
  4658. +
  4659. + return result;
  4660. +}
  4661. +
  4662. +// Searches for the class bytes of the given class and returns them as a byte array.
  4663. +jvmtiError VM_RedefineClasses::find_class_bytes(instanceKlassHandle the_class, const unsigned char **class_bytes, jint *class_byte_count, jboolean *not_changed) {
  4664. +
  4665. + *not_changed = false;
  4666. +
  4667. + // Search for the index in the redefinition array that corresponds to the current class
  4668. + int j;
  4669. + for (j=0; j<_class_count; j++) {
  4670. + oop mirror = JNIHandles::resolve_non_null(_class_defs[j].klass);
  4671. + klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
  4672. + if (the_class_oop == the_class()) {
  4673. + break;
  4674. + }
  4675. + }
  4676. +
  4677. + if (j == _class_count) {
  4678. +
  4679. + *not_changed = true;
  4680. +
  4681. + // Redefine with same bytecodes. This is a class that is only indirectly affected by redefinition,
  4682. + // so the user did not specify a different bytecode for that class.
  4683. +
  4684. + if (the_class->get_cached_class_file_bytes() == NULL) {
  4685. + // not cached, we need to reconstitute the class file from VM representation
  4686. + constantPoolHandle constants(Thread::current(), the_class->constants());
  4687. + ObjectLocker ol(constants, Thread::current()); // lock constant pool while we query it
  4688. +
  4689. + JvmtiClassFileReconstituter reconstituter(the_class);
  4690. + if (reconstituter.get_error() != JVMTI_ERROR_NONE) {
  4691. + return reconstituter.get_error();
  4692. + }
  4693. +
  4694. + *class_byte_count = (jint)reconstituter.class_file_size();
  4695. + *class_bytes = (unsigned char*)reconstituter.class_file_bytes();
  4696. +
  4697. + } else {
  4698. +
  4699. + // it is cached, get it from the cache
  4700. + *class_byte_count = the_class->get_cached_class_file_len();
  4701. + *class_bytes = the_class->get_cached_class_file_bytes();
  4702. + }
  4703. +
  4704. + } else {
  4705. +
  4706. + // Redefine with bytecodes at index j
  4707. + *class_bytes = _class_defs[j].class_bytes;
  4708. + *class_byte_count = _class_defs[j].class_byte_count;
  4709. + }
  4710. +
  4711. + return JVMTI_ERROR_NONE;
  4712. +}
  4713. +
  4714. +// Prologue of the VM operation, called on the Java thread in parallel to normal program execution
  4715. bool VM_RedefineClasses::doit_prologue() {
  4716. - if (_class_count == 0) {
  4717. - _res = JVMTI_ERROR_NONE;
  4718. +
  4719. + _revision_number++;
  4720. + RC_TRACE(0x00000001, ("Redefinition with revision number %d started!", _revision_number));
  4721. +
  4722. + assert(Thread::current()->is_Java_thread(), "must be Java thread");
  4723. + RC_TIMER_START(_timer_prologue);
  4724. +
  4725. + if (!check_arguments()) {
  4726. + RC_TIMER_STOP(_timer_prologue);
  4727. return false;
  4728. }
  4729. - if (_class_defs == NULL) {
  4730. - _res = JVMTI_ERROR_NULL_POINTER;
  4731. +
  4732. + // We first load new class versions in the prologue, because somewhere down the
  4733. + // call chain it is required that the current thread is a Java thread.
  4734. + _new_classes = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<instanceKlassHandle>(5, true);
  4735. + _result = load_new_class_versions(Thread::current());
  4736. +
  4737. + RC_TRACE(0x00000001, ("Loaded new class versions!"));
  4738. + if (_result != JVMTI_ERROR_NONE) {
  4739. + RC_TRACE(0x00000001, ("error occured: %d!", _result));
  4740. + delete _new_classes;
  4741. + _new_classes = NULL;
  4742. + RC_TIMER_STOP(_timer_prologue);
  4743. return false;
  4744. }
  4745. +
  4746. + RC_TRACE(0x00000001, ("nearly finished"));
  4747. + VM_GC_Operation::doit_prologue();
  4748. + RC_TIMER_STOP(_timer_prologue);
  4749. + RC_TRACE(0x00000001, ("doit_prologue finished!"));
  4750. + return true;
  4751. +}
  4752. +
  4753. +// Checks basic properties of the arguments of the redefinition command.
  4754. +bool VM_RedefineClasses::check_arguments() {
  4755. +
  4756. + if (_class_count == 0) RC_ABORT(JVMTI_ERROR_NONE);
  4757. + if (_class_defs == NULL) RC_ABORT(JVMTI_ERROR_NULL_POINTER);
  4758. for (int i = 0; i < _class_count; i++) {
  4759. - if (_class_defs[i].klass == NULL) {
  4760. - _res = JVMTI_ERROR_INVALID_CLASS;
  4761. - return false;
  4762. + if (_class_defs[i].klass == NULL) RC_ABORT(JVMTI_ERROR_INVALID_CLASS);
  4763. + if (_class_defs[i].class_byte_count == 0) RC_ABORT(JVMTI_ERROR_INVALID_CLASS_FORMAT);
  4764. + if (_class_defs[i].class_bytes == NULL) RC_ABORT(JVMTI_ERROR_NULL_POINTER);
  4765. + }
  4766. +
  4767. + return true;
  4768. +}
  4769. +
  4770. +jvmtiError VM_RedefineClasses::check_exception() const {
  4771. + Thread* THREAD = Thread::current();
  4772. + if (HAS_PENDING_EXCEPTION) {
  4773. +
  4774. + Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  4775. + RC_TRACE(0x00000001, ("parse_stream exception: '%s'",
  4776. + ex_name->as_C_string()));
  4777. + if (TraceRedefineClasses >= 1) {
  4778. + java_lang_Throwable::print(PENDING_EXCEPTION, tty);
  4779. + tty->print_cr("");
  4780. }
  4781. - if (_class_defs[i].class_byte_count == 0) {
  4782. - _res = JVMTI_ERROR_INVALID_CLASS_FORMAT;
  4783. - return false;
  4784. - }
  4785. - if (_class_defs[i].class_bytes == NULL) {
  4786. - _res = JVMTI_ERROR_NULL_POINTER;
  4787. - return false;
  4788. + CLEAR_PENDING_EXCEPTION;
  4789. +
  4790. + if (ex_name == vmSymbols::java_lang_UnsupportedClassVersionError()) {
  4791. + return JVMTI_ERROR_UNSUPPORTED_VERSION;
  4792. + } else if (ex_name == vmSymbols::java_lang_ClassFormatError()) {
  4793. + return JVMTI_ERROR_INVALID_CLASS_FORMAT;
  4794. + } else if (ex_name == vmSymbols::java_lang_ClassCircularityError()) {
  4795. + return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  4796. + } else if (ex_name == vmSymbols::java_lang_NoClassDefFoundError()) {
  4797. + // The message will be "XXX (wrong name: YYY)"
  4798. + return JVMTI_ERROR_NAMES_DONT_MATCH;
  4799. + } else if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  4800. + return JVMTI_ERROR_OUT_OF_MEMORY;
  4801. + } else {
  4802. + // Just in case more exceptions can be thrown..
  4803. + return JVMTI_ERROR_FAILS_VERIFICATION;
  4804. }
  4805. }
  4806. - // Start timer after all the sanity checks; not quite accurate, but
  4807. - // better than adding a bunch of stop() calls.
  4808. - RC_TIMER_START(_timer_vm_op_prologue);
  4809. -
  4810. - // We first load new class versions in the prologue, because somewhere down the
  4811. - // call chain it is required that the current thread is a Java thread.
  4812. - _res = load_new_class_versions(Thread::current());
  4813. - if (_res != JVMTI_ERROR_NONE) {
  4814. - // Free os::malloc allocated memory in load_new_class_version.
  4815. - os::free(_scratch_classes);
  4816. - RC_TIMER_STOP(_timer_vm_op_prologue);
  4817. - return false;
  4818. + return JVMTI_ERROR_NONE;
  4819. +}
  4820. +
  4821. +// Loads all new class versions and stores the instanceKlass handles in an array.
  4822. +jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) {
  4823. +
  4824. + ResourceMark rm(THREAD);
  4825. +
  4826. + RC_TRACE(0x00000001, ("==================================================================="));
  4827. + RC_TRACE(0x00000001, ("load new class versions (%d)",
  4828. + _class_count));
  4829. +
  4830. + // Retrieve an array of all classes that need to be redefined
  4831. + GrowableArray<instanceKlassHandle> all_affected_klasses;
  4832. + jvmtiError err = find_sorted_affected_classes(&all_affected_klasses);
  4833. + if (err != JVMTI_ERROR_NONE) {
  4834. + RC_TRACE(0x00000001, ("Error finding sorted affected classes: %d",
  4835. + (int)err));
  4836. + return err;
  4837. }
  4838. - RC_TIMER_STOP(_timer_vm_op_prologue);
  4839. - return true;
  4840. -}
  4841. -
  4842. -void VM_RedefineClasses::doit() {
  4843. - Thread *thread = Thread::current();
  4844. -
  4845. - if (UseSharedSpaces) {
  4846. - // Sharing is enabled so we remap the shared readonly space to
  4847. - // shared readwrite, private just in case we need to redefine
  4848. - // a shared class. We do the remap during the doit() phase of
  4849. - // the safepoint to be safer.
  4850. - if (!CompactingPermGenGen::remap_shared_readonly_as_readwrite()) {
  4851. - RC_TRACE_WITH_THREAD(0x00000001, thread,
  4852. - ("failed to remap shared readonly space to readwrite, private"));
  4853. - _res = JVMTI_ERROR_INTERNAL;
  4854. - return;
  4855. +
  4856. + JvmtiThreadState *state = JvmtiThreadState::state_for(JavaThread::current());
  4857. +
  4858. + _max_redefinition_flags = Klass::NoRedefinition;
  4859. + jvmtiError result = JVMTI_ERROR_NONE;
  4860. +
  4861. + for (int i=0; i<all_affected_klasses.length(); i++) {
  4862. + RC_TRACE(0x00000002, ("Processing affected class %d of %d",
  4863. + i+1, all_affected_klasses.length()));
  4864. +
  4865. + instanceKlassHandle the_class = all_affected_klasses.at(i);
  4866. + RC_TRACE(0x00000002, ("name=%s",
  4867. + the_class->name()->as_C_string()));
  4868. +
  4869. + the_class->link_class(THREAD);
  4870. + result = check_exception();
  4871. + if (result != JVMTI_ERROR_NONE) break;
  4872. +
  4873. + // Find new class bytes
  4874. + const unsigned char* class_bytes;
  4875. + jint class_byte_count;
  4876. + jvmtiError error;
  4877. + jboolean not_changed;
  4878. + if ((error = find_class_bytes(the_class, &class_bytes, &class_byte_count, &not_changed)) != JVMTI_ERROR_NONE) {
  4879. + RC_TRACE(0x00000001, ("Error finding class bytes: %d",
  4880. + (int)error));
  4881. + result = error;
  4882. + break;
  4883. + }
  4884. + assert(class_bytes != NULL && class_byte_count != 0, "Class bytes defined at this point!");
  4885. +
  4886. +
  4887. + // Set redefined class handle in JvmtiThreadState class.
  4888. + // This redefined class is sent to agent event handler for class file
  4889. + // load hook event.
  4890. + state->set_class_being_redefined(&the_class, _class_load_kind);
  4891. +
  4892. + RC_TRACE(0x00000002, ("Before resolving from stream"));
  4893. +
  4894. + RC_TIMER_STOP(_timer_prologue);
  4895. + RC_TIMER_START(_timer_class_loading);
  4896. +
  4897. +
  4898. + // Parse the stream.
  4899. + Handle the_class_loader(THREAD, the_class->class_loader());
  4900. + Handle protection_domain(THREAD, the_class->protection_domain());
  4901. + Symbol* the_class_sym = the_class->name();
  4902. + ClassFileStream st((u1*) class_bytes, class_byte_count, (char *)"__VM_RedefineClasses__");
  4903. + instanceKlassHandle new_class(THREAD, SystemDictionary::resolve_from_stream(the_class_sym,
  4904. + the_class_loader,
  4905. + protection_domain,
  4906. + &st,
  4907. + true,
  4908. + the_class,
  4909. + THREAD));
  4910. +
  4911. + not_changed = false;
  4912. +
  4913. + RC_TIMER_STOP(_timer_class_loading);
  4914. + RC_TIMER_START(_timer_prologue);
  4915. +
  4916. + RC_TRACE(0x00000002, ("After resolving class from stream!"));
  4917. + // Clear class_being_redefined just to be sure.
  4918. + state->clear_class_being_redefined();
  4919. +
  4920. + result = check_exception();
  4921. + if (result != JVMTI_ERROR_NONE) break;
  4922. +
  4923. +#ifdef ASSERT
  4924. +
  4925. + assert(new_class() != NULL, "Class could not be loaded!");
  4926. + assert(new_class() != the_class(), "must be different");
  4927. + assert(new_class->new_version() == NULL && new_class->old_version() != NULL, "");
  4928. +
  4929. +
  4930. + objArrayOop k_interfaces = new_class->local_interfaces();
  4931. + for (int j=0; j<k_interfaces->length(); j++) {
  4932. + assert(((klassOop)k_interfaces->obj_at(j))->klass_part()->is_newest_version(), "just checking");
  4933. + }
  4934. +
  4935. + if (!THREAD->is_Compiler_thread()) {
  4936. +
  4937. + RC_TRACE(0x00000002, ("name=%s loader="INTPTR_FORMAT" protection_domain="INTPTR_FORMAT" ",
  4938. + the_class->name()->as_C_string(),
  4939. + (address)(the_class->class_loader()),
  4940. + (address)(the_class->protection_domain())));
  4941. + // If we are on the compiler thread, we must not try to resolve a class.
  4942. + klassOop systemLookup = SystemDictionary::resolve_or_null(the_class->name(), the_class->class_loader(), the_class->protection_domain(), THREAD);
  4943. +
  4944. + if (systemLookup != NULL) {
  4945. + assert(systemLookup == new_class->old_version(), "Old class must be in system dictionary!");
  4946. +
  4947. +
  4948. + Klass *subklass = new_class()->klass_part()->subklass();
  4949. + while (subklass != NULL) {
  4950. + assert(subklass->new_version() == NULL, "Most recent version of class!");
  4951. + subklass = subklass->next_sibling();
  4952. + }
  4953. + } else {
  4954. + // This can happen for reflection generated classes.. ?
  4955. + CLEAR_PENDING_EXCEPTION;
  4956. + }
  4957. + }
  4958. +
  4959. +#endif
  4960. +
  4961. + if (RC_TRACE_ENABLED(0x00000001)) {
  4962. + if (new_class->layout_helper() != the_class->layout_helper()) {
  4963. + RC_TRACE(0x00000001, ("Instance size change for class %s: new=%d old=%d",
  4964. + new_class->name()->as_C_string(),
  4965. + new_class->layout_helper(),
  4966. + the_class->layout_helper()));
  4967. + }
  4968. + }
  4969. +
  4970. + // Set the new version of the class
  4971. + new_class->set_revision_number(_revision_number);
  4972. + new_class->set_redefinition_index(i);
  4973. + the_class->set_new_version(new_class());
  4974. + _new_classes->append(new_class);
  4975. +
  4976. + assert(new_class->new_version() == NULL, "");
  4977. +
  4978. + int redefinition_flags = Klass::NoRedefinition;
  4979. +
  4980. + if (not_changed) {
  4981. + redefinition_flags = Klass::NoRedefinition;
  4982. + } else if (AllowAdvancedClassRedefinition) {
  4983. + redefinition_flags = calculate_redefinition_flags(new_class);
  4984. + } else {
  4985. + jvmtiError allowed = check_redefinition_allowed(new_class);
  4986. + if (allowed != JVMTI_ERROR_NONE) {
  4987. + RC_TRACE(0x00000001, ("Error redefinition not allowed!"));
  4988. + result = allowed;
  4989. + break;
  4990. + }
  4991. + redefinition_flags = Klass::ModifyClass;
  4992. + }
  4993. +
  4994. + if (new_class->super() != NULL) {
  4995. + redefinition_flags = redefinition_flags | new_class->super()->klass_part()->redefinition_flags();
  4996. + }
  4997. +
  4998. + for (int j=0; j<new_class->local_interfaces()->length(); j++) {
  4999. + redefinition_flags = redefinition_flags | ((klassOop)new_class->local_interfaces()->obj_at(j))->klass_part()->redefinition_flags();
  5000. + }
  5001. +
  5002. + new_class->set_redefinition_flags(redefinition_flags);
  5003. +
  5004. + _max_redefinition_flags = _max_redefinition_flags | redefinition_flags;
  5005. +
  5006. + if ((redefinition_flags & Klass::ModifyInstances) != 0) {
  5007. + // TODO: Check if watch access flags of static fields are updated correctly.
  5008. + calculate_instance_update_information(_new_classes->at(i)());
  5009. + } else {
  5010. + assert(new_class->layout_helper() >> 1 == new_class->old_version()->klass_part()->layout_helper() >> 1, "must be equal");
  5011. + assert(new_class->fields()->length() == ((instanceKlass*)new_class->old_version()->klass_part())->fields()->length(), "must be equal");
  5012. +
  5013. + fieldDescriptor fd_new;
  5014. + fieldDescriptor fd_old;
  5015. + for (JavaFieldStream fs(new_class); !fs.done(); fs.next()) {
  5016. + fd_new.initialize(new_class(), fs.index());
  5017. + fd_old.initialize(new_class->old_version(), fs.index());
  5018. + transfer_special_access_flags(&fd_old, &fd_new);
  5019. + }
  5020. + }
  5021. +
  5022. + if (RC_TRACE_ENABLED(0x00000008)) {
  5023. + if (new_class->super() != NULL) {
  5024. + RC_TRACE(0x00000008, ("Super class is %s",
  5025. + new_class->super()->klass_part()->name()->as_C_string()));
  5026. + }
  5027. + }
  5028. +
  5029. +#ifdef ASSERT
  5030. + assert(new_class->super() == NULL || new_class->super()->klass_part()->new_version() == NULL, "Super klass must be newest version!");
  5031. +
  5032. + the_class->vtable()->verify(tty);
  5033. + new_class->vtable()->verify(tty);
  5034. +#endif
  5035. +
  5036. + RC_TRACE(0x00000002, ("Verification done!"));
  5037. +
  5038. + if (i == all_affected_klasses.length() - 1) {
  5039. +
  5040. + // This was the last class processed => check if additional classes have been loaded in the meantime
  5041. +
  5042. + RC_TIMER_STOP(_timer_prologue);
  5043. + lock_threads();
  5044. + RC_TIMER_START(_timer_prologue);
  5045. +
  5046. + for (int j=0; j<all_affected_klasses.length(); j++) {
  5047. +
  5048. + klassOop initial_klass = all_affected_klasses.at(j)();
  5049. + Klass *initial_subklass = initial_klass->klass_part()->subklass();
  5050. + Klass *cur_klass = initial_subklass;
  5051. + while(cur_klass != NULL) {
  5052. +
  5053. + if(cur_klass->oop_is_instance() && cur_klass->is_newest_version()) {
  5054. + instanceKlassHandle handle(THREAD, cur_klass->as_klassOop());
  5055. + if (!all_affected_klasses.contains(handle)) {
  5056. +
  5057. + int k = i + 1;
  5058. + for (; k<all_affected_klasses.length(); k++) {
  5059. + if (all_affected_klasses.at(k)->is_subtype_of(cur_klass->as_klassOop())) {
  5060. + break;
  5061. + }
  5062. + }
  5063. + all_affected_klasses.insert_before(k, handle);
  5064. + RC_TRACE(0x00000002, ("Adding newly loaded class to affected classes: %s",
  5065. + cur_klass->name()->as_C_string()));
  5066. + }
  5067. + }
  5068. +
  5069. + cur_klass = cur_klass->next_sibling();
  5070. + }
  5071. + }
  5072. +
  5073. + int new_count = all_affected_klasses.length() - 1 - i;
  5074. + if (new_count != 0) {
  5075. +
  5076. + unlock_threads();
  5077. + RC_TRACE(0x00000001, ("Found new number of affected classes: %d",
  5078. + new_count));
  5079. + }
  5080. }
  5081. }
  5082. - for (int i = 0; i < _class_count; i++) {
  5083. - redefine_single_class(_class_defs[i].klass, _scratch_classes[i], thread);
  5084. + if (result != JVMTI_ERROR_NONE) {
  5085. + rollback();
  5086. + return result;
  5087. }
  5088. - // Disable any dependent concurrent compilations
  5089. - SystemDictionary::notice_modification();
  5090. -
  5091. - // Set flag indicating that some invariants are no longer true.
  5092. - // See jvmtiExport.hpp for detailed explanation.
  5093. - JvmtiExport::set_has_redefined_a_class();
  5094. -
  5095. -// check_class() is optionally called for product bits, but is
  5096. -// always called for non-product bits.
  5097. -#ifdef PRODUCT
  5098. - if (RC_TRACE_ENABLED(0x00004000)) {
  5099. +
  5100. + RC_TIMER_STOP(_timer_prologue);
  5101. + RC_TIMER_START(_timer_class_linking);
  5102. + // Link and verify new classes _after_ all classes have been updated in the system dictionary!
  5103. + for (int i=0; i<all_affected_klasses.length(); i++) {
  5104. + instanceKlassHandle the_class = all_affected_klasses.at(i);
  5105. + instanceKlassHandle new_class(the_class->new_version());
  5106. +
  5107. + RC_TRACE(0x00000002, ("Linking class %d/%d %s",
  5108. + i,
  5109. + all_affected_klasses.length(),
  5110. + the_class->name()->as_C_string()));
  5111. + new_class->link_class(THREAD);
  5112. +
  5113. + result = check_exception();
  5114. + if (result != JVMTI_ERROR_NONE) break;
  5115. + }
  5116. + RC_TIMER_STOP(_timer_class_linking);
  5117. + RC_TIMER_START(_timer_prologue);
  5118. +
  5119. + if (result != JVMTI_ERROR_NONE) {
  5120. + rollback();
  5121. + return result;
  5122. + }
  5123. +
  5124. + RC_TRACE(0x00000002, ("All classes loaded!"));
  5125. +
  5126. +#ifdef ASSERT
  5127. + for (int i=0; i<all_affected_klasses.length(); i++) {
  5128. + instanceKlassHandle the_class = all_affected_klasses.at(i);
  5129. + assert(the_class->new_version() != NULL, "Must have been redefined");
  5130. + instanceKlassHandle new_version = instanceKlassHandle(THREAD, the_class->new_version());
  5131. + assert(new_version->new_version() == NULL, "Must be newest version");
  5132. +
  5133. + if (!(new_version->super() == NULL || new_version->super()->klass_part()->new_version() == NULL)) {
  5134. + new_version()->print();
  5135. + new_version->super()->print();
  5136. + }
  5137. + assert(new_version->super() == NULL || new_version->super()->klass_part()->new_version() == NULL, "Super class must be newest version");
  5138. + }
  5139. +
  5140. + SystemDictionary::classes_do(check_class, THREAD);
  5141. +
  5142. #endif
  5143. - RC_TRACE_WITH_THREAD(0x00004000, thread, ("calling check_class"));
  5144. - SystemDictionary::classes_do(check_class, thread);
  5145. -#ifdef PRODUCT
  5146. +
  5147. + RC_TRACE(0x00000001, ("Finished verification!"));
  5148. + return JVMTI_ERROR_NONE;
  5149. +}
  5150. +
  5151. +void VM_RedefineClasses::lock_threads() {
  5152. +
  5153. + RC_TIMER_START(_timer_wait_for_locks);
  5154. +
  5155. +
  5156. + JavaThread *javaThread = Threads::first();
  5157. + while (javaThread != NULL) {
  5158. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  5159. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  5160. + compilerThread->set_should_bailout(true);
  5161. + }
  5162. + javaThread = javaThread->next();
  5163. }
  5164. -#endif
  5165. +
  5166. + int cnt = 0;
  5167. + javaThread = Threads::first();
  5168. + while (javaThread != NULL) {
  5169. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  5170. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  5171. + compilerThread->compilation_mutex()->lock();
  5172. + cnt++;
  5173. + }
  5174. + javaThread = javaThread->next();
  5175. + }
  5176. +
  5177. + RC_TRACE(0x00000002, ("Locked %d compiler threads", cnt));
  5178. +
  5179. + cnt = 0;
  5180. + javaThread = Threads::first();
  5181. + while (javaThread != NULL) {
  5182. + if (javaThread != Thread::current()) {
  5183. + javaThread->redefine_classes_mutex()->lock();
  5184. + }
  5185. + javaThread = javaThread->next();
  5186. + }
  5187. +
  5188. +
  5189. + RC_TRACE(0x00000002, ("Locked %d threads", cnt));
  5190. +
  5191. + RC_TIMER_STOP(_timer_wait_for_locks);
  5192. }
  5193. -void VM_RedefineClasses::doit_epilogue() {
  5194. - // Free os::malloc allocated memory.
  5195. - // The memory allocated in redefine will be free'ed in next VM operation.
  5196. - os::free(_scratch_classes);
  5197. -
  5198. - if (RC_TRACE_ENABLED(0x00000004)) {
  5199. - // Used to have separate timers for "doit" and "all", but the timer
  5200. - // overhead skewed the measurements.
  5201. - jlong doit_time = _timer_rsc_phase1.milliseconds() +
  5202. - _timer_rsc_phase2.milliseconds();
  5203. - jlong all_time = _timer_vm_op_prologue.milliseconds() + doit_time;
  5204. -
  5205. - RC_TRACE(0x00000004, ("vm_op: all=" UINT64_FORMAT
  5206. - " prologue=" UINT64_FORMAT " doit=" UINT64_FORMAT, all_time,
  5207. - _timer_vm_op_prologue.milliseconds(), doit_time));
  5208. - RC_TRACE(0x00000004,
  5209. - ("redefine_single_class: phase1=" UINT64_FORMAT " phase2=" UINT64_FORMAT,
  5210. - _timer_rsc_phase1.milliseconds(), _timer_rsc_phase2.milliseconds()));
  5211. +void VM_RedefineClasses::unlock_threads() {
  5212. +
  5213. + int cnt = 0;
  5214. + JavaThread *javaThread = Threads::first();
  5215. + Thread *thread = Thread::current();
  5216. + while (javaThread != NULL) {
  5217. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  5218. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  5219. + if (compilerThread->compilation_mutex()->owned_by_self()) {
  5220. + compilerThread->compilation_mutex()->unlock();
  5221. + cnt++;
  5222. + }
  5223. + }
  5224. + javaThread = javaThread->next();
  5225. }
  5226. +
  5227. + RC_TRACE(0x00000002, ("Unlocked %d compiler threads", cnt));
  5228. +
  5229. + cnt = 0;
  5230. + javaThread = Threads::first();
  5231. + while (javaThread != NULL) {
  5232. + if (javaThread != Thread::current()) {
  5233. + if (javaThread->redefine_classes_mutex()->owned_by_self()) {
  5234. + javaThread->redefine_classes_mutex()->unlock();
  5235. + }
  5236. + }
  5237. + javaThread = javaThread->next();
  5238. + }
  5239. +
  5240. + RC_TRACE(0x00000002, ("Unlocked %d threads", cnt));
  5241. }
  5242. -bool VM_RedefineClasses::is_modifiable_class(oop klass_mirror) {
  5243. - // classes for primitives cannot be redefined
  5244. - if (java_lang_Class::is_primitive(klass_mirror)) {
  5245. - return false;
  5246. - }
  5247. - klassOop the_class_oop = java_lang_Class::as_klassOop(klass_mirror);
  5248. - // classes for arrays cannot be redefined
  5249. - if (the_class_oop == NULL || !Klass::cast(the_class_oop)->oop_is_instance()) {
  5250. - return false;
  5251. - }
  5252. - return true;
  5253. -}
  5254. -
  5255. -// Append the current entry at scratch_i in scratch_cp to *merge_cp_p
  5256. -// where the end of *merge_cp_p is specified by *merge_cp_length_p. For
  5257. -// direct CP entries, there is just the current entry to append. For
  5258. -// indirect and double-indirect CP entries, there are zero or more
  5259. -// referenced CP entries along with the current entry to append.
  5260. -// Indirect and double-indirect CP entries are handled by recursive
  5261. -// calls to append_entry() as needed. The referenced CP entries are
  5262. -// always appended to *merge_cp_p before the referee CP entry. These
  5263. -// referenced CP entries may already exist in *merge_cp_p in which case
  5264. -// there is nothing extra to append and only the current entry is
  5265. -// appended.
  5266. -void VM_RedefineClasses::append_entry(constantPoolHandle scratch_cp,
  5267. - int scratch_i, constantPoolHandle *merge_cp_p, int *merge_cp_length_p,
  5268. - TRAPS) {
  5269. -
  5270. - // append is different depending on entry tag type
  5271. - switch (scratch_cp->tag_at(scratch_i).value()) {
  5272. -
  5273. - // The old verifier is implemented outside the VM. It loads classes,
  5274. - // but does not resolve constant pool entries directly so we never
  5275. - // see Class entries here with the old verifier. Similarly the old
  5276. - // verifier does not like Class entries in the input constant pool.
  5277. - // The split-verifier is implemented in the VM so it can optionally
  5278. - // and directly resolve constant pool entries to load classes. The
  5279. - // split-verifier can accept either Class entries or UnresolvedClass
  5280. - // entries in the input constant pool. We revert the appended copy
  5281. - // back to UnresolvedClass so that either verifier will be happy
  5282. - // with the constant pool entry.
  5283. - case JVM_CONSTANT_Class:
  5284. - {
  5285. - // revert the copy to JVM_CONSTANT_UnresolvedClass
  5286. - (*merge_cp_p)->unresolved_klass_at_put(*merge_cp_length_p,
  5287. - scratch_cp->klass_name_at(scratch_i));
  5288. -
  5289. - if (scratch_i != *merge_cp_length_p) {
  5290. - // The new entry in *merge_cp_p is at a different index than
  5291. - // the new entry in scratch_cp so we need to map the index values.
  5292. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5293. - }
  5294. - (*merge_cp_length_p)++;
  5295. - } break;
  5296. -
  5297. - // these are direct CP entries so they can be directly appended,
  5298. - // but double and long take two constant pool entries
  5299. - case JVM_CONSTANT_Double: // fall through
  5300. - case JVM_CONSTANT_Long:
  5301. - {
  5302. - constantPoolOopDesc::copy_entry_to(scratch_cp, scratch_i, *merge_cp_p, *merge_cp_length_p,
  5303. - THREAD);
  5304. -
  5305. - if (scratch_i != *merge_cp_length_p) {
  5306. - // The new entry in *merge_cp_p is at a different index than
  5307. - // the new entry in scratch_cp so we need to map the index values.
  5308. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5309. - }
  5310. - (*merge_cp_length_p) += 2;
  5311. - } break;
  5312. -
  5313. - // these are direct CP entries so they can be directly appended
  5314. - case JVM_CONSTANT_Float: // fall through
  5315. - case JVM_CONSTANT_Integer: // fall through
  5316. - case JVM_CONSTANT_Utf8: // fall through
  5317. -
  5318. - // This was an indirect CP entry, but it has been changed into
  5319. - // an interned string so this entry can be directly appended.
  5320. - case JVM_CONSTANT_String: // fall through
  5321. -
  5322. - // These were indirect CP entries, but they have been changed into
  5323. - // Symbol*s so these entries can be directly appended.
  5324. - case JVM_CONSTANT_UnresolvedClass: // fall through
  5325. - case JVM_CONSTANT_UnresolvedString:
  5326. - {
  5327. - constantPoolOopDesc::copy_entry_to(scratch_cp, scratch_i, *merge_cp_p, *merge_cp_length_p,
  5328. - THREAD);
  5329. -
  5330. - if (scratch_i != *merge_cp_length_p) {
  5331. - // The new entry in *merge_cp_p is at a different index than
  5332. - // the new entry in scratch_cp so we need to map the index values.
  5333. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5334. - }
  5335. - (*merge_cp_length_p)++;
  5336. - } break;
  5337. -
  5338. - // this is an indirect CP entry so it needs special handling
  5339. - case JVM_CONSTANT_NameAndType:
  5340. - {
  5341. - int name_ref_i = scratch_cp->name_ref_index_at(scratch_i);
  5342. - int new_name_ref_i = 0;
  5343. - bool match = (name_ref_i < *merge_cp_length_p) &&
  5344. - scratch_cp->compare_entry_to(name_ref_i, *merge_cp_p, name_ref_i,
  5345. - THREAD);
  5346. - if (!match) {
  5347. - // forward reference in *merge_cp_p or not a direct match
  5348. -
  5349. - int found_i = scratch_cp->find_matching_entry(name_ref_i, *merge_cp_p,
  5350. - THREAD);
  5351. - if (found_i != 0) {
  5352. - guarantee(found_i != name_ref_i,
  5353. - "compare_entry_to() and find_matching_entry() do not agree");
  5354. -
  5355. - // Found a matching entry somewhere else in *merge_cp_p so
  5356. - // just need a mapping entry.
  5357. - new_name_ref_i = found_i;
  5358. - map_index(scratch_cp, name_ref_i, found_i);
  5359. - } else {
  5360. - // no match found so we have to append this entry to *merge_cp_p
  5361. - append_entry(scratch_cp, name_ref_i, merge_cp_p, merge_cp_length_p,
  5362. - THREAD);
  5363. - // The above call to append_entry() can only append one entry
  5364. - // so the post call query of *merge_cp_length_p is only for
  5365. - // the sake of consistency.
  5366. - new_name_ref_i = *merge_cp_length_p - 1;
  5367. - }
  5368. - }
  5369. -
  5370. - int signature_ref_i = scratch_cp->signature_ref_index_at(scratch_i);
  5371. - int new_signature_ref_i = 0;
  5372. - match = (signature_ref_i < *merge_cp_length_p) &&
  5373. - scratch_cp->compare_entry_to(signature_ref_i, *merge_cp_p,
  5374. - signature_ref_i, THREAD);
  5375. - if (!match) {
  5376. - // forward reference in *merge_cp_p or not a direct match
  5377. -
  5378. - int found_i = scratch_cp->find_matching_entry(signature_ref_i,
  5379. - *merge_cp_p, THREAD);
  5380. - if (found_i != 0) {
  5381. - guarantee(found_i != signature_ref_i,
  5382. - "compare_entry_to() and find_matching_entry() do not agree");
  5383. -
  5384. - // Found a matching entry somewhere else in *merge_cp_p so
  5385. - // just need a mapping entry.
  5386. - new_signature_ref_i = found_i;
  5387. - map_index(scratch_cp, signature_ref_i, found_i);
  5388. - } else {
  5389. - // no match found so we have to append this entry to *merge_cp_p
  5390. - append_entry(scratch_cp, signature_ref_i, merge_cp_p,
  5391. - merge_cp_length_p, THREAD);
  5392. - // The above call to append_entry() can only append one entry
  5393. - // so the post call query of *merge_cp_length_p is only for
  5394. - // the sake of consistency.
  5395. - new_signature_ref_i = *merge_cp_length_p - 1;
  5396. - }
  5397. - }
  5398. -
  5399. - // If the referenced entries already exist in *merge_cp_p, then
  5400. - // both new_name_ref_i and new_signature_ref_i will both be 0.
  5401. - // In that case, all we are appending is the current entry.
  5402. - if (new_name_ref_i == 0) {
  5403. - new_name_ref_i = name_ref_i;
  5404. - } else {
  5405. - RC_TRACE(0x00080000,
  5406. - ("NameAndType entry@%d name_ref_index change: %d to %d",
  5407. - *merge_cp_length_p, name_ref_i, new_name_ref_i));
  5408. - }
  5409. - if (new_signature_ref_i == 0) {
  5410. - new_signature_ref_i = signature_ref_i;
  5411. - } else {
  5412. - RC_TRACE(0x00080000,
  5413. - ("NameAndType entry@%d signature_ref_index change: %d to %d",
  5414. - *merge_cp_length_p, signature_ref_i, new_signature_ref_i));
  5415. - }
  5416. -
  5417. - (*merge_cp_p)->name_and_type_at_put(*merge_cp_length_p,
  5418. - new_name_ref_i, new_signature_ref_i);
  5419. - if (scratch_i != *merge_cp_length_p) {
  5420. - // The new entry in *merge_cp_p is at a different index than
  5421. - // the new entry in scratch_cp so we need to map the index values.
  5422. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5423. - }
  5424. - (*merge_cp_length_p)++;
  5425. - } break;
  5426. -
  5427. - // this is a double-indirect CP entry so it needs special handling
  5428. - case JVM_CONSTANT_Fieldref: // fall through
  5429. - case JVM_CONSTANT_InterfaceMethodref: // fall through
  5430. - case JVM_CONSTANT_Methodref:
  5431. - {
  5432. - int klass_ref_i = scratch_cp->uncached_klass_ref_index_at(scratch_i);
  5433. - int new_klass_ref_i = 0;
  5434. - bool match = (klass_ref_i < *merge_cp_length_p) &&
  5435. - scratch_cp->compare_entry_to(klass_ref_i, *merge_cp_p, klass_ref_i,
  5436. - THREAD);
  5437. - if (!match) {
  5438. - // forward reference in *merge_cp_p or not a direct match
  5439. -
  5440. - int found_i = scratch_cp->find_matching_entry(klass_ref_i, *merge_cp_p,
  5441. - THREAD);
  5442. - if (found_i != 0) {
  5443. - guarantee(found_i != klass_ref_i,
  5444. - "compare_entry_to() and find_matching_entry() do not agree");
  5445. -
  5446. - // Found a matching entry somewhere else in *merge_cp_p so
  5447. - // just need a mapping entry.
  5448. - new_klass_ref_i = found_i;
  5449. - map_index(scratch_cp, klass_ref_i, found_i);
  5450. - } else {
  5451. - // no match found so we have to append this entry to *merge_cp_p
  5452. - append_entry(scratch_cp, klass_ref_i, merge_cp_p, merge_cp_length_p,
  5453. - THREAD);
  5454. - // The above call to append_entry() can only append one entry
  5455. - // so the post call query of *merge_cp_length_p is only for
  5456. - // the sake of consistency. Without the optimization where we
  5457. - // use JVM_CONSTANT_UnresolvedClass, then up to two entries
  5458. - // could be appended.
  5459. - new_klass_ref_i = *merge_cp_length_p - 1;
  5460. - }
  5461. - }
  5462. -
  5463. - int name_and_type_ref_i =
  5464. - scratch_cp->uncached_name_and_type_ref_index_at(scratch_i);
  5465. - int new_name_and_type_ref_i = 0;
  5466. - match = (name_and_type_ref_i < *merge_cp_length_p) &&
  5467. - scratch_cp->compare_entry_to(name_and_type_ref_i, *merge_cp_p,
  5468. - name_and_type_ref_i, THREAD);
  5469. - if (!match) {
  5470. - // forward reference in *merge_cp_p or not a direct match
  5471. -
  5472. - int found_i = scratch_cp->find_matching_entry(name_and_type_ref_i,
  5473. - *merge_cp_p, THREAD);
  5474. - if (found_i != 0) {
  5475. - guarantee(found_i != name_and_type_ref_i,
  5476. - "compare_entry_to() and find_matching_entry() do not agree");
  5477. -
  5478. - // Found a matching entry somewhere else in *merge_cp_p so
  5479. - // just need a mapping entry.
  5480. - new_name_and_type_ref_i = found_i;
  5481. - map_index(scratch_cp, name_and_type_ref_i, found_i);
  5482. - } else {
  5483. - // no match found so we have to append this entry to *merge_cp_p
  5484. - append_entry(scratch_cp, name_and_type_ref_i, merge_cp_p,
  5485. - merge_cp_length_p, THREAD);
  5486. - // The above call to append_entry() can append more than
  5487. - // one entry so the post call query of *merge_cp_length_p
  5488. - // is required in order to get the right index for the
  5489. - // JVM_CONSTANT_NameAndType entry.
  5490. - new_name_and_type_ref_i = *merge_cp_length_p - 1;
  5491. - }
  5492. - }
  5493. -
  5494. - // If the referenced entries already exist in *merge_cp_p, then
  5495. - // both new_klass_ref_i and new_name_and_type_ref_i will both be
  5496. - // 0. In that case, all we are appending is the current entry.
  5497. - if (new_klass_ref_i == 0) {
  5498. - new_klass_ref_i = klass_ref_i;
  5499. - }
  5500. - if (new_name_and_type_ref_i == 0) {
  5501. - new_name_and_type_ref_i = name_and_type_ref_i;
  5502. - }
  5503. -
  5504. - const char *entry_name;
  5505. - switch (scratch_cp->tag_at(scratch_i).value()) {
  5506. - case JVM_CONSTANT_Fieldref:
  5507. - entry_name = "Fieldref";
  5508. - (*merge_cp_p)->field_at_put(*merge_cp_length_p, new_klass_ref_i,
  5509. - new_name_and_type_ref_i);
  5510. - break;
  5511. - case JVM_CONSTANT_InterfaceMethodref:
  5512. - entry_name = "IFMethodref";
  5513. - (*merge_cp_p)->interface_method_at_put(*merge_cp_length_p,
  5514. - new_klass_ref_i, new_name_and_type_ref_i);
  5515. - break;
  5516. - case JVM_CONSTANT_Methodref:
  5517. - entry_name = "Methodref";
  5518. - (*merge_cp_p)->method_at_put(*merge_cp_length_p, new_klass_ref_i,
  5519. - new_name_and_type_ref_i);
  5520. - break;
  5521. - default:
  5522. - guarantee(false, "bad switch");
  5523. - break;
  5524. - }
  5525. -
  5526. - if (klass_ref_i != new_klass_ref_i) {
  5527. - RC_TRACE(0x00080000, ("%s entry@%d class_index changed: %d to %d",
  5528. - entry_name, *merge_cp_length_p, klass_ref_i, new_klass_ref_i));
  5529. - }
  5530. - if (name_and_type_ref_i != new_name_and_type_ref_i) {
  5531. - RC_TRACE(0x00080000,
  5532. - ("%s entry@%d name_and_type_index changed: %d to %d",
  5533. - entry_name, *merge_cp_length_p, name_and_type_ref_i,
  5534. - new_name_and_type_ref_i));
  5535. - }
  5536. -
  5537. - if (scratch_i != *merge_cp_length_p) {
  5538. - // The new entry in *merge_cp_p is at a different index than
  5539. - // the new entry in scratch_cp so we need to map the index values.
  5540. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5541. - }
  5542. - (*merge_cp_length_p)++;
  5543. - } break;
  5544. -
  5545. - // At this stage, Class or UnresolvedClass could be here, but not
  5546. - // ClassIndex
  5547. - case JVM_CONSTANT_ClassIndex: // fall through
  5548. -
  5549. - // Invalid is used as the tag for the second constant pool entry
  5550. - // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should
  5551. - // not be seen by itself.
  5552. - case JVM_CONSTANT_Invalid: // fall through
  5553. -
  5554. - // At this stage, String or UnresolvedString could be here, but not
  5555. - // StringIndex
  5556. - case JVM_CONSTANT_StringIndex: // fall through
  5557. -
  5558. - // At this stage JVM_CONSTANT_UnresolvedClassInError should not be
  5559. - // here
  5560. - case JVM_CONSTANT_UnresolvedClassInError: // fall through
  5561. -
  5562. - default:
  5563. - {
  5564. - // leave a breadcrumb
  5565. - jbyte bad_value = scratch_cp->tag_at(scratch_i).value();
  5566. - ShouldNotReachHere();
  5567. - } break;
  5568. - } // end switch tag value
  5569. -} // end append_entry()
  5570. -
  5571. -
  5572. -void VM_RedefineClasses::swap_all_method_annotations(int i, int j, instanceKlassHandle scratch_class) {
  5573. - typeArrayOop save;
  5574. -
  5575. - save = scratch_class->get_method_annotations_of(i);
  5576. - scratch_class->set_method_annotations_of(i, scratch_class->get_method_annotations_of(j));
  5577. - scratch_class->set_method_annotations_of(j, save);
  5578. -
  5579. - save = scratch_class->get_method_parameter_annotations_of(i);
  5580. - scratch_class->set_method_parameter_annotations_of(i, scratch_class->get_method_parameter_annotations_of(j));
  5581. - scratch_class->set_method_parameter_annotations_of(j, save);
  5582. -
  5583. - save = scratch_class->get_method_default_annotations_of(i);
  5584. - scratch_class->set_method_default_annotations_of(i, scratch_class->get_method_default_annotations_of(j));
  5585. - scratch_class->set_method_default_annotations_of(j, save);
  5586. -}
  5587. -
  5588. -
  5589. -jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions(
  5590. - instanceKlassHandle the_class,
  5591. - instanceKlassHandle scratch_class) {
  5592. +jvmtiError VM_RedefineClasses::check_redefinition_allowed(instanceKlassHandle scratch_class) {
  5593. +
  5594. +
  5595. +
  5596. + // Compatibility mode => check for unsupported modification
  5597. +
  5598. +
  5599. + assert(scratch_class->old_version() != NULL, "must have old version");
  5600. + instanceKlassHandle the_class(scratch_class->old_version());
  5601. +
  5602. int i;
  5603. // Check superclasses, or rather their names, since superclasses themselves can be
  5604. // requested to replace.
  5605. // Check for NULL superclass first since this might be java.lang.Object
  5606. if (the_class->super() != scratch_class->super() &&
  5607. - (the_class->super() == NULL || scratch_class->super() == NULL ||
  5608. - Klass::cast(the_class->super())->name() !=
  5609. - Klass::cast(scratch_class->super())->name())) {
  5610. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  5611. + (the_class->super() == NULL || scratch_class->super() == NULL ||
  5612. + Klass::cast(the_class->super())->name() !=
  5613. + Klass::cast(scratch_class->super())->name())) {
  5614. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  5615. }
  5616. // Check if the number, names and order of directly implemented interfaces are the same.
  5617. @@ -539,8 +678,8 @@
  5618. }
  5619. for (i = 0; i < n_intfs; i++) {
  5620. if (Klass::cast((klassOop) k_interfaces->obj_at(i))->name() !=
  5621. - Klass::cast((klassOop) k_new_interfaces->obj_at(i))->name()) {
  5622. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  5623. + Klass::cast((klassOop) k_new_interfaces->obj_at(i))->name()) {
  5624. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  5625. }
  5626. }
  5627. @@ -689,12 +828,8 @@
  5628. idnum_owner->set_method_idnum(new_num);
  5629. }
  5630. k_new_method->set_method_idnum(old_num);
  5631. - swap_all_method_annotations(old_num, new_num, scratch_class);
  5632. }
  5633. }
  5634. - RC_TRACE(0x00008000, ("Method matched: new: %s [%d] == old: %s [%d]",
  5635. - k_new_method->name_and_sig_as_C_string(), ni,
  5636. - k_old_method->name_and_sig_as_C_string(), oi));
  5637. // advance to next pair of methods
  5638. ++oi;
  5639. ++ni;
  5640. @@ -703,11 +838,11 @@
  5641. // method added, see if it is OK
  5642. new_flags = (jushort) k_new_method->access_flags().get_flags();
  5643. if ((new_flags & JVM_ACC_PRIVATE) == 0
  5644. - // hack: private should be treated as final, but alas
  5645. - || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5646. - ) {
  5647. - // new methods must be private
  5648. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED;
  5649. + // hack: private should be treated as final, but alas
  5650. + || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5651. + ) {
  5652. + // new methods must be private
  5653. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED;
  5654. }
  5655. {
  5656. u2 num = the_class->next_method_idnum();
  5657. @@ -722,24 +857,19 @@
  5658. idnum_owner->set_method_idnum(new_num);
  5659. }
  5660. k_new_method->set_method_idnum(num);
  5661. - swap_all_method_annotations(new_num, num, scratch_class);
  5662. }
  5663. - RC_TRACE(0x00008000, ("Method added: new: %s [%d]",
  5664. - k_new_method->name_and_sig_as_C_string(), ni));
  5665. ++ni; // advance to next new method
  5666. break;
  5667. case deleted:
  5668. // method deleted, see if it is OK
  5669. old_flags = (jushort) k_old_method->access_flags().get_flags();
  5670. if ((old_flags & JVM_ACC_PRIVATE) == 0
  5671. - // hack: private should be treated as final, but alas
  5672. - || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5673. - ) {
  5674. - // deleted methods must be private
  5675. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED;
  5676. + // hack: private should be treated as final, but alas
  5677. + || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5678. + ) {
  5679. + // deleted methods must be private
  5680. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED;
  5681. }
  5682. - RC_TRACE(0x00008000, ("Method deleted: old: %s [%d]",
  5683. - k_old_method->name_and_sig_as_C_string(), oi));
  5684. ++oi; // advance to next old method
  5685. break;
  5686. default:
  5687. @@ -750,2067 +880,2266 @@
  5688. return JVMTI_ERROR_NONE;
  5689. }
  5690. -
  5691. -// Find new constant pool index value for old constant pool index value
  5692. -// by seaching the index map. Returns zero (0) if there is no mapped
  5693. -// value for the old constant pool index.
  5694. -int VM_RedefineClasses::find_new_index(int old_index) {
  5695. - if (_index_map_count == 0) {
  5696. - // map is empty so nothing can be found
  5697. - return 0;
  5698. +int VM_RedefineClasses::calculate_redefinition_flags(instanceKlassHandle new_class) {
  5699. +
  5700. + int result = Klass::NoRedefinition;
  5701. +
  5702. +
  5703. +
  5704. + RC_TRACE(0x00000002, ("Comparing different class versions of class %s",
  5705. + new_class->name()->as_C_string()));
  5706. +
  5707. + assert(new_class->old_version() != NULL, "must have old version");
  5708. + instanceKlassHandle the_class(new_class->old_version());
  5709. +
  5710. + // Check whether class is in the error init state.
  5711. + if (the_class->is_in_error_state()) {
  5712. + // TBD #5057930: special error code is needed in 1.6
  5713. + //result = Klass::union_redefinition_level(result, Klass::Invalid);
  5714. }
  5715. - if (old_index < 1 || old_index >= _index_map_p->length()) {
  5716. - // The old_index is out of range so it is not mapped. This should
  5717. - // not happen in regular constant pool merging use, but it can
  5718. - // happen if a corrupt annotation is processed.
  5719. - return 0;
  5720. + int i;
  5721. +
  5722. + //////////////////////////////////////////////////////////////////////////////////////////////////////////
  5723. + // Check superclasses
  5724. + assert(new_class->super() == NULL || new_class->super()->klass_part()->is_newest_version(), "");
  5725. + if (the_class->super() != new_class->super()) {
  5726. + // Super class changed
  5727. +
  5728. + klassOop cur_klass = the_class->super();
  5729. + while (cur_klass != NULL) {
  5730. + if (!new_class->is_subclass_of(cur_klass->klass_part()->newest_version())) {
  5731. + RC_TRACE(0x00000002, ("Removed super class %s",
  5732. + cur_klass->klass_part()->name()->as_C_string()));
  5733. + result = result | Klass::RemoveSuperType | Klass::ModifyInstances | Klass::ModifyClass;
  5734. +
  5735. + if (!cur_klass->klass_part()->has_subtype_changed()) {
  5736. + RC_TRACE(0x00000002, ("Subtype changed of class %s",
  5737. + cur_klass->klass_part()->name()->as_C_string()));
  5738. + cur_klass->klass_part()->set_subtype_changed(true);
  5739. + }
  5740. + }
  5741. +
  5742. + cur_klass = cur_klass->klass_part()->super();
  5743. + }
  5744. +
  5745. + cur_klass = new_class->super();
  5746. + while (cur_klass != NULL) {
  5747. + if (!the_class->is_subclass_of(cur_klass->klass_part()->old_version())) {
  5748. + RC_TRACE(0x00000002, ("Added super class %s",
  5749. + cur_klass->klass_part()->name()->as_C_string()));
  5750. + result = result | Klass::ModifyClass | Klass::ModifyInstances;
  5751. + }
  5752. + cur_klass = cur_klass->klass_part()->super();
  5753. + }
  5754. }
  5755. - int value = _index_map_p->at(old_index);
  5756. - if (value == -1) {
  5757. - // the old_index is not mapped
  5758. - return 0;
  5759. - }
  5760. -
  5761. - return value;
  5762. -} // end find_new_index()
  5763. -
  5764. -
  5765. -// Returns true if the current mismatch is due to a resolved/unresolved
  5766. -// class pair. Otherwise, returns false.
  5767. -bool VM_RedefineClasses::is_unresolved_class_mismatch(constantPoolHandle cp1,
  5768. - int index1, constantPoolHandle cp2, int index2) {
  5769. -
  5770. - jbyte t1 = cp1->tag_at(index1).value();
  5771. - if (t1 != JVM_CONSTANT_Class && t1 != JVM_CONSTANT_UnresolvedClass) {
  5772. - return false; // wrong entry type; not our special case
  5773. - }
  5774. -
  5775. - jbyte t2 = cp2->tag_at(index2).value();
  5776. - if (t2 != JVM_CONSTANT_Class && t2 != JVM_CONSTANT_UnresolvedClass) {
  5777. - return false; // wrong entry type; not our special case
  5778. - }
  5779. -
  5780. - if (t1 == t2) {
  5781. - return false; // not a mismatch; not our special case
  5782. - }
  5783. -
  5784. - char *s1 = cp1->klass_name_at(index1)->as_C_string();
  5785. - char *s2 = cp2->klass_name_at(index2)->as_C_string();
  5786. - if (strcmp(s1, s2) != 0) {
  5787. - return false; // strings don't match; not our special case
  5788. - }
  5789. -
  5790. - return true; // made it through the gauntlet; this is our special case
  5791. -} // end is_unresolved_class_mismatch()
  5792. -
  5793. -
  5794. -// Returns true if the current mismatch is due to a resolved/unresolved
  5795. -// string pair. Otherwise, returns false.
  5796. -bool VM_RedefineClasses::is_unresolved_string_mismatch(constantPoolHandle cp1,
  5797. - int index1, constantPoolHandle cp2, int index2) {
  5798. -
  5799. - jbyte t1 = cp1->tag_at(index1).value();
  5800. - if (t1 != JVM_CONSTANT_String && t1 != JVM_CONSTANT_UnresolvedString) {
  5801. - return false; // wrong entry type; not our special case
  5802. - }
  5803. -
  5804. - jbyte t2 = cp2->tag_at(index2).value();
  5805. - if (t2 != JVM_CONSTANT_String && t2 != JVM_CONSTANT_UnresolvedString) {
  5806. - return false; // wrong entry type; not our special case
  5807. - }
  5808. -
  5809. - if (t1 == t2) {
  5810. - return false; // not a mismatch; not our special case
  5811. - }
  5812. -
  5813. - char *s1 = cp1->string_at_noresolve(index1);
  5814. - char *s2 = cp2->string_at_noresolve(index2);
  5815. - if (strcmp(s1, s2) != 0) {
  5816. - return false; // strings don't match; not our special case
  5817. - }
  5818. -
  5819. - return true; // made it through the gauntlet; this is our special case
  5820. -} // end is_unresolved_string_mismatch()
  5821. -
  5822. -
  5823. -jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) {
  5824. - // For consistency allocate memory using os::malloc wrapper.
  5825. - _scratch_classes = (instanceKlassHandle *)
  5826. - os::malloc(sizeof(instanceKlassHandle) * _class_count, mtInternal);
  5827. - if (_scratch_classes == NULL) {
  5828. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5829. - }
  5830. -
  5831. - ResourceMark rm(THREAD);
  5832. -
  5833. - JvmtiThreadState *state = JvmtiThreadState::state_for(JavaThread::current());
  5834. - // state can only be NULL if the current thread is exiting which
  5835. - // should not happen since we're trying to do a RedefineClasses
  5836. - guarantee(state != NULL, "exiting thread calling load_new_class_versions");
  5837. - for (int i = 0; i < _class_count; i++) {
  5838. - oop mirror = JNIHandles::resolve_non_null(_class_defs[i].klass);
  5839. - // classes for primitives cannot be redefined
  5840. - if (!is_modifiable_class(mirror)) {
  5841. - return JVMTI_ERROR_UNMODIFIABLE_CLASS;
  5842. - }
  5843. - klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
  5844. - instanceKlassHandle the_class = instanceKlassHandle(THREAD, the_class_oop);
  5845. - Symbol* the_class_sym = the_class->name();
  5846. -
  5847. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5848. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  5849. - ("loading name=%s kind=%d (avail_mem=" UINT64_FORMAT "K)",
  5850. - the_class->external_name(), _class_load_kind,
  5851. - os::available_memory() >> 10));
  5852. -
  5853. - ClassFileStream st((u1*) _class_defs[i].class_bytes,
  5854. - _class_defs[i].class_byte_count, (char *)"__VM_RedefineClasses__");
  5855. -
  5856. - // Parse the stream.
  5857. - Handle the_class_loader(THREAD, the_class->class_loader());
  5858. - Handle protection_domain(THREAD, the_class->protection_domain());
  5859. - // Set redefined class handle in JvmtiThreadState class.
  5860. - // This redefined class is sent to agent event handler for class file
  5861. - // load hook event.
  5862. - state->set_class_being_redefined(&the_class, _class_load_kind);
  5863. -
  5864. - klassOop k = SystemDictionary::parse_stream(the_class_sym,
  5865. - the_class_loader,
  5866. - protection_domain,
  5867. - &st,
  5868. - THREAD);
  5869. - // Clear class_being_redefined just to be sure.
  5870. - state->clear_class_being_redefined();
  5871. -
  5872. - // TODO: if this is retransform, and nothing changed we can skip it
  5873. -
  5874. - instanceKlassHandle scratch_class (THREAD, k);
  5875. -
  5876. - if (HAS_PENDING_EXCEPTION) {
  5877. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  5878. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5879. - RC_TRACE_WITH_THREAD(0x00000002, THREAD, ("parse_stream exception: '%s'",
  5880. - ex_name->as_C_string()));
  5881. - CLEAR_PENDING_EXCEPTION;
  5882. -
  5883. - if (ex_name == vmSymbols::java_lang_UnsupportedClassVersionError()) {
  5884. - return JVMTI_ERROR_UNSUPPORTED_VERSION;
  5885. - } else if (ex_name == vmSymbols::java_lang_ClassFormatError()) {
  5886. - return JVMTI_ERROR_INVALID_CLASS_FORMAT;
  5887. - } else if (ex_name == vmSymbols::java_lang_ClassCircularityError()) {
  5888. - return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  5889. - } else if (ex_name == vmSymbols::java_lang_NoClassDefFoundError()) {
  5890. - // The message will be "XXX (wrong name: YYY)"
  5891. - return JVMTI_ERROR_NAMES_DONT_MATCH;
  5892. - } else if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  5893. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5894. - } else { // Just in case more exceptions can be thrown..
  5895. - return JVMTI_ERROR_FAILS_VERIFICATION;
  5896. + //////////////////////////////////////////////////////////////////////////////////////////////////////////
  5897. + // Check interfaces
  5898. +
  5899. + // Interfaces removed?
  5900. + objArrayOop old_interfaces = the_class->transitive_interfaces();
  5901. + for (i = 0; i<old_interfaces->length(); i++) {
  5902. + instanceKlassHandle old_interface((klassOop)old_interfaces->obj_at(i));
  5903. + if (!new_class->implements_interface_any_version(old_interface())) {
  5904. + result = result | Klass::RemoveSuperType | Klass::ModifyClass;
  5905. + RC_TRACE(0x00000002, ("Removed interface %s",
  5906. + old_interface->name()->as_C_string()));
  5907. +
  5908. + if (!old_interface->has_subtype_changed()) {
  5909. + RC_TRACE(0x00000002, ("Subtype changed of interface %s",
  5910. + old_interface->name()->as_C_string()));
  5911. + old_interface->set_subtype_changed(true);
  5912. }
  5913. }
  5914. -
  5915. - // Ensure class is linked before redefine
  5916. - if (!the_class->is_linked()) {
  5917. - the_class->link_class(THREAD);
  5918. - if (HAS_PENDING_EXCEPTION) {
  5919. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  5920. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5921. - RC_TRACE_WITH_THREAD(0x00000002, THREAD, ("link_class exception: '%s'",
  5922. - ex_name->as_C_string()));
  5923. - CLEAR_PENDING_EXCEPTION;
  5924. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  5925. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5926. + }
  5927. +
  5928. + // Interfaces added?
  5929. + objArrayOop new_interfaces = new_class->transitive_interfaces();
  5930. + for (i = 0; i<new_interfaces->length(); i++) {
  5931. + if (!the_class->implements_interface_any_version((klassOop)new_interfaces->obj_at(i))) {
  5932. + result = result | Klass::ModifyClass;
  5933. + RC_TRACE(0x00000002, ("Added interface %s",
  5934. + ((klassOop)new_interfaces->obj_at(i))->klass_part()->name()->as_C_string()));
  5935. + }
  5936. + }
  5937. +
  5938. +
  5939. + // Check whether class modifiers are the same.
  5940. + jushort old_flags = (jushort) the_class->access_flags().get_flags();
  5941. + jushort new_flags = (jushort) new_class->access_flags().get_flags();
  5942. + if (old_flags != new_flags) {
  5943. + // TODO (tw): Can this have any effects?
  5944. + }
  5945. +
  5946. + // Check if the number, names, types and order of fields declared in these classes
  5947. + // are the same.
  5948. + JavaFieldStream old_fs(the_class);
  5949. + JavaFieldStream new_fs(new_class);
  5950. + for (; !old_fs.done() && !new_fs.done(); old_fs.next(), new_fs.next()) {
  5951. + // access
  5952. + old_flags = old_fs.access_flags().as_short();
  5953. + new_flags = new_fs.access_flags().as_short();
  5954. + if ((old_flags ^ new_flags) & JVM_RECOGNIZED_FIELD_MODIFIERS) {
  5955. + // (tw) Can this have any effects?
  5956. + }
  5957. + // offset
  5958. + if (old_fs.offset() != new_fs.offset()) {
  5959. + result = result | Klass::ModifyInstances;
  5960. + }
  5961. + // name and signature
  5962. + Symbol* name_sym1 = the_class->constants()->symbol_at(old_fs.name_index());
  5963. + Symbol* sig_sym1 = the_class->constants()->symbol_at(old_fs.signature_index());
  5964. + Symbol* name_sym2 = new_class->constants()->symbol_at(new_fs.name_index());
  5965. + Symbol* sig_sym2 = new_class->constants()->symbol_at(new_fs.signature_index());
  5966. + if (name_sym1 != name_sym2 || sig_sym1 != sig_sym2) {
  5967. + result = result | Klass::ModifyInstances;
  5968. + }
  5969. + }
  5970. +
  5971. + if (!old_fs.done() || !new_fs.done()) {
  5972. + result = result | Klass::ModifyInstances;
  5973. + }
  5974. +
  5975. + // Do a parallel walk through the old and new methods. Detect
  5976. + // cases where they match (exist in both), have been added in
  5977. + // the new methods, or have been deleted (exist only in the
  5978. + // old methods). The class file parser places methods in order
  5979. + // by method name, but does not order overloaded methods by
  5980. + // signature. In order to determine what fate befell the methods,
  5981. + // this code places the overloaded new methods that have matching
  5982. + // old methods in the same order as the old methods and places
  5983. + // new overloaded methods at the end of overloaded methods of
  5984. + // that name. The code for this order normalization is adapted
  5985. + // from the algorithm used in instanceKlass::find_method().
  5986. + // Since we are swapping out of order entries as we find them,
  5987. + // we only have to search forward through the overloaded methods.
  5988. + // Methods which are added and have the same name as an existing
  5989. + // method (but different signature) will be put at the end of
  5990. + // the methods with that name, and the name mismatch code will
  5991. + // handle them.
  5992. + objArrayHandle k_old_methods(the_class->methods());
  5993. + objArrayHandle k_new_methods(new_class->methods());
  5994. + int n_old_methods = k_old_methods->length();
  5995. + int n_new_methods = k_new_methods->length();
  5996. +
  5997. + int ni = 0;
  5998. + int oi = 0;
  5999. + while (true) {
  6000. + methodOop k_old_method;
  6001. + methodOop k_new_method;
  6002. + enum { matched, added, deleted, undetermined } method_was = undetermined;
  6003. +
  6004. + if (oi >= n_old_methods) {
  6005. + if (ni >= n_new_methods) {
  6006. + break; // we've looked at everything, done
  6007. + }
  6008. + // New method at the end
  6009. + k_new_method = (methodOop) k_new_methods->obj_at(ni);
  6010. + method_was = added;
  6011. + } else if (ni >= n_new_methods) {
  6012. + // Old method, at the end, is deleted
  6013. + k_old_method = (methodOop) k_old_methods->obj_at(oi);
  6014. + method_was = deleted;
  6015. + } else {
  6016. + // There are more methods in both the old and new lists
  6017. + k_old_method = (methodOop) k_old_methods->obj_at(oi);
  6018. + k_new_method = (methodOop) k_new_methods->obj_at(ni);
  6019. + if (k_old_method->name() != k_new_method->name()) {
  6020. + // Methods are sorted by method name, so a mismatch means added
  6021. + // or deleted
  6022. + if (k_old_method->name()->fast_compare(k_new_method->name()) > 0) {
  6023. + method_was = added;
  6024. } else {
  6025. - return JVMTI_ERROR_INTERNAL;
  6026. + method_was = deleted;
  6027. + }
  6028. + } else if (k_old_method->signature() == k_new_method->signature()) {
  6029. + // Both the name and signature match
  6030. + method_was = matched;
  6031. + } else {
  6032. + // The name matches, but the signature doesn't, which means we have to
  6033. + // search forward through the new overloaded methods.
  6034. + int nj; // outside the loop for post-loop check
  6035. + for (nj = ni + 1; nj < n_new_methods; nj++) {
  6036. + methodOop m = (methodOop)k_new_methods->obj_at(nj);
  6037. + if (k_old_method->name() != m->name()) {
  6038. + // reached another method name so no more overloaded methods
  6039. + method_was = deleted;
  6040. + break;
  6041. + }
  6042. + if (k_old_method->signature() == m->signature()) {
  6043. + // found a match so swap the methods
  6044. + k_new_methods->obj_at_put(ni, m);
  6045. + k_new_methods->obj_at_put(nj, k_new_method);
  6046. + k_new_method = m;
  6047. + method_was = matched;
  6048. + break;
  6049. + }
  6050. + }
  6051. +
  6052. + if (nj >= n_new_methods) {
  6053. + // reached the end without a match; so method was deleted
  6054. + method_was = deleted;
  6055. }
  6056. }
  6057. }
  6058. - // Do the validity checks in compare_and_normalize_class_versions()
  6059. - // before verifying the byte codes. By doing these checks first, we
  6060. - // limit the number of functions that require redirection from
  6061. - // the_class to scratch_class. In particular, we don't have to
  6062. - // modify JNI GetSuperclass() and thus won't change its performance.
  6063. - jvmtiError res = compare_and_normalize_class_versions(the_class,
  6064. - scratch_class);
  6065. - if (res != JVMTI_ERROR_NONE) {
  6066. - return res;
  6067. + switch (method_was) {
  6068. + case matched:
  6069. + // methods match, be sure modifiers do too
  6070. + old_flags = (jushort) k_old_method->access_flags().get_flags();
  6071. + new_flags = (jushort) k_new_method->access_flags().get_flags();
  6072. + if ((old_flags ^ new_flags) & ~(JVM_ACC_NATIVE)) {
  6073. + // (tw) Can this have any effects? Probably yes on vtables?
  6074. + result = result | Klass::ModifyClass;
  6075. }
  6076. -
  6077. - // verify what the caller passed us
  6078. {
  6079. - // The bug 6214132 caused the verification to fail.
  6080. - // Information about the_class and scratch_class is temporarily
  6081. - // recorded into jvmtiThreadState. This data is used to redirect
  6082. - // the_class to scratch_class in the JVM_* functions called by the
  6083. - // verifier. Please, refer to jvmtiThreadState.hpp for the detailed
  6084. - // description.
  6085. - RedefineVerifyMark rvm(&the_class, &scratch_class, state);
  6086. - Verifier::verify(
  6087. - scratch_class, Verifier::ThrowException, true, THREAD);
  6088. - }
  6089. -
  6090. - if (HAS_PENDING_EXCEPTION) {
  6091. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  6092. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  6093. - RC_TRACE_WITH_THREAD(0x00000002, THREAD,
  6094. - ("verify_byte_codes exception: '%s'", ex_name->as_C_string()));
  6095. - CLEAR_PENDING_EXCEPTION;
  6096. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  6097. - return JVMTI_ERROR_OUT_OF_MEMORY;
  6098. - } else {
  6099. - // tell the caller the bytecodes are bad
  6100. - return JVMTI_ERROR_FAILS_VERIFICATION;
  6101. + u2 new_num = k_new_method->method_idnum();
  6102. + u2 old_num = k_old_method->method_idnum();
  6103. + if (new_num != old_num) {
  6104. + methodOop idnum_owner = new_class->method_with_idnum(old_num);
  6105. + if (idnum_owner != NULL) {
  6106. + // There is already a method assigned this idnum -- switch them
  6107. + idnum_owner->set_method_idnum(new_num);
  6108. + }
  6109. + k_new_method->set_method_idnum(old_num);
  6110. + RC_TRACE(0x00000002, ("swapping idnum of new and old method %d / %d!",
  6111. + new_num,
  6112. + old_num));
  6113. + // swap_all_method_annotations(old_num, new_num, new_class);
  6114. }
  6115. }
  6116. -
  6117. - res = merge_cp_and_rewrite(the_class, scratch_class, THREAD);
  6118. - if (res != JVMTI_ERROR_NONE) {
  6119. - return res;
  6120. + RC_TRACE(0x00008000, ("Method matched: new: %s [%d] == old: %s [%d]",
  6121. + k_new_method->name_and_sig_as_C_string(), ni,
  6122. + k_old_method->name_and_sig_as_C_string(), oi));
  6123. + // advance to next pair of methods
  6124. + ++oi;
  6125. + ++ni;
  6126. + break;
  6127. + case added:
  6128. + // method added, see if it is OK
  6129. + new_flags = (jushort) k_new_method->access_flags().get_flags();
  6130. + if ((new_flags & JVM_ACC_PRIVATE) == 0
  6131. + // hack: private should be treated as final, but alas
  6132. + || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  6133. + ) {
  6134. + // new methods must be private
  6135. + result = result | Klass::ModifyClass;
  6136. }
  6137. -
  6138. - if (VerifyMergedCPBytecodes) {
  6139. - // verify what we have done during constant pool merging
  6140. - {
  6141. - RedefineVerifyMark rvm(&the_class, &scratch_class, state);
  6142. - Verifier::verify(scratch_class, Verifier::ThrowException, true, THREAD);
  6143. + {
  6144. + u2 num = the_class->next_method_idnum();
  6145. + if (num == constMethodOopDesc::UNSET_IDNUM) {
  6146. + // cannot add any more methods
  6147. + result = result | Klass::ModifyClass;
  6148. }
  6149. -
  6150. - if (HAS_PENDING_EXCEPTION) {
  6151. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  6152. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  6153. - RC_TRACE_WITH_THREAD(0x00000002, THREAD,
  6154. - ("verify_byte_codes post merge-CP exception: '%s'",
  6155. - ex_name->as_C_string()));
  6156. - CLEAR_PENDING_EXCEPTION;
  6157. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  6158. - return JVMTI_ERROR_OUT_OF_MEMORY;
  6159. - } else {
  6160. - // tell the caller that constant pool merging screwed up
  6161. - return JVMTI_ERROR_INTERNAL;
  6162. + u2 new_num = k_new_method->method_idnum();
  6163. + methodOop idnum_owner = new_class->method_with_idnum(num);
  6164. + if (idnum_owner != NULL) {
  6165. + // There is already a method assigned this idnum -- switch them
  6166. + idnum_owner->set_method_idnum(new_num);
  6167. + }
  6168. + k_new_method->set_method_idnum(num);
  6169. + //swap_all_method_annotations(new_num, num, new_class);
  6170. + }
  6171. + RC_TRACE(0x00000001, ("Method added: new: %s [%d]",
  6172. + k_new_method->name_and_sig_as_C_string(), ni));
  6173. + ++ni; // advance to next new method
  6174. + break;
  6175. + case deleted:
  6176. + // method deleted, see if it is OK
  6177. + old_flags = (jushort) k_old_method->access_flags().get_flags();
  6178. + if ((old_flags & JVM_ACC_PRIVATE) == 0
  6179. + // hack: private should be treated as final, but alas
  6180. + || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  6181. + ) {
  6182. + // deleted methods must be private
  6183. + result = result | Klass::ModifyClass;
  6184. + }
  6185. + RC_TRACE(0x00000001, ("Method deleted: old: %s [%d]",
  6186. + k_old_method->name_and_sig_as_C_string(), oi));
  6187. + ++oi; // advance to next old method
  6188. + break;
  6189. + default:
  6190. + ShouldNotReachHere();
  6191. + }
  6192. + }
  6193. +
  6194. + if (new_class()->size() != new_class->old_version()->size()) {
  6195. + result |= Klass::ModifyClassSize;
  6196. + }
  6197. +
  6198. + if (new_class->size_helper() != ((instanceKlass*)(new_class->old_version()->klass_part()))->size_helper()) {
  6199. + result |= Klass::ModifyInstanceSize;
  6200. + }
  6201. +
  6202. + methodHandle instanceTransformerMethod(new_class->find_method(vmSymbols::transformer_name(), vmSymbols::void_method_signature()));
  6203. + if (!instanceTransformerMethod.is_null() && !instanceTransformerMethod->is_static()) {
  6204. + result |= Klass::HasInstanceTransformer;
  6205. + }
  6206. +
  6207. + // (tw) Check method bodies to be able to return NoChange?
  6208. + return result;
  6209. +}
  6210. +
  6211. +void VM_RedefineClasses::calculate_instance_update_information(klassOop new_version) {
  6212. +
  6213. + class UpdateFieldsEvolutionClosure : public FieldEvolutionClosure {
  6214. +
  6215. + private:
  6216. +
  6217. + GrowableArray<int> info;
  6218. + int curPosition;
  6219. + bool copy_backwards;
  6220. +
  6221. + public:
  6222. +
  6223. + bool does_copy_backwards() {
  6224. + return copy_backwards;
  6225. + }
  6226. +
  6227. + UpdateFieldsEvolutionClosure(klassOop klass) {
  6228. +
  6229. + int base_offset = instanceOopDesc::base_offset_in_bytes();
  6230. +
  6231. + if (klass->klass_part()->newest_version() == SystemDictionary::Reference_klass()->klass_part()->newest_version()) {
  6232. + base_offset += java_lang_ref_Reference::number_of_fake_oop_fields*size_of_type(T_OBJECT);
  6233. + }
  6234. +
  6235. + info.append(base_offset);
  6236. + info.append(0);
  6237. + curPosition = base_offset;
  6238. + copy_backwards = false;
  6239. + }
  6240. +
  6241. + GrowableArray<int> &finish() {
  6242. + info.append(0);
  6243. + return info;
  6244. + }
  6245. +
  6246. + virtual void do_new_field(fieldDescriptor* fd){
  6247. + int alignment = fd->offset() - curPosition;
  6248. + if (alignment > 0) {
  6249. + // This field was aligned, so we need to make sure that we fill the gap
  6250. + fill(alignment);
  6251. + }
  6252. +
  6253. + int size = size_of_type(fd->field_type());
  6254. + fill(size);
  6255. + }
  6256. +
  6257. + private:
  6258. +
  6259. + void fill(int size) {
  6260. + if (info.length() > 0 && info.at(info.length() - 1) < 0) {
  6261. + (*info.adr_at(info.length() - 1)) -= size;
  6262. + } else {
  6263. + info.append(-size);
  6264. + }
  6265. +
  6266. + curPosition += size;
  6267. + }
  6268. +
  6269. + int size_of_type(BasicType type) {
  6270. + int size = 0;
  6271. + switch(type) {
  6272. + case T_BOOLEAN:
  6273. + size = sizeof(jboolean);
  6274. + break;
  6275. +
  6276. + case T_CHAR:
  6277. + size = (sizeof(jchar));
  6278. + break;
  6279. +
  6280. + case T_FLOAT:
  6281. + size = (sizeof(jfloat));
  6282. + break;
  6283. +
  6284. + case T_DOUBLE:
  6285. + size = (sizeof(jdouble));
  6286. + break;
  6287. +
  6288. + case T_BYTE:
  6289. + size = (sizeof(jbyte));
  6290. + break;
  6291. +
  6292. + case T_SHORT:
  6293. + size = (sizeof(jshort));
  6294. + break;
  6295. +
  6296. + case T_INT:
  6297. + size = (sizeof(jint));
  6298. + break;
  6299. +
  6300. + case T_LONG:
  6301. + size = (sizeof(jlong));
  6302. + break;
  6303. +
  6304. + case T_OBJECT:
  6305. + case T_ARRAY:
  6306. + if (UseCompressedOops) {
  6307. + size = sizeof(narrowOop);
  6308. + } else {
  6309. + size = (sizeof(oop));
  6310. + }
  6311. + break;
  6312. +
  6313. + default:
  6314. + ShouldNotReachHere();
  6315. + }
  6316. +
  6317. + assert(size > 0, "");
  6318. + return size;
  6319. +
  6320. + }
  6321. +
  6322. + public:
  6323. +
  6324. + virtual void do_old_field(fieldDescriptor* fd){}
  6325. +
  6326. + virtual void do_changed_field(fieldDescriptor* old_fd, fieldDescriptor *new_fd){
  6327. +
  6328. + int alignment = new_fd->offset() - curPosition;
  6329. + if (alignment > 0) {
  6330. + // This field was aligned, so we need to make sure that we fill the gap
  6331. + fill(alignment);
  6332. + }
  6333. +
  6334. + assert(old_fd->field_type() == new_fd->field_type(), "");
  6335. + assert(curPosition == new_fd->offset(), "must be correct offset!");
  6336. +
  6337. + int offset = old_fd->offset();
  6338. + int size = size_of_type(old_fd->field_type());
  6339. +
  6340. + int prevEnd = -1;
  6341. + if (info.length() > 0 && info.at(info.length() - 1) > 0) {
  6342. + prevEnd = info.at(info.length() - 2) + info.at(info.length() - 1);
  6343. + }
  6344. +
  6345. + if (prevEnd == offset) {
  6346. + info.at_put(info.length() - 2, info.at(info.length() - 2) + size);
  6347. + } else {
  6348. + info.append(size);
  6349. + info.append(offset);
  6350. + }
  6351. +
  6352. + if (old_fd->offset() < new_fd->offset()) {
  6353. + copy_backwards = true;
  6354. + }
  6355. +
  6356. + transfer_special_access_flags(old_fd, new_fd);
  6357. +
  6358. + curPosition += size;
  6359. + }
  6360. + };
  6361. +
  6362. + UpdateFieldsEvolutionClosure cl(new_version);
  6363. + ((instanceKlass*)new_version->klass_part())->do_fields_evolution(&cl);
  6364. +
  6365. + GrowableArray<int> result = cl.finish();
  6366. + ((instanceKlass*)new_version->klass_part())->store_update_information(result);
  6367. + ((instanceKlass*)new_version->klass_part())->set_copying_backwards(cl.does_copy_backwards());
  6368. +
  6369. + if (RC_TRACE_ENABLED(0x00000002)) {
  6370. + RC_TRACE(0x00000002, ("Instance update information for %s:",
  6371. + new_version->klass_part()->name()->as_C_string()));
  6372. + if (cl.does_copy_backwards()) {
  6373. + RC_TRACE(0x00000002, ("\tDoes copy backwards!"));
  6374. + }
  6375. + for (int i=0; i<result.length(); i++) {
  6376. + int curNum = result.at(i);
  6377. + if (curNum < 0) {
  6378. + RC_TRACE(0x00000002, ("\t%d CLEAN", curNum));
  6379. + } else if (curNum > 0) {
  6380. + RC_TRACE(0x00000002, ("\t%d COPY from %d", curNum, result.at(i + 1)));
  6381. + i++;
  6382. + } else {
  6383. + RC_TRACE(0x00000002, ("\tEND"));
  6384. + }
  6385. + }
  6386. + }
  6387. +}
  6388. +
  6389. +Symbol* VM_RedefineClasses::signature_to_class_name(Symbol* signature) {
  6390. + assert(FieldType::is_obj(signature), "");
  6391. + return SymbolTable::new_symbol(signature->as_C_string() + 1, signature->utf8_length() - 2, Thread::current());
  6392. +}
  6393. +
  6394. +void VM_RedefineClasses::calculate_type_check_information(klassOop klass) {
  6395. + if (klass->klass_part()->is_redefining()) {
  6396. + klass = klass->klass_part()->old_version();
  6397. + }
  6398. +
  6399. + // We found an instance klass!
  6400. + instanceKlass *cur_instance_klass = instanceKlass::cast(klass);
  6401. + GrowableArray< Pair<int, klassOop> > type_check_information;
  6402. +
  6403. + class MyFieldClosure : public FieldClosure {
  6404. +
  6405. + public:
  6406. +
  6407. + GrowableArray< Pair<int, klassOop> > *_arr;
  6408. +
  6409. + MyFieldClosure(GrowableArray< Pair<int, klassOop> > *arr) {
  6410. + _arr = arr;
  6411. + }
  6412. +
  6413. + virtual void do_field(fieldDescriptor* fd) {
  6414. + if (fd->field_type() == T_OBJECT) {
  6415. + Symbol* signature = fd->signature();
  6416. + if (FieldType::is_obj(signature)) {
  6417. + Symbol* name = signature_to_class_name(signature);
  6418. + klassOop field_klass;
  6419. + if (is_field_dangerous(name, fd, field_klass)) {
  6420. + RC_TRACE(0x00000002, ("Found dangerous field %s in klass %s of type %s",
  6421. + fd->name()->as_C_string(),
  6422. + fd->field_holder()->klass_part()->name()->as_C_string(),
  6423. + name->as_C_string()));
  6424. + _arr->append(Pair<int, klassOop>(fd->offset(), field_klass->klass_part()->newest_version()));
  6425. + }
  6426. + }
  6427. +
  6428. + // Array fields can never be a problem!
  6429. + }
  6430. + }
  6431. +
  6432. + bool is_field_dangerous(Symbol* klass_name, fieldDescriptor *fd, klassOop &field_klass) {
  6433. + field_klass = SystemDictionary::find(klass_name, fd->field_holder()->klass_part()->class_loader(),
  6434. + fd->field_holder()->klass_part()->protection_domain(), Thread::current());
  6435. + if(field_klass != NULL) {
  6436. + if (field_klass->klass_part()->is_redefining()) {
  6437. + field_klass = field_klass->klass_part()->old_version();
  6438. + }
  6439. + if (field_klass->klass_part()->has_subtype_changed()) {
  6440. + return true;
  6441. + }
  6442. + }
  6443. + return false;
  6444. + }
  6445. + };
  6446. +
  6447. + MyFieldClosure fieldClosure(&type_check_information);
  6448. + cur_instance_klass->do_nonstatic_fields(&fieldClosure);
  6449. +
  6450. + if (type_check_information.length() > 0) {
  6451. + type_check_information.append(Pair<int, klassOop>(-1, NULL));
  6452. + cur_instance_klass->store_type_check_information(type_check_information);
  6453. + }
  6454. +}
  6455. +
  6456. +bool VM_RedefineClasses::check_field_value_types() {
  6457. +
  6458. + Thread *THREAD = Thread::current();
  6459. + class CheckFieldTypesClosure : public ObjectClosure {
  6460. +
  6461. + private:
  6462. +
  6463. + bool _result;
  6464. +
  6465. + public:
  6466. +
  6467. + CheckFieldTypesClosure() {
  6468. + _result = true;
  6469. + }
  6470. +
  6471. + bool result() { return _result; }
  6472. +
  6473. + virtual void do_object(oop obj) {
  6474. +
  6475. + if (!_result) {
  6476. + return;
  6477. + }
  6478. +
  6479. + if (obj->is_objArray()) {
  6480. +
  6481. + objArrayOop array = objArrayOop(obj);
  6482. +
  6483. + klassOop element_klass = objArrayKlass::cast(array->klass())->element_klass();
  6484. +
  6485. + if (element_klass->klass_part()->has_subtype_changed()) {
  6486. + int length = array->length();
  6487. + for (int i=0; i<length; i++) {
  6488. + oop element = array->obj_at(i);
  6489. + if (element != NULL && element->blueprint()->newest_version()->klass_part()->is_redefining()) {
  6490. + // Check subtype relationship to static type of array
  6491. + if (!element->blueprint()->newest_version()->klass_part()->is_subtype_of(element_klass->klass_part()->newest_version())) {
  6492. + RC_TRACE(0x00000001, ("Array value is INVALID - abort redefinition (static_type=%s, index=%d, dynamic_type=%s)",
  6493. + element_klass->klass_part()->name()->as_C_string(),
  6494. + i,
  6495. + element->blueprint()->name()->as_C_string()));
  6496. + _result = false;
  6497. + break;
  6498. + }
  6499. + }
  6500. + }
  6501. + }
  6502. +
  6503. + } else {
  6504. + Pair<int, klassOop> *cur = obj->klass()->klass_part()->type_check_information();
  6505. + if (cur != NULL) {
  6506. + // Type check information exists for this oop
  6507. + while ((*cur).left() != -1) {
  6508. + check_field(obj, (*cur).left(), (*cur).right());
  6509. + cur++;
  6510. + }
  6511. }
  6512. }
  6513. }
  6514. - Rewriter::rewrite(scratch_class, THREAD);
  6515. - if (!HAS_PENDING_EXCEPTION) {
  6516. - Rewriter::relocate_and_link(scratch_class, THREAD);
  6517. - }
  6518. - if (HAS_PENDING_EXCEPTION) {
  6519. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  6520. - CLEAR_PENDING_EXCEPTION;
  6521. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  6522. - return JVMTI_ERROR_OUT_OF_MEMORY;
  6523. - } else {
  6524. - return JVMTI_ERROR_INTERNAL;
  6525. - }
  6526. - }
  6527. -
  6528. - _scratch_classes[i] = scratch_class;
  6529. -
  6530. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  6531. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  6532. - ("loaded name=%s (avail_mem=" UINT64_FORMAT "K)",
  6533. - the_class->external_name(), os::available_memory() >> 10));
  6534. - }
  6535. -
  6536. - return JVMTI_ERROR_NONE;
  6537. -}
  6538. -
  6539. -
  6540. -// Map old_index to new_index as needed. scratch_cp is only needed
  6541. -// for RC_TRACE() calls.
  6542. -void VM_RedefineClasses::map_index(constantPoolHandle scratch_cp,
  6543. - int old_index, int new_index) {
  6544. - if (find_new_index(old_index) != 0) {
  6545. - // old_index is already mapped
  6546. - return;
  6547. - }
  6548. -
  6549. - if (old_index == new_index) {
  6550. - // no mapping is needed
  6551. - return;
  6552. - }
  6553. -
  6554. - _index_map_p->at_put(old_index, new_index);
  6555. - _index_map_count++;
  6556. -
  6557. - RC_TRACE(0x00040000, ("mapped tag %d at index %d to %d",
  6558. - scratch_cp->tag_at(old_index).value(), old_index, new_index));
  6559. -} // end map_index()
  6560. -
  6561. -
  6562. -// Merge old_cp and scratch_cp and return the results of the merge via
  6563. -// merge_cp_p. The number of entries in *merge_cp_p is returned via
  6564. -// merge_cp_length_p. The entries in old_cp occupy the same locations
  6565. -// in *merge_cp_p. Also creates a map of indices from entries in
  6566. -// scratch_cp to the corresponding entry in *merge_cp_p. Index map
  6567. -// entries are only created for entries in scratch_cp that occupy a
  6568. -// different location in *merged_cp_p.
  6569. -bool VM_RedefineClasses::merge_constant_pools(constantPoolHandle old_cp,
  6570. - constantPoolHandle scratch_cp, constantPoolHandle *merge_cp_p,
  6571. - int *merge_cp_length_p, TRAPS) {
  6572. -
  6573. - if (merge_cp_p == NULL) {
  6574. - assert(false, "caller must provide scatch constantPool");
  6575. - return false; // robustness
  6576. - }
  6577. - if (merge_cp_length_p == NULL) {
  6578. - assert(false, "caller must provide scatch CP length");
  6579. - return false; // robustness
  6580. - }
  6581. - // Worst case we need old_cp->length() + scratch_cp()->length(),
  6582. - // but the caller might be smart so make sure we have at least
  6583. - // the minimum.
  6584. - if ((*merge_cp_p)->length() < old_cp->length()) {
  6585. - assert(false, "merge area too small");
  6586. - return false; // robustness
  6587. - }
  6588. -
  6589. - RC_TRACE_WITH_THREAD(0x00010000, THREAD,
  6590. - ("old_cp_len=%d, scratch_cp_len=%d", old_cp->length(),
  6591. - scratch_cp->length()));
  6592. -
  6593. - {
  6594. - // Pass 0:
  6595. - // The old_cp is copied to *merge_cp_p; this means that any code
  6596. - // using old_cp does not have to change. This work looks like a
  6597. - // perfect fit for constantPoolOop::copy_cp_to(), but we need to
  6598. - // handle one special case:
  6599. - // - revert JVM_CONSTANT_Class to JVM_CONSTANT_UnresolvedClass
  6600. - // This will make verification happy.
  6601. -
  6602. - int old_i; // index into old_cp
  6603. -
  6604. - // index zero (0) is not used in constantPools
  6605. - for (old_i = 1; old_i < old_cp->length(); old_i++) {
  6606. - // leave debugging crumb
  6607. - jbyte old_tag = old_cp->tag_at(old_i).value();
  6608. - switch (old_tag) {
  6609. - case JVM_CONSTANT_Class:
  6610. - case JVM_CONSTANT_UnresolvedClass:
  6611. - // revert the copy to JVM_CONSTANT_UnresolvedClass
  6612. - // May be resolving while calling this so do the same for
  6613. - // JVM_CONSTANT_UnresolvedClass (klass_name_at() deals with transition)
  6614. - (*merge_cp_p)->unresolved_klass_at_put(old_i,
  6615. - old_cp->klass_name_at(old_i));
  6616. - break;
  6617. -
  6618. - case JVM_CONSTANT_Double:
  6619. - case JVM_CONSTANT_Long:
  6620. - // just copy the entry to *merge_cp_p, but double and long take
  6621. - // two constant pool entries
  6622. - constantPoolOopDesc::copy_entry_to(old_cp, old_i, *merge_cp_p, old_i, CHECK_0);
  6623. - old_i++;
  6624. - break;
  6625. -
  6626. - default:
  6627. - // just copy the entry to *merge_cp_p
  6628. - constantPoolOopDesc::copy_entry_to(old_cp, old_i, *merge_cp_p, old_i, CHECK_0);
  6629. - break;
  6630. - }
  6631. - } // end for each old_cp entry
  6632. -
  6633. - // We don't need to sanity check that *merge_cp_length_p is within
  6634. - // *merge_cp_p bounds since we have the minimum on-entry check above.
  6635. - (*merge_cp_length_p) = old_i;
  6636. - }
  6637. -
  6638. - // merge_cp_len should be the same as old_cp->length() at this point
  6639. - // so this trace message is really a "warm-and-breathing" message.
  6640. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  6641. - ("after pass 0: merge_cp_len=%d", *merge_cp_length_p));
  6642. -
  6643. - int scratch_i; // index into scratch_cp
  6644. - {
  6645. - // Pass 1a:
  6646. - // Compare scratch_cp entries to the old_cp entries that we have
  6647. - // already copied to *merge_cp_p. In this pass, we are eliminating
  6648. - // exact duplicates (matching entry at same index) so we only
  6649. - // compare entries in the common indice range.
  6650. - int increment = 1;
  6651. - int pass1a_length = MIN2(old_cp->length(), scratch_cp->length());
  6652. - for (scratch_i = 1; scratch_i < pass1a_length; scratch_i += increment) {
  6653. - switch (scratch_cp->tag_at(scratch_i).value()) {
  6654. - case JVM_CONSTANT_Double:
  6655. - case JVM_CONSTANT_Long:
  6656. - // double and long take two constant pool entries
  6657. - increment = 2;
  6658. - break;
  6659. -
  6660. - default:
  6661. - increment = 1;
  6662. - break;
  6663. - }
  6664. -
  6665. - bool match = scratch_cp->compare_entry_to(scratch_i, *merge_cp_p,
  6666. - scratch_i, CHECK_0);
  6667. - if (match) {
  6668. - // found a match at the same index so nothing more to do
  6669. - continue;
  6670. - } else if (is_unresolved_class_mismatch(scratch_cp, scratch_i,
  6671. - *merge_cp_p, scratch_i)) {
  6672. - // The mismatch in compare_entry_to() above is because of a
  6673. - // resolved versus unresolved class entry at the same index
  6674. - // with the same string value. Since Pass 0 reverted any
  6675. - // class entries to unresolved class entries in *merge_cp_p,
  6676. - // we go with the unresolved class entry.
  6677. - continue;
  6678. - } else if (is_unresolved_string_mismatch(scratch_cp, scratch_i,
  6679. - *merge_cp_p, scratch_i)) {
  6680. - // The mismatch in compare_entry_to() above is because of a
  6681. - // resolved versus unresolved string entry at the same index
  6682. - // with the same string value. We can live with whichever
  6683. - // happens to be at scratch_i in *merge_cp_p.
  6684. - continue;
  6685. - }
  6686. -
  6687. - int found_i = scratch_cp->find_matching_entry(scratch_i, *merge_cp_p,
  6688. - CHECK_0);
  6689. - if (found_i != 0) {
  6690. - guarantee(found_i != scratch_i,
  6691. - "compare_entry_to() and find_matching_entry() do not agree");
  6692. -
  6693. - // Found a matching entry somewhere else in *merge_cp_p so
  6694. - // just need a mapping entry.
  6695. - map_index(scratch_cp, scratch_i, found_i);
  6696. - continue;
  6697. - }
  6698. -
  6699. - // The find_matching_entry() call above could fail to find a match
  6700. - // due to a resolved versus unresolved class or string entry situation
  6701. - // like we solved above with the is_unresolved_*_mismatch() calls.
  6702. - // However, we would have to call is_unresolved_*_mismatch() over
  6703. - // all of *merge_cp_p (potentially) and that doesn't seem to be
  6704. - // worth the time.
  6705. -
  6706. - // No match found so we have to append this entry and any unique
  6707. - // referenced entries to *merge_cp_p.
  6708. - append_entry(scratch_cp, scratch_i, merge_cp_p, merge_cp_length_p,
  6709. - CHECK_0);
  6710. - }
  6711. - }
  6712. -
  6713. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  6714. - ("after pass 1a: merge_cp_len=%d, scratch_i=%d, index_map_len=%d",
  6715. - *merge_cp_length_p, scratch_i, _index_map_count));
  6716. -
  6717. - if (scratch_i < scratch_cp->length()) {
  6718. - // Pass 1b:
  6719. - // old_cp is smaller than scratch_cp so there are entries in
  6720. - // scratch_cp that we have not yet processed. We take care of
  6721. - // those now.
  6722. - int increment = 1;
  6723. - for (; scratch_i < scratch_cp->length(); scratch_i += increment) {
  6724. - switch (scratch_cp->tag_at(scratch_i).value()) {
  6725. - case JVM_CONSTANT_Double:
  6726. - case JVM_CONSTANT_Long:
  6727. - // double and long take two constant pool entries
  6728. - increment = 2;
  6729. - break;
  6730. -
  6731. - default:
  6732. - increment = 1;
  6733. - break;
  6734. - }
  6735. -
  6736. - int found_i =
  6737. - scratch_cp->find_matching_entry(scratch_i, *merge_cp_p, CHECK_0);
  6738. - if (found_i != 0) {
  6739. - // Found a matching entry somewhere else in *merge_cp_p so
  6740. - // just need a mapping entry.
  6741. - map_index(scratch_cp, scratch_i, found_i);
  6742. - continue;
  6743. - }
  6744. -
  6745. - // No match found so we have to append this entry and any unique
  6746. - // referenced entries to *merge_cp_p.
  6747. - append_entry(scratch_cp, scratch_i, merge_cp_p, merge_cp_length_p,
  6748. - CHECK_0);
  6749. - }
  6750. -
  6751. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  6752. - ("after pass 1b: merge_cp_len=%d, scratch_i=%d, index_map_len=%d",
  6753. - *merge_cp_length_p, scratch_i, _index_map_count));
  6754. - }
  6755. -
  6756. - return true;
  6757. -} // end merge_constant_pools()
  6758. -
  6759. -
  6760. -// Merge constant pools between the_class and scratch_class and
  6761. -// potentially rewrite bytecodes in scratch_class to use the merged
  6762. -// constant pool.
  6763. -jvmtiError VM_RedefineClasses::merge_cp_and_rewrite(
  6764. - instanceKlassHandle the_class, instanceKlassHandle scratch_class,
  6765. - TRAPS) {
  6766. - // worst case merged constant pool length is old and new combined
  6767. - int merge_cp_length = the_class->constants()->length()
  6768. - + scratch_class->constants()->length();
  6769. -
  6770. - constantPoolHandle old_cp(THREAD, the_class->constants());
  6771. - constantPoolHandle scratch_cp(THREAD, scratch_class->constants());
  6772. -
  6773. - // Constant pools are not easily reused so we allocate a new one
  6774. - // each time.
  6775. - // merge_cp is created unsafe for concurrent GC processing. It
  6776. - // should be marked safe before discarding it. Even though
  6777. - // garbage, if it crosses a card boundary, it may be scanned
  6778. - // in order to find the start of the first complete object on the card.
  6779. - constantPoolHandle merge_cp(THREAD,
  6780. - oopFactory::new_constantPool(merge_cp_length,
  6781. - oopDesc::IsUnsafeConc,
  6782. - THREAD));
  6783. - int orig_length = old_cp->orig_length();
  6784. - if (orig_length == 0) {
  6785. - // This old_cp is an actual original constant pool. We save
  6786. - // the original length in the merged constant pool so that
  6787. - // merge_constant_pools() can be more efficient. If a constant
  6788. - // pool has a non-zero orig_length() value, then that constant
  6789. - // pool was created by a merge operation in RedefineClasses.
  6790. - merge_cp->set_orig_length(old_cp->length());
  6791. - } else {
  6792. - // This old_cp is a merged constant pool from a previous
  6793. - // RedefineClasses() calls so just copy the orig_length()
  6794. - // value.
  6795. - merge_cp->set_orig_length(old_cp->orig_length());
  6796. - }
  6797. -
  6798. - ResourceMark rm(THREAD);
  6799. - _index_map_count = 0;
  6800. - _index_map_p = new intArray(scratch_cp->length(), -1);
  6801. -
  6802. - bool result = merge_constant_pools(old_cp, scratch_cp, &merge_cp,
  6803. - &merge_cp_length, THREAD);
  6804. - if (!result) {
  6805. - // The merge can fail due to memory allocation failure or due
  6806. - // to robustness checks.
  6807. - return JVMTI_ERROR_INTERNAL;
  6808. - }
  6809. -
  6810. - RC_TRACE_WITH_THREAD(0x00010000, THREAD,
  6811. - ("merge_cp_len=%d, index_map_len=%d", merge_cp_length, _index_map_count));
  6812. -
  6813. - if (_index_map_count == 0) {
  6814. - // there is nothing to map between the new and merged constant pools
  6815. -
  6816. - if (old_cp->length() == scratch_cp->length()) {
  6817. - // The old and new constant pools are the same length and the
  6818. - // index map is empty. This means that the three constant pools
  6819. - // are equivalent (but not the same). Unfortunately, the new
  6820. - // constant pool has not gone through link resolution nor have
  6821. - // the new class bytecodes gone through constant pool cache
  6822. - // rewriting so we can't use the old constant pool with the new
  6823. - // class.
  6824. -
  6825. - merge_cp()->set_is_conc_safe(true);
  6826. - merge_cp = constantPoolHandle(); // toss the merged constant pool
  6827. - } else if (old_cp->length() < scratch_cp->length()) {
  6828. - // The old constant pool has fewer entries than the new constant
  6829. - // pool and the index map is empty. This means the new constant
  6830. - // pool is a superset of the old constant pool. However, the old
  6831. - // class bytecodes have already gone through constant pool cache
  6832. - // rewriting so we can't use the new constant pool with the old
  6833. - // class.
  6834. -
  6835. - merge_cp()->set_is_conc_safe(true);
  6836. - merge_cp = constantPoolHandle(); // toss the merged constant pool
  6837. - } else {
  6838. - // The old constant pool has more entries than the new constant
  6839. - // pool and the index map is empty. This means that both the old
  6840. - // and merged constant pools are supersets of the new constant
  6841. - // pool.
  6842. -
  6843. - // Replace the new constant pool with a shrunken copy of the
  6844. - // merged constant pool; the previous new constant pool will
  6845. - // get GCed.
  6846. - set_new_constant_pool(scratch_class, merge_cp, merge_cp_length, true,
  6847. - THREAD);
  6848. - // drop local ref to the merged constant pool
  6849. - merge_cp()->set_is_conc_safe(true);
  6850. - merge_cp = constantPoolHandle();
  6851. - }
  6852. - } else {
  6853. - if (RC_TRACE_ENABLED(0x00040000)) {
  6854. - // don't want to loop unless we are tracing
  6855. - int count = 0;
  6856. - for (int i = 1; i < _index_map_p->length(); i++) {
  6857. - int value = _index_map_p->at(i);
  6858. -
  6859. - if (value != -1) {
  6860. - RC_TRACE_WITH_THREAD(0x00040000, THREAD,
  6861. - ("index_map[%d]: old=%d new=%d", count, i, value));
  6862. - count++;
  6863. + void check_field(oop obj, int offset, klassOop static_type) {
  6864. + oop field_value = obj->obj_field(offset);
  6865. + if (field_value != NULL) {
  6866. + // Field is not null
  6867. + if (field_value->klass()->klass_part()->newest_version()->klass_part()->is_subtype_of(static_type)) {
  6868. + // We are OK
  6869. + RC_TRACE(0x00008000, ("Field value is OK (klass=%s, static_type=%s, offset=%d, dynamic_type=%s)",
  6870. + obj->klass()->klass_part()->name()->as_C_string(),
  6871. + static_type->klass_part()->name()->as_C_string(),
  6872. + offset,
  6873. + field_value->klass()->klass_part()->name()->as_C_string()));
  6874. + } else {
  6875. + // Failure!
  6876. + RC_TRACE(0x00000001, ("Field value is INVALID - abort redefinition (klass=%s, static_type=%s, offset=%d, dynamic_type=%s)",
  6877. + obj->klass()->klass_part()->name()->as_C_string(),
  6878. + static_type->klass_part()->name()->as_C_string(),
  6879. + offset,
  6880. + field_value->klass()->klass_part()->name()->as_C_string()));
  6881. + _result = false;
  6882. }
  6883. }
  6884. }
  6885. -
  6886. - // We have entries mapped between the new and merged constant pools
  6887. - // so we have to rewrite some constant pool references.
  6888. - if (!rewrite_cp_refs(scratch_class, THREAD)) {
  6889. - return JVMTI_ERROR_INTERNAL;
  6890. + };
  6891. +
  6892. + CheckFieldTypesClosure myObjectClosure;
  6893. +
  6894. + // make sure that heap is parsable (fills TLABs with filler objects)
  6895. + Universe::heap()->ensure_parsability(false); // no need to retire TLABs
  6896. +
  6897. + // do the iteration
  6898. + // If this operation encounters a bad object when using CMS,
  6899. + // consider using safe_object_iterate() which avoids perm gen
  6900. + // objects that may contain bad references.
  6901. + Universe::heap()->object_iterate(&myObjectClosure);
  6902. +
  6903. + // when sharing is enabled we must iterate over the shared spaces
  6904. + if (UseSharedSpaces) {
  6905. + GenCollectedHeap* gch = GenCollectedHeap::heap();
  6906. + CompactingPermGenGen* gen = (CompactingPermGenGen*)gch->perm_gen();
  6907. + gen->ro_space()->object_iterate(&myObjectClosure);
  6908. + gen->rw_space()->object_iterate(&myObjectClosure);
  6909. + }
  6910. +
  6911. + return myObjectClosure.result();
  6912. +}
  6913. +
  6914. +void VM_RedefineClasses::clear_type_check_information(klassOop k) {
  6915. + if (k->klass_part()->is_redefining()) {
  6916. + k = k->klass_part()->old_version();
  6917. + }
  6918. +
  6919. + // We found an instance klass!
  6920. + instanceKlass *cur_instance_klass = instanceKlass::cast(k);
  6921. + cur_instance_klass->clear_type_check_information();
  6922. +}
  6923. +
  6924. +void VM_RedefineClasses::update_active_methods() {
  6925. +
  6926. + RC_TRACE(0x00000002, ("Updating active methods"));
  6927. + JavaThread *java_thread = Threads::first();
  6928. + while (java_thread != NULL) {
  6929. +
  6930. + int stack_depth = 0;
  6931. + if (java_thread->has_last_Java_frame()) {
  6932. +
  6933. + RC_TRACE(0x0000000400, ("checking stack of Java thread %s", java_thread->name()));
  6934. +
  6935. + // vframes are resource allocated
  6936. + Thread* current_thread = Thread::current();
  6937. + ResourceMark rm(current_thread);
  6938. + HandleMark hm(current_thread);
  6939. +
  6940. + RegisterMap reg_map(java_thread);
  6941. + frame f = java_thread->last_frame();
  6942. + vframe* vf = vframe::new_vframe(&f, &reg_map, java_thread);
  6943. + frame* last_entry_frame = NULL;
  6944. +
  6945. + while (vf != NULL) {
  6946. + if (vf->is_java_frame()) {
  6947. + // java frame (interpreted, compiled, ...)
  6948. + javaVFrame *jvf = javaVFrame::cast(vf);
  6949. +
  6950. + if (!(jvf->method()->is_native())) {
  6951. + int bci = jvf->bci();
  6952. + RC_TRACE(0x00000400, ("found method: %s / bci=%d", jvf->method()->name()->as_C_string(), bci));
  6953. + ResourceMark rm(Thread::current());
  6954. + HandleMark hm;
  6955. + instanceKlassHandle klass(jvf->method()->method_holder());
  6956. +
  6957. + if (jvf->method()->new_version() != NULL && jvf->is_interpreted_frame()) {
  6958. +
  6959. +
  6960. + RC_TRACE(0x00000002, ("Found method that should just be updated to the newest version %s",
  6961. + jvf->method()->name_and_sig_as_C_string()));
  6962. +
  6963. + if (RC_TRACE_ENABLED(0x01000000)) {
  6964. + int code_size = jvf->method()->code_size();
  6965. + char *code_base_old = (char*)jvf->method()->code_base();
  6966. + char *code_base_new = (char*)jvf->method()->new_version()->code_base();
  6967. + for (int i=0; i<code_size; i++) {
  6968. + tty->print_cr("old=%d new=%d", *code_base_old++, *code_base_new++);
  6969. + }
  6970. + jvf->method()->print_codes_on(tty);
  6971. + jvf->method()->new_version()->print_codes_on(tty);
  6972. + }
  6973. +
  6974. + assert(jvf->is_interpreted_frame(), "Every frame must be interpreted!");
  6975. + interpretedVFrame *iframe = (interpretedVFrame *)jvf;
  6976. +
  6977. +
  6978. + if (RC_TRACE_ENABLED(0x01000000)) {
  6979. + constantPoolCacheOop cp_old = jvf->method()->constants()->cache();
  6980. + tty->print_cr("old cp");
  6981. + for (int i=0; i<cp_old->length(); i++) {
  6982. + cp_old->entry_at(i)->print(tty, i);
  6983. + }
  6984. + constantPoolCacheOop cp_new = jvf->method()->new_version()->constants()->cache();
  6985. + tty->print_cr("new cp");
  6986. + for (int i=0; i<cp_new->length(); i++) {
  6987. + cp_new->entry_at(i)->print(tty, i);
  6988. + }
  6989. + }
  6990. +
  6991. + iframe->set_method(jvf->method()->new_version(), bci);
  6992. + RC_TRACE(0x00000002, ("Updated method to newer version"));
  6993. + assert(jvf->method()->new_version() == NULL, "must be latest version");
  6994. +
  6995. + }
  6996. + }
  6997. + }
  6998. + vf = vf->sender();
  6999. + }
  7000. }
  7001. - // Replace the new constant pool with a shrunken copy of the
  7002. - // merged constant pool so now the rewritten bytecodes have
  7003. - // valid references; the previous new constant pool will get
  7004. - // GCed.
  7005. - set_new_constant_pool(scratch_class, merge_cp, merge_cp_length, true,
  7006. - THREAD);
  7007. - merge_cp()->set_is_conc_safe(true);
  7008. + // Advance to next thread
  7009. + java_thread = java_thread->next();
  7010. }
  7011. - assert(old_cp()->is_conc_safe(), "Just checking");
  7012. - assert(scratch_cp()->is_conc_safe(), "Just checking");
  7013. -
  7014. - return JVMTI_ERROR_NONE;
  7015. -} // end merge_cp_and_rewrite()
  7016. -
  7017. -
  7018. -// Rewrite constant pool references in klass scratch_class.
  7019. -bool VM_RedefineClasses::rewrite_cp_refs(instanceKlassHandle scratch_class,
  7020. - TRAPS) {
  7021. -
  7022. - // rewrite constant pool references in the methods:
  7023. - if (!rewrite_cp_refs_in_methods(scratch_class, THREAD)) {
  7024. - // propagate failure back to caller
  7025. +}
  7026. +
  7027. +void VM_RedefineClasses::method_forwarding() {
  7028. +
  7029. + int forwarding_count = 0;
  7030. + JavaThread *java_thread = Threads::first();
  7031. + while (java_thread != NULL) {
  7032. +
  7033. + int stack_depth = 0;
  7034. + if (java_thread->has_last_Java_frame()) {
  7035. +
  7036. + RC_TRACE(0x00000400, ("checking stack of Java thread %s", java_thread->name()));
  7037. +
  7038. + // vframes are resource allocated
  7039. + Thread* current_thread = Thread::current();
  7040. + ResourceMark rm(current_thread);
  7041. + HandleMark hm(current_thread);
  7042. +
  7043. + RegisterMap reg_map(java_thread);
  7044. + frame f = java_thread->last_frame();
  7045. + vframe* vf = vframe::new_vframe(&f, &reg_map, java_thread);
  7046. + frame* last_entry_frame = NULL;
  7047. +
  7048. + while (vf != NULL) {
  7049. + if (vf->is_java_frame()) {
  7050. + // java frame (interpreted, compiled, ...)
  7051. + javaVFrame *jvf = javaVFrame::cast(vf);
  7052. +
  7053. + if (!(jvf->method()->is_native())) {
  7054. + RC_TRACE(0x00008000, ("found method: %s",
  7055. + jvf->method()->name()->as_C_string()));
  7056. + ResourceMark rm(Thread::current());
  7057. + HandleMark hm;
  7058. + instanceKlassHandle klass(jvf->method()->method_holder());
  7059. + methodOop m = jvf->method();
  7060. + int bci = jvf->bci();
  7061. + RC_TRACE(0x00008000, ("klass redef %d",
  7062. + klass->is_redefining()));
  7063. +
  7064. + if (klass->new_version() != NULL && m->new_version() == NULL) {
  7065. + RC_TRACE(0x00008000, ("found potential forwarding method: %s",
  7066. + m->name()->as_C_string()));
  7067. +
  7068. + klassOop new_klass = klass->newest_version();
  7069. + methodOop new_method = new_klass->klass_part()->lookup_method(m->name(), m->signature());
  7070. + RC_TRACE(0x00000002, ("%d %d",
  7071. + new_method,
  7072. + new_method->constMethod()->has_code_section_table()));
  7073. +
  7074. + if (new_method != NULL && new_method->constMethod()->has_code_section_table()) {
  7075. + RC_TRACE(0x00008000, ("found code section table for method: %s",
  7076. + new_method->name()->as_C_string()));
  7077. + m->set_forward_method(new_method);
  7078. + if (new_method->max_locals() != m->max_locals()) {
  7079. + tty->print_cr("new_m max locals: %d old_m max locals: %d", new_method->max_locals(), m->max_locals());
  7080. + }
  7081. + assert(new_method->max_locals() == m->max_locals(), "number of locals must match");
  7082. + assert(new_method->max_stack() == m->max_stack(), "number of stack values must match");
  7083. + if (jvf->is_interpreted_frame()) {
  7084. + if (m->is_in_code_section(bci)) {
  7085. + // We must transfer now and cannot delay until next NOP.
  7086. + int new_bci = m->calculate_forward_bci(bci, new_method);
  7087. + interpretedVFrame* iframe = interpretedVFrame::cast(jvf);
  7088. + RC_TRACE(0x00000002, ("Transferring execution of %s to new method old_bci=%d new_bci=%d",
  7089. + new_method->name()->as_C_string(),
  7090. + bci,
  7091. + new_bci));
  7092. + iframe->set_method(new_method, new_bci);
  7093. + } else {
  7094. + RC_TRACE(0x00000002, ("Delaying method forwarding of %s because %d is not in a code section",
  7095. + new_method->name()->as_C_string(),
  7096. + bci));
  7097. + }
  7098. + } else {
  7099. + RC_TRACE(0x00000002, ("Delaying method forwarding of %s because method is compiled",
  7100. + new_method->name()->as_C_string()));
  7101. + }
  7102. + }
  7103. + }
  7104. + }
  7105. + }
  7106. + vf = vf->sender();
  7107. + }
  7108. + }
  7109. +
  7110. + // Advance to next thread
  7111. + java_thread = java_thread->next();
  7112. + }
  7113. +
  7114. + RC_TRACE(0x00000001, ("Method forwarding applied to %d methods",
  7115. + forwarding_count));
  7116. +}
  7117. +
  7118. +bool VM_RedefineClasses::check_method_stacks() {
  7119. +
  7120. + JavaThread *java_thread = Threads::first();
  7121. + while (java_thread != NULL) {
  7122. +
  7123. + int stack_depth = 0;
  7124. + if (java_thread->has_last_Java_frame()) {
  7125. +
  7126. + RC_TRACE(0x00000400, ("checking stack of Java thread %s", java_thread->name()));
  7127. +
  7128. + // vframes are resource allocated
  7129. + Thread* current_thread = Thread::current();
  7130. + ResourceMark rm(current_thread);
  7131. + HandleMark hm(current_thread);
  7132. +
  7133. + RegisterMap reg_map(java_thread);
  7134. + frame f = java_thread->last_frame();
  7135. + vframe* vf = vframe::new_vframe(&f, &reg_map, java_thread);
  7136. + frame* last_entry_frame = NULL;
  7137. +
  7138. + while (vf != NULL) {
  7139. + if (vf->is_java_frame()) {
  7140. + // java frame (interpreted, compiled, ...)
  7141. + javaVFrame *jvf = javaVFrame::cast(vf);
  7142. +
  7143. + if (!(jvf->method()->is_native())) {
  7144. + RC_TRACE(0x00000400, ("found method: %s", jvf->method()->name()->as_C_string()));
  7145. + ResourceMark rm(Thread::current());
  7146. + HandleMark hm;
  7147. + instanceKlassHandle klass(jvf->method()->method_holder());
  7148. +
  7149. + StackValueCollection *locals = jvf->locals();
  7150. + const size_t message_buffer_len = klass->name()->utf8_length() + 1024;
  7151. + char* message_buffer = NEW_RESOURCE_ARRAY(char, message_buffer_len);
  7152. +
  7153. + for (int i=0; i<locals->size(); i++) {
  7154. + StackValue *stack_value = locals->at(i);
  7155. + if (stack_value->type() == T_OBJECT) {
  7156. + Handle obj = stack_value->get_obj();
  7157. + if (!obj.is_null() && obj->klass()->klass_part()->newest_version()->klass_part()->check_redefinition_flag(Klass::RemoveSuperType)) {
  7158. +
  7159. + // OK, so this is a possible failure => check local variable table, if it could be OK.
  7160. + bool result = false;
  7161. + methodOop method = jvf->method();
  7162. + if (method->has_localvariable_table()) {
  7163. + LocalVariableTableElement *elem = jvf->method()->localvariable_table_start();
  7164. + for (int j=0; j<method->localvariable_table_length(); j++) {
  7165. +
  7166. + if (elem->slot == i) {
  7167. +
  7168. + // Matching index found
  7169. +
  7170. + if (elem->start_bci <= jvf->bci() && elem->start_bci + elem->length > jvf->bci()) {
  7171. +
  7172. + // Also in range!!
  7173. + Symbol* signature = jvf->method()->constants()->symbol_at(elem->descriptor_cp_index);
  7174. + Symbol* klass_name = signature_to_class_name(signature);
  7175. +
  7176. + 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();
  7177. + klassOop cur = obj->klass()->klass_part()->newest_version();
  7178. +
  7179. + // Field is not null
  7180. + if (cur->klass_part()->newest_version()->klass_part()->is_subtype_of(local_klass)) {
  7181. + // We are OK
  7182. + RC_TRACE(0x00008000, ("Local variable value is OK (local_klass=%s, cur_klass=%s)",
  7183. + local_klass->klass_part()->name()->as_C_string(), cur->klass_part()->name()->as_C_string()));
  7184. + result = true;
  7185. + } else {
  7186. + // Failure!
  7187. + RC_TRACE(0x00000001, ("Local variable value is INVALID - abort redefinition (local_klass=%s, cur_klass=%s)",
  7188. + local_klass->klass_part()->name()->as_C_string(),
  7189. + cur->klass_part()->name()->as_C_string()));
  7190. + return false;
  7191. + }
  7192. + }
  7193. + }
  7194. +
  7195. + elem++;
  7196. + }
  7197. + } else {
  7198. + RC_TRACE(0x00000002, ("Method %s does not have a local variable table => abort",
  7199. + method->name_and_sig_as_C_string()));
  7200. + }
  7201. +
  7202. + if (!result) {
  7203. + return false;
  7204. + }
  7205. +
  7206. + RC_TRACE(0x00008000, ("Verifying class %s",
  7207. + jvf->method()->method_holder()->klass_part()->name()->as_C_string()));
  7208. +
  7209. + Symbol* exception_name;
  7210. + const size_t message_buffer_len = klass->name()->utf8_length() + 1024;
  7211. + char* message_buffer = NEW_RESOURCE_ARRAY(char, message_buffer_len);
  7212. +
  7213. + Thread::current()->set_pretend_new_universe(true);
  7214. + ClassVerifier split_verifier(klass, Thread::current());
  7215. + split_verifier.verify_method(jvf->method(), Thread::current());
  7216. + exception_name = split_verifier.result();
  7217. + Thread::current()->set_pretend_new_universe(false);
  7218. +
  7219. + if (exception_name != NULL) {
  7220. +
  7221. + RC_TRACE(0x00000001, ("Verification of class %s failed",
  7222. + jvf->method()->method_holder()->klass_part()->name()->as_C_string()));
  7223. + RC_TRACE(0x00000001, ("Exception: %s",
  7224. + exception_name->as_C_string()));
  7225. + RC_TRACE(0x00000001, ("Message: %s",
  7226. + message_buffer));
  7227. + Thread::current()->clear_pending_exception();
  7228. + return false;
  7229. + }
  7230. +
  7231. + }
  7232. + }
  7233. + }
  7234. + }
  7235. + }
  7236. + vf = vf->sender();
  7237. + }
  7238. + }
  7239. +
  7240. + // Advance to next thread
  7241. + java_thread = java_thread->next();
  7242. + }
  7243. +
  7244. + return true;
  7245. +}
  7246. +
  7247. +bool VM_RedefineClasses::check_method(methodOop method) {
  7248. +
  7249. +
  7250. + return true;
  7251. +}
  7252. +
  7253. +// Warning: destroys redefinition level values of klasses.
  7254. +bool VM_RedefineClasses::check_loaded_methods() {
  7255. +
  7256. + class CheckLoadedMethodsClosure : public ObjectClosure {
  7257. +
  7258. + private:
  7259. +
  7260. + bool _result;
  7261. + GrowableArray<klassOop> *_dangerous_klasses;
  7262. +
  7263. + public:
  7264. + CheckLoadedMethodsClosure(GrowableArray<klassOop> *dangerous_klasses) {
  7265. + _result = true;
  7266. + _dangerous_klasses = dangerous_klasses;
  7267. + }
  7268. +
  7269. + bool result() {
  7270. + return _result;
  7271. + }
  7272. +
  7273. + bool is_class_dangerous(klassOop k) {
  7274. + return k->klass_part()->newest_version()->klass_part()->check_redefinition_flag(Klass::RemoveSuperType);
  7275. + }
  7276. +
  7277. + bool can_be_affected(instanceKlass *klass) {
  7278. +
  7279. + constantPoolOop cp = klass->constants();
  7280. +
  7281. + Thread *THREAD = Thread::current();
  7282. + klassOop k;
  7283. + Symbol* symbol;
  7284. +
  7285. + for (int i=1; i<cp->length(); i++) {
  7286. + jbyte tag = cp->tag_at(i).value();
  7287. + switch(tag) {
  7288. + case JVM_CONSTANT_Long:
  7289. + case JVM_CONSTANT_Double:
  7290. + i++;
  7291. + break;
  7292. +
  7293. + case JVM_CONSTANT_Utf8:
  7294. + case JVM_CONSTANT_Unicode:
  7295. + case JVM_CONSTANT_Integer:
  7296. + case JVM_CONSTANT_Float:
  7297. + case JVM_CONSTANT_String:
  7298. + case JVM_CONSTANT_Fieldref:
  7299. + case JVM_CONSTANT_Methodref:
  7300. + case JVM_CONSTANT_InterfaceMethodref:
  7301. + case JVM_CONSTANT_ClassIndex:
  7302. + case JVM_CONSTANT_UnresolvedString:
  7303. + case JVM_CONSTANT_StringIndex:
  7304. + case JVM_CONSTANT_UnresolvedClassInError:
  7305. + case JVM_CONSTANT_Object:
  7306. + // do nothing
  7307. + break;
  7308. +
  7309. + case JVM_CONSTANT_Class:
  7310. + k = cp->klass_at(i, CHECK_(true));
  7311. + if (is_class_dangerous(k)) {
  7312. + RC_TRACE(0x00000002, ("Class %s is potentially affected, because at cp[%d] references class %s",
  7313. + klass->name()->as_C_string(),
  7314. + i,
  7315. + k->klass_part()->name()->as_C_string()));
  7316. + return true;
  7317. + }
  7318. + break;
  7319. +
  7320. + case JVM_CONSTANT_NameAndType:
  7321. + symbol = cp->symbol_at(cp->signature_ref_index_at(i));
  7322. + if (symbol->byte_at(0) == '(') {
  7323. + // This must be a method
  7324. + SignatureStream signatureStream(symbol);
  7325. + while (true) {
  7326. +
  7327. + if (signatureStream.is_array()) {
  7328. + Symbol* cur_signature = signatureStream.as_symbol(Thread::current());
  7329. + if (is_type_signature_dangerous(cur_signature)) {
  7330. + return true;
  7331. + }
  7332. + } else if (signatureStream.is_object()) {
  7333. + if (is_symbol_dangerous(signatureStream.as_symbol(Thread::current()))) {
  7334. + return true;
  7335. + }
  7336. + }
  7337. +
  7338. + if (signatureStream.at_return_type()) {
  7339. + break;
  7340. + }
  7341. +
  7342. + signatureStream.next();
  7343. + }
  7344. +
  7345. + } else if (is_type_signature_dangerous(symbol)) {
  7346. + return true;
  7347. + }
  7348. + break;
  7349. +
  7350. + case JVM_CONSTANT_UnresolvedClass:
  7351. + symbol = cp->unresolved_klass_at(i);
  7352. + if (is_symbol_dangerous(symbol)) {
  7353. + return true;
  7354. + }
  7355. + break;
  7356. +
  7357. + default:
  7358. + ShouldNotReachHere();
  7359. + }
  7360. + }
  7361. +
  7362. + return false;
  7363. + }
  7364. +
  7365. + bool is_type_signature_dangerous(Symbol* signature) {
  7366. + // This must be a field type
  7367. + if (FieldType::is_obj(signature)) {
  7368. + Symbol* name = signature_to_class_name(signature);
  7369. + if (is_symbol_dangerous(name)) {
  7370. + return true;
  7371. + }
  7372. + } else if (FieldType::is_array(signature)) {
  7373. + //jint dimension;
  7374. + //Symbol* object_key;
  7375. + FieldArrayInfo fd;
  7376. + FieldType::get_array_info(signature, fd, Thread::current());
  7377. + if (is_symbol_dangerous(fd.object_key())) {
  7378. + return true;
  7379. + }
  7380. + }
  7381. + return false;
  7382. + }
  7383. +
  7384. + bool is_symbol_dangerous(Symbol* symbol) {
  7385. + for (int i=0; i<_dangerous_klasses->length(); i++) {
  7386. + if(_dangerous_klasses->at(i)->klass_part()->name() == symbol) {
  7387. + RC_TRACE(0x00000002, ("Found constant pool index %d references class %s",
  7388. + i,
  7389. + symbol->as_C_string()));
  7390. + return true;
  7391. + }
  7392. + }
  7393. + return false;
  7394. + }
  7395. +
  7396. + virtual void do_object(oop obj) {
  7397. +
  7398. + if (!_result) return;
  7399. +
  7400. + klassOop klassObj = (klassOop)obj;
  7401. + Thread *THREAD = Thread::current();
  7402. +
  7403. + // We found an instance klass!
  7404. + instanceKlass *klass = instanceKlass::cast(klassObj);
  7405. + instanceKlassHandle handle(klassObj);
  7406. +
  7407. + RC_TRACE(0x00000400, ("Check if verification is necessary for class %s major_version=%d", handle->name()->as_C_string(), handle->major_version()));
  7408. +
  7409. + if (!can_be_affected(klass)) {
  7410. + RC_TRACE(0x00000400, ("Skipping verification of class %s major_version=%d", handle->name()->as_C_string(), handle->major_version()));
  7411. + return;
  7412. + }
  7413. +
  7414. + if (handle->major_version() < Verifier::STACKMAP_ATTRIBUTE_MAJOR_VERSION) {
  7415. + RC_TRACE(0x00000001, ("Failing because cannot verify class %s major_version=%d", handle->name()->as_C_string(), handle->major_version()));
  7416. + _result = false;
  7417. + return;
  7418. + }
  7419. +
  7420. + RC_TRACE(0x00000001, ("Verifying class %s", handle->name()->as_C_string()));
  7421. +
  7422. + if (!Verifier::verify(handle, Verifier::NoException, true, false, Thread::current())) {
  7423. +
  7424. + RC_TRACE(0x00000001, ("Verification of class %s failed", handle->name()->as_C_string()));
  7425. + //Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  7426. + //RC_TRACE(0x00000002, ("exception when verifying class: '%s'", ex_name->as_C_string());
  7427. + //PENDING_EXCEPTION->print();
  7428. + CLEAR_PENDING_EXCEPTION;
  7429. + _result = false;
  7430. + }
  7431. +
  7432. + /*int method_count = klass->methods()->length();
  7433. + for (int i=0; i<method_count; i++) {
  7434. + methodOop cur_method = (methodOop)klass->methods()->obj_at(i);
  7435. + if (!check_method(cur_method)) {
  7436. + RC_TRACE(0x00000001, ("Failed to verify consistency of method %s of klass %s", cur_method->name()->as_C_string(), klass->name()->as_C_string());
  7437. + }
  7438. + }*/
  7439. + }
  7440. + };
  7441. +
  7442. + // TODO: Check bytecodes in case of interface => class or class => interface etc..
  7443. +
  7444. + GrowableArray<klassOop> dangerous_klasses;
  7445. + for (int i=0; i<_new_classes->length(); i++) {
  7446. + instanceKlassHandle handle = _new_classes->at(i);
  7447. + if (handle->check_redefinition_flag(Klass::RemoveSuperType)) {
  7448. + dangerous_klasses.append(handle());
  7449. + }
  7450. + }
  7451. +
  7452. + CheckLoadedMethodsClosure checkLoadedMethodsClosure(&dangerous_klasses);
  7453. + Thread::current()->set_pretend_new_universe(true);
  7454. + SystemDictionary::classes_do(&checkLoadedMethodsClosure);
  7455. + Thread::current()->set_pretend_new_universe(false);
  7456. +
  7457. +
  7458. + return checkLoadedMethodsClosure.result();
  7459. +}
  7460. +
  7461. +bool VM_RedefineClasses::check_type_consistency() {
  7462. +
  7463. + Universe::set_verify_in_progress(true);
  7464. +
  7465. + SystemDictionary::classes_do(calculate_type_check_information);
  7466. + bool result = check_field_value_types();
  7467. + SystemDictionary::classes_do(clear_type_check_information);
  7468. + if (!result) {
  7469. + RC_TRACE(0x00000001, ("Aborting redefinition because of wrong field or array element value!"));
  7470. + Universe::set_verify_in_progress(false);
  7471. return false;
  7472. }
  7473. - // rewrite constant pool references in the class_annotations:
  7474. - if (!rewrite_cp_refs_in_class_annotations(scratch_class, THREAD)) {
  7475. - // propagate failure back to caller
  7476. + result = check_method_stacks();
  7477. + if (!result) {
  7478. + RC_TRACE(0x00000001, ("Aborting redefinition because of wrong value on the stack"));
  7479. + Universe::set_verify_in_progress(false);
  7480. return false;
  7481. }
  7482. - // rewrite constant pool references in the fields_annotations:
  7483. - if (!rewrite_cp_refs_in_fields_annotations(scratch_class, THREAD)) {
  7484. - // propagate failure back to caller
  7485. + result = check_loaded_methods();
  7486. + if (!result) {
  7487. + RC_TRACE(0x00000001, ("Aborting redefinition because of wrong loaded method"));
  7488. + Universe::set_verify_in_progress(false);
  7489. return false;
  7490. }
  7491. - // rewrite constant pool references in the methods_annotations:
  7492. - if (!rewrite_cp_refs_in_methods_annotations(scratch_class, THREAD)) {
  7493. - // propagate failure back to caller
  7494. + RC_TRACE(0x00000001, ("Verification passed => hierarchy change is valid!"));
  7495. + Universe::set_verify_in_progress(false);
  7496. + return true;
  7497. +}
  7498. +
  7499. +void VM_RedefineClasses::rollback() {
  7500. + RC_TRACE(0x00000001, ("Rolling back redefinition!"));
  7501. + SystemDictionary::rollback_redefinition();
  7502. +
  7503. + RC_TRACE(0x00000001, ("After rolling back system dictionary!"));
  7504. + for (int i=0; i<_new_classes->length(); i++) {
  7505. + SystemDictionary::remove_from_hierarchy(_new_classes->at(i));
  7506. + }
  7507. +
  7508. + for (int i=0; i<_new_classes->length(); i++) {
  7509. + instanceKlassHandle new_class = _new_classes->at(i);
  7510. + new_class->set_redefining(false);
  7511. + new_class->old_version()->klass_part()->set_new_version(NULL);
  7512. + new_class->set_old_version(NULL);
  7513. + }
  7514. +
  7515. +}
  7516. +
  7517. +template <class T> void VM_RedefineClasses::do_oop_work(T* p) {
  7518. + T heap_oop = oopDesc::load_heap_oop(p);
  7519. + if (!oopDesc::is_null(heap_oop)) {
  7520. + oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
  7521. + if (obj->is_instanceKlass()) {
  7522. + klassOop klass = (klassOop)obj;
  7523. + // DCEVM: note: can overwrite owner of old_klass constants pool with new_klass, so we need to fix it back later
  7524. + if (klass->new_version() != NULL && klass->new_version()->klass_part()->is_redefining()) {
  7525. + obj = klass->klass_part()->new_version();
  7526. + oopDesc::encode_store_heap_oop_not_null(p, obj);
  7527. + }
  7528. + } else if (obj->blueprint()->newest_version() == SystemDictionary::Class_klass()->klass_part()->newest_version()) {
  7529. + // update references to java.lang.Class to point to newest version. Only update references to non-primitive
  7530. + // java.lang.Class instances.
  7531. + klassOop klass_oop = java_lang_Class::as_klassOop(obj);
  7532. + if (klass_oop != NULL) {
  7533. + if (klass_oop->new_version() != NULL && klass_oop->new_version()->klass_part()->is_redefining()) {
  7534. + obj = klass_oop->new_version()->java_mirror();
  7535. + } else if (klass_oop->klass_part()->is_redefining()) {
  7536. + obj = klass_oop->java_mirror();
  7537. + }
  7538. + oopDesc::encode_store_heap_oop_not_null(p, obj);
  7539. +
  7540. +
  7541. + // FIXME: DCEVM: better implementation?
  7542. + // Starting from JDK 7 java_mirror can be kept in the regular heap. Therefore, it is possible
  7543. + // that new java_mirror is in the young generation whereas p is in tenured generation. In that
  7544. + // case we need to run write barrier to make sure card table is properly updated. This will
  7545. + // allow JVM to detect reference in tenured generation properly during young generation GC.
  7546. + if (Universe::heap()->is_in_reserved(p)) {
  7547. + if (GenCollectedHeap::heap()->is_in_young(obj)) {
  7548. + GenRemSet* rs = GenCollectedHeap::heap()->rem_set();
  7549. + assert(rs->rs_kind() == GenRemSet::CardTable, "Wrong rem set kind.");
  7550. + CardTableRS* _rs = (CardTableRS*)rs;
  7551. + _rs->inline_write_ref_field_gc(p, obj);
  7552. + }
  7553. + }
  7554. + }
  7555. + }
  7556. + }
  7557. +}
  7558. +
  7559. +void VM_RedefineClasses::swap_marks(oop first, oop second) {
  7560. + markOop first_mark = first->mark();
  7561. + markOop second_mark = second->mark();
  7562. + first->set_mark(second_mark);
  7563. + second->set_mark(first_mark);
  7564. +}
  7565. +
  7566. +void VM_RedefineClasses::doit() {
  7567. + Thread *thread = Thread::current();
  7568. +
  7569. + RC_TRACE(0x00000001, ("Entering doit!"));
  7570. +
  7571. +
  7572. + if ((_max_redefinition_flags & Klass::RemoveSuperType) != 0) {
  7573. +
  7574. + RC_TIMER_START(_timer_check_type);
  7575. +
  7576. + if (!check_type_consistency()) {
  7577. + // (tw) TODO: Rollback the class redefinition
  7578. + rollback();
  7579. + RC_TRACE(0x00000001, ("Detected type inconsistency!"));
  7580. + _result = JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  7581. + RC_TIMER_STOP(_timer_check_type);
  7582. + return;
  7583. + }
  7584. +
  7585. + RC_TIMER_STOP(_timer_check_type);
  7586. +
  7587. + } else {
  7588. + RC_TRACE(0x00000001, ("No type narrowing => skipping check for type inconsistency"));
  7589. + }
  7590. +
  7591. + if (UseMethodForwardPoints) {
  7592. + RC_TRACE(0x00000001, ("Check stack for forwarding methods to new version"));
  7593. + method_forwarding();
  7594. + }
  7595. +
  7596. + if (UseSharedSpaces) {
  7597. + // Sharing is enabled so we remap the shared readonly space to
  7598. + // shared readwrite, private just in case we need to redefine
  7599. + // a shared class. We do the remap during the doit() phase of
  7600. + // the safepoint to be safer.
  7601. + if (!CompactingPermGenGen::remap_shared_readonly_as_readwrite()) {
  7602. + RC_TRACE(0x00000001, ("failed to remap shared readonly space to readwrite, private"));
  7603. + _result = JVMTI_ERROR_INTERNAL;
  7604. + return;
  7605. + }
  7606. + }
  7607. +
  7608. + RC_TIMER_START(_timer_prepare_redefinition);
  7609. + for (int i = 0; i < _new_classes->length(); i++) {
  7610. + redefine_single_class(_new_classes->at(i), thread);
  7611. + }
  7612. +
  7613. + // Deoptimize all compiled code that depends on this class
  7614. + flush_dependent_code(instanceKlassHandle(Thread::current(), (klassOop)NULL), Thread::current());
  7615. +
  7616. + // Adjust constantpool caches and vtables for all classes
  7617. + // that reference methods of the evolved class.
  7618. + SystemDictionary::classes_do(adjust_cpool_cache, Thread::current());
  7619. +
  7620. + RC_TIMER_STOP(_timer_prepare_redefinition);
  7621. + RC_TIMER_START(_timer_redefinition);
  7622. +
  7623. + class ChangePointersOopClosure : public OopClosure {
  7624. + virtual void do_oop(oop* o) {
  7625. + do_oop_work(o);
  7626. + }
  7627. +
  7628. + virtual void do_oop(narrowOop* o) {
  7629. + do_oop_work(o);
  7630. + }
  7631. + };
  7632. +
  7633. + class ChangePointersObjectClosure : public ObjectClosure {
  7634. +
  7635. + private:
  7636. +
  7637. + OopClosure *_closure;
  7638. + bool _needs_instance_update;
  7639. + GrowableArray<oop> *_updated_oops;
  7640. +
  7641. + public:
  7642. + ChangePointersObjectClosure(OopClosure *closure) : _closure(closure), _needs_instance_update(false), _updated_oops(NULL) {}
  7643. +
  7644. + bool needs_instance_update() {
  7645. + return _needs_instance_update;
  7646. + }
  7647. +
  7648. + GrowableArray<oop> *updated_oops() { return _updated_oops; }
  7649. +
  7650. + virtual void do_object(oop obj) {
  7651. + if (!obj->is_instanceKlass()) {
  7652. + obj->oop_iterate(_closure);
  7653. +
  7654. + if (obj->blueprint()->is_redefining()) {
  7655. +
  7656. + if (obj->blueprint()->check_redefinition_flag(Klass::HasInstanceTransformer)) {
  7657. + if (_updated_oops == NULL) {
  7658. + _updated_oops = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<oop>(100, true);
  7659. + }
  7660. + _updated_oops->append(obj);
  7661. + }
  7662. +
  7663. + if(obj->blueprint()->update_information() != NULL || obj->is_perm()) {
  7664. +
  7665. + assert(obj->blueprint()->old_version() != NULL, "must have old version");
  7666. + obj->set_klass_no_check(obj->blueprint()->old_version());
  7667. +
  7668. + if (obj->size() != obj->size_given_klass(obj->blueprint()->new_version()->klass_part()) || obj->is_perm()) {
  7669. + // We need an instance update => set back to old klass
  7670. + _needs_instance_update = true;
  7671. +
  7672. + } else {
  7673. + MarkSweep::update_fields(obj, obj);
  7674. + assert(obj->blueprint()->is_redefining(), "update fields resets the klass");
  7675. + }
  7676. + }
  7677. + }
  7678. +
  7679. + } else {
  7680. + instanceKlass *klass = instanceKlass::cast((klassOop)obj);
  7681. + if (klass->is_redefining()) {
  7682. + // DCEVM: We need to restorte constants pool owner which was updated by do_oop_work
  7683. + instanceKlass* old_klass = instanceKlass::cast(klass->old_version());
  7684. + old_klass->constants()->set_pool_holder(klass->old_version());
  7685. +
  7686. + // Initialize the new class! Special static initialization that does not execute the
  7687. + // static constructor but copies static field values from the old class if name
  7688. + // and signature of a static field match.
  7689. + klass->initialize_redefined_class();
  7690. + }
  7691. + // idubrov: FIXME: we probably don't need that since oop's will be visited in a regular way...
  7692. + // idubrov: need to check if there is a test to verify that fields referencing class being updated
  7693. + // idubrov: will get new version of that class
  7694. + //klass->iterate_static_fields(_closure);
  7695. + }
  7696. + }
  7697. + };
  7698. +
  7699. + ChangePointersOopClosure oopClosure;
  7700. + ChangePointersObjectClosure objectClosure(&oopClosure);
  7701. +
  7702. + {
  7703. + SharedHeap::heap()->gc_prologue(true);
  7704. + Universe::root_oops_do(&oopClosure);
  7705. + Universe::heap()->object_iterate(&objectClosure);
  7706. + SharedHeap::heap()->gc_epilogue(false);
  7707. + }
  7708. +
  7709. + // Swap marks to have same hashcodes
  7710. + for (int i=0; i<_new_classes->length(); i++) {
  7711. + swap_marks(_new_classes->at(i)(), _new_classes->at(i)->old_version());
  7712. + swap_marks(_new_classes->at(i)->java_mirror(), _new_classes->at(i)->old_version()->java_mirror());
  7713. + }
  7714. +
  7715. + _updated_oops = objectClosure.updated_oops();
  7716. +
  7717. + if (objectClosure.needs_instance_update()){
  7718. +
  7719. + // Do a full garbage collection to update the instance sizes accordingly
  7720. + RC_TRACE(0x00000001, ("Before performing full GC!"));
  7721. + Universe::set_redefining_gc_run(true);
  7722. + JvmtiGCMarker jgcm;
  7723. + notify_gc_begin(true);
  7724. + Universe::heap()->collect_as_vm_thread(GCCause::_heap_inspection);
  7725. + notify_gc_end();
  7726. + Universe::set_redefining_gc_run(false);
  7727. + RC_TRACE(0x00000001, ("GC done!"));
  7728. + }
  7729. +
  7730. +
  7731. + if (RC_TRACE_ENABLED(0x00000001)) {
  7732. + if (_updated_oops != NULL) {
  7733. + RC_TRACE(0x00000001, ("%d object(s) updated!", _updated_oops->length()));
  7734. + } else {
  7735. + RC_TRACE(0x00000001, ("No objects updated!"));
  7736. + }
  7737. + }
  7738. +
  7739. + // Unmark klassOops as "redefining"
  7740. + for (int i=0; i<_new_classes->length(); i++) {
  7741. + klassOop cur = _new_classes->at(i)();
  7742. + _new_classes->at(i)->set_redefining(false);
  7743. + _new_classes->at(i)->clear_update_information();
  7744. + _new_classes->at(i)->update_supers_to_newest_version();
  7745. +
  7746. + if (((instanceKlass *)cur->klass_part()->old_version()->klass_part())->array_klasses() != NULL) {
  7747. + update_array_classes_to_newest_version(((instanceKlass *)cur->klass_part()->old_version()->klass_part())->array_klasses());
  7748. +
  7749. + // Transfer the array classes, otherwise we might get cast exceptions when casting array types.
  7750. + ((instanceKlass*)cur->klass_part())->set_array_klasses(((instanceKlass*)cur->klass_part()->old_version()->klass_part())->array_klasses());
  7751. +
  7752. + oop new_mirror = _new_classes->at(i)->java_mirror();
  7753. + oop old_mirror = _new_classes->at(i)->old_version()->java_mirror();
  7754. + java_lang_Class::set_array_klass(new_mirror, java_lang_Class::array_klass(old_mirror));
  7755. + }
  7756. + }
  7757. +
  7758. + for (int i=T_BOOLEAN; i<=T_LONG; i++) {
  7759. + update_array_classes_to_newest_version(Universe::typeArrayKlassObj((BasicType)i));
  7760. + }
  7761. +
  7762. + // Disable any dependent concurrent compilations
  7763. + SystemDictionary::notice_modification();
  7764. +
  7765. + // Set flag indicating that some invariants are no longer true.
  7766. + // See jvmtiExport.hpp for detailed explanation.
  7767. + JvmtiExport::set_has_redefined_a_class();
  7768. +
  7769. + // Clean up caches in the compiler interface and compiler threads
  7770. + CompileBroker::cleanup_after_redefinition();
  7771. +
  7772. +#ifdef ASSERT
  7773. +
  7774. + // Universe::verify();
  7775. + // JNIHandles::verify();
  7776. +
  7777. + SystemDictionary::classes_do(check_class, thread);
  7778. +#endif
  7779. +
  7780. + update_active_methods();
  7781. + RC_TIMER_STOP(_timer_redefinition);
  7782. +
  7783. +}
  7784. +
  7785. +void VM_RedefineClasses::update_array_classes_to_newest_version(klassOop smallest_dimension) {
  7786. +
  7787. + arrayKlass *curArrayKlass = arrayKlass::cast(smallest_dimension);
  7788. + assert(curArrayKlass->lower_dimension() == NULL, "argument must be smallest dimension");
  7789. +
  7790. +
  7791. + while (curArrayKlass != NULL) {
  7792. + klassOop higher_dimension = curArrayKlass->higher_dimension();
  7793. + klassOop lower_dimension = curArrayKlass->lower_dimension();
  7794. + curArrayKlass->update_supers_to_newest_version();
  7795. +
  7796. + curArrayKlass = NULL;
  7797. + if (higher_dimension != NULL) {
  7798. + curArrayKlass = arrayKlass::cast(higher_dimension);
  7799. + }
  7800. + }
  7801. +
  7802. +}
  7803. +
  7804. +void VM_RedefineClasses::doit_epilogue() {
  7805. +
  7806. + RC_TIMER_START(_timer_vm_op_epilogue);
  7807. +
  7808. + unlock_threads();
  7809. +
  7810. + ResourceMark mark;
  7811. +
  7812. + VM_GC_Operation::doit_epilogue();
  7813. + RC_TRACE(0x00000001, ("GC Operation epilogue finished! "));
  7814. +
  7815. + GrowableArray<methodHandle> instanceTransformerMethods;
  7816. +
  7817. + // Call static transformers
  7818. + for (int i=0; i<_new_classes->length(); i++) {
  7819. +
  7820. + instanceKlassHandle klass = _new_classes->at(i);
  7821. +
  7822. + // Transfer init state
  7823. + if (klass->old_version() != NULL) {
  7824. + instanceKlass::ClassState state = instanceKlass::cast(klass->old_version())->init_state();
  7825. + if (state > instanceKlass::linked) {
  7826. + klass->initialize(Thread::current());
  7827. + }
  7828. + }
  7829. +
  7830. + // Find instance transformer method
  7831. +
  7832. + if (klass->check_redefinition_flag(Klass::HasInstanceTransformer)) {
  7833. +
  7834. + RC_TRACE(0x00008000, ("Call instance transformer of %s instance", klass->name()->as_C_string()));
  7835. + klassOop cur_klass = klass();
  7836. + while (cur_klass != NULL) {
  7837. + methodOop method = ((instanceKlass*)cur_klass->klass_part())->find_method(vmSymbols::transformer_name(), vmSymbols::void_method_signature());
  7838. + if (method != NULL) {
  7839. + methodHandle instanceTransformerMethod(method);
  7840. + instanceTransformerMethods.append(instanceTransformerMethod);
  7841. + break;
  7842. + } else {
  7843. + cur_klass = cur_klass->klass_part()->super();
  7844. + }
  7845. + }
  7846. + assert(cur_klass != NULL, "must have instance transformer method");
  7847. + } else {
  7848. + instanceTransformerMethods.append(methodHandle(Thread::current(), NULL));
  7849. + }
  7850. + }
  7851. +
  7852. +
  7853. + // Call instance transformers
  7854. + if (_updated_oops != NULL) {
  7855. +
  7856. + for (int i=0; i<_updated_oops->length(); i++) {
  7857. + assert(_updated_oops->at(i) != NULL, "must not be null!");
  7858. + Handle cur(_updated_oops->at(i));
  7859. + instanceKlassHandle klass(cur->klass());
  7860. +
  7861. + if (klass->check_redefinition_flag(Klass::HasInstanceTransformer)) {
  7862. +
  7863. + methodHandle method = instanceTransformerMethods.at(klass->redefinition_index());
  7864. +
  7865. + RC_TRACE(0x00008000, ("executing transformer method"));
  7866. +
  7867. + Thread *__the_thread__ = Thread::current();
  7868. + JavaValue result(T_VOID);
  7869. + JavaCallArguments args(cur);
  7870. + JavaCalls::call(&result,
  7871. + method,
  7872. + &args,
  7873. + THREAD);
  7874. +
  7875. + // TODO: What to do with an exception here?
  7876. + if (HAS_PENDING_EXCEPTION) {
  7877. + Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  7878. + RC_TRACE(0x00000002, ("exception when executing transformer: '%s'",
  7879. + ex_name->as_C_string()));
  7880. + CLEAR_PENDING_EXCEPTION;
  7881. + }
  7882. + }
  7883. + }
  7884. +
  7885. + delete _updated_oops;
  7886. + _updated_oops = NULL;
  7887. + }
  7888. +
  7889. + // Free the array of scratch classes
  7890. + delete _new_classes;
  7891. + _new_classes = NULL;
  7892. + RC_TRACE(0x00000001, ("Redefinition finished!"));
  7893. +
  7894. + RC_TIMER_STOP(_timer_vm_op_epilogue);
  7895. +}
  7896. +
  7897. +bool VM_RedefineClasses::is_modifiable_class(oop klass_mirror) {
  7898. + // classes for primitives cannot be redefined
  7899. + if (java_lang_Class::is_primitive(klass_mirror)) {
  7900. return false;
  7901. }
  7902. -
  7903. - // rewrite constant pool references in the methods_parameter_annotations:
  7904. - if (!rewrite_cp_refs_in_methods_parameter_annotations(scratch_class,
  7905. - THREAD)) {
  7906. - // propagate failure back to caller
  7907. + klassOop the_class_oop = java_lang_Class::as_klassOop(klass_mirror);
  7908. + // classes for arrays cannot be redefined
  7909. + if (the_class_oop == NULL || !Klass::cast(the_class_oop)->oop_is_instance()) {
  7910. return false;
  7911. }
  7912. -
  7913. - // rewrite constant pool references in the methods_default_annotations:
  7914. - if (!rewrite_cp_refs_in_methods_default_annotations(scratch_class,
  7915. - THREAD)) {
  7916. - // propagate failure back to caller
  7917. - return false;
  7918. + return true;
  7919. +}
  7920. +
  7921. +#ifdef ASSERT
  7922. +
  7923. +void VM_RedefineClasses::verify_classes(klassOop k_oop_latest, oop initiating_loader, TRAPS) {
  7924. + klassOop k_oop = k_oop_latest;
  7925. + while (k_oop != NULL) {
  7926. +
  7927. + instanceKlassHandle k_handle(THREAD, k_oop);
  7928. + Verifier::verify(k_handle, Verifier::ThrowException, true, true, THREAD);
  7929. + k_oop = k_oop->klass_part()->old_version();
  7930. }
  7931. -
  7932. - return true;
  7933. -} // end rewrite_cp_refs()
  7934. -
  7935. -
  7936. -// Rewrite constant pool references in the methods.
  7937. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods(
  7938. - instanceKlassHandle scratch_class, TRAPS) {
  7939. -
  7940. - objArrayHandle methods(THREAD, scratch_class->methods());
  7941. -
  7942. - if (methods.is_null() || methods->length() == 0) {
  7943. - // no methods so nothing to do
  7944. - return true;
  7945. - }
  7946. -
  7947. - // rewrite constant pool references in the methods:
  7948. - for (int i = methods->length() - 1; i >= 0; i--) {
  7949. - methodHandle method(THREAD, (methodOop)methods->obj_at(i));
  7950. - methodHandle new_method;
  7951. - rewrite_cp_refs_in_method(method, &new_method, CHECK_false);
  7952. - if (!new_method.is_null()) {
  7953. - // the method has been replaced so save the new method version
  7954. - methods->obj_at_put(i, new_method());
  7955. +}
  7956. +
  7957. +#endif
  7958. +
  7959. +// Rewrite faster byte-codes back to their slower equivalent. Undoes rewriting happening in templateTable_xxx.cpp
  7960. +// The reason is that once we zero cpool caches, we need to re-resolve all entries again. Faster bytecodes do not
  7961. +// do that, they assume that cache entry is resolved already.
  7962. +static void unpatch_bytecode(methodOop method) {
  7963. + RawBytecodeStream bcs(method);
  7964. + Bytecodes::Code code;
  7965. + Bytecodes::Code java_code;
  7966. + while (!bcs.is_last_bytecode()) {
  7967. + code = bcs.raw_next();
  7968. + address bcp = bcs.bcp();
  7969. +
  7970. + if (code == Bytecodes::_breakpoint) {
  7971. + int bci = method->bci_from(bcp);
  7972. + code = method->orig_bytecode_at(bci);
  7973. + java_code = Bytecodes::java_code(code);
  7974. + if (code != java_code &&
  7975. + (java_code == Bytecodes::_getfield ||
  7976. + java_code == Bytecodes::_putfield ||
  7977. + java_code == Bytecodes::_aload_0)) {
  7978. + // Let breakpoint table handling unpatch bytecode
  7979. + method->set_orig_bytecode_at(bci, java_code);
  7980. + }
  7981. + } else {
  7982. + java_code = Bytecodes::java_code(code);
  7983. + if (code != java_code &&
  7984. + (java_code == Bytecodes::_getfield ||
  7985. + java_code == Bytecodes::_putfield ||
  7986. + java_code == Bytecodes::_aload_0)) {
  7987. + *bcp = java_code;
  7988. + }
  7989. + }
  7990. +
  7991. + // Additionally, we need to unpatch bytecode at bcp+1 for fast_xaccess (which would be fast field access)
  7992. + if (code == Bytecodes::_fast_iaccess_0 || code == Bytecodes::_fast_aaccess_0 || code == Bytecodes::_fast_faccess_0) {
  7993. + Bytecodes::Code code2 = Bytecodes::code_or_bp_at(bcp + 1);
  7994. + assert(code2 == Bytecodes::_fast_igetfield ||
  7995. + code2 == Bytecodes::_fast_agetfield ||
  7996. + code2 == Bytecodes::_fast_fgetfield, "");
  7997. + *(bcp + 1) = Bytecodes::java_code(code2);
  7998. }
  7999. }
  8000. -
  8001. - return true;
  8002. }
  8003. -
  8004. -// Rewrite constant pool references in the specific method. This code
  8005. -// was adapted from Rewriter::rewrite_method().
  8006. -void VM_RedefineClasses::rewrite_cp_refs_in_method(methodHandle method,
  8007. - methodHandle *new_method_p, TRAPS) {
  8008. -
  8009. - *new_method_p = methodHandle(); // default is no new method
  8010. -
  8011. - // We cache a pointer to the bytecodes here in code_base. If GC
  8012. - // moves the methodOop, then the bytecodes will also move which
  8013. - // will likely cause a crash. We create a No_Safepoint_Verifier
  8014. - // object to detect whether we pass a possible safepoint in this
  8015. - // code block.
  8016. - No_Safepoint_Verifier nsv;
  8017. -
  8018. - // Bytecodes and their length
  8019. - address code_base = method->code_base();
  8020. - int code_length = method->code_size();
  8021. -
  8022. - int bc_length;
  8023. - for (int bci = 0; bci < code_length; bci += bc_length) {
  8024. - address bcp = code_base + bci;
  8025. - Bytecodes::Code c = (Bytecodes::Code)(*bcp);
  8026. -
  8027. - bc_length = Bytecodes::length_for(c);
  8028. - if (bc_length == 0) {
  8029. - // More complicated bytecodes report a length of zero so
  8030. - // we have to try again a slightly different way.
  8031. - bc_length = Bytecodes::length_at(method(), bcp);
  8032. - }
  8033. -
  8034. - assert(bc_length != 0, "impossible bytecode length");
  8035. -
  8036. - switch (c) {
  8037. - case Bytecodes::_ldc:
  8038. - {
  8039. - int cp_index = *(bcp + 1);
  8040. - int new_index = find_new_index(cp_index);
  8041. -
  8042. - if (StressLdcRewrite && new_index == 0) {
  8043. - // If we are stressing ldc -> ldc_w rewriting, then we
  8044. - // always need a new_index value.
  8045. - new_index = cp_index;
  8046. - }
  8047. - if (new_index != 0) {
  8048. - // the original index is mapped so we have more work to do
  8049. - if (!StressLdcRewrite && new_index <= max_jubyte) {
  8050. - // The new value can still use ldc instead of ldc_w
  8051. - // unless we are trying to stress ldc -> ldc_w rewriting
  8052. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8053. - ("%s@" INTPTR_FORMAT " old=%d, new=%d", Bytecodes::name(c),
  8054. - bcp, cp_index, new_index));
  8055. - *(bcp + 1) = new_index;
  8056. - } else {
  8057. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8058. - ("%s->ldc_w@" INTPTR_FORMAT " old=%d, new=%d",
  8059. - Bytecodes::name(c), bcp, cp_index, new_index));
  8060. - // the new value needs ldc_w instead of ldc
  8061. - u_char inst_buffer[4]; // max instruction size is 4 bytes
  8062. - bcp = (address)inst_buffer;
  8063. - // construct new instruction sequence
  8064. - *bcp = Bytecodes::_ldc_w;
  8065. - bcp++;
  8066. - // Rewriter::rewrite_method() does not rewrite ldc -> ldc_w.
  8067. - // See comment below for difference between put_Java_u2()
  8068. - // and put_native_u2().
  8069. - Bytes::put_Java_u2(bcp, new_index);
  8070. -
  8071. - Relocator rc(method, NULL /* no RelocatorListener needed */);
  8072. - methodHandle m;
  8073. - {
  8074. - Pause_No_Safepoint_Verifier pnsv(&nsv);
  8075. -
  8076. - // ldc is 2 bytes and ldc_w is 3 bytes
  8077. - m = rc.insert_space_at(bci, 3, inst_buffer, THREAD);
  8078. - if (m.is_null() || HAS_PENDING_EXCEPTION) {
  8079. - guarantee(false, "insert_space_at() failed");
  8080. - }
  8081. - }
  8082. -
  8083. - // return the new method so that the caller can update
  8084. - // the containing class
  8085. - *new_method_p = method = m;
  8086. - // switch our bytecode processing loop from the old method
  8087. - // to the new method
  8088. - code_base = method->code_base();
  8089. - code_length = method->code_size();
  8090. - bcp = code_base + bci;
  8091. - c = (Bytecodes::Code)(*bcp);
  8092. - bc_length = Bytecodes::length_for(c);
  8093. - assert(bc_length != 0, "sanity check");
  8094. - } // end we need ldc_w instead of ldc
  8095. - } // end if there is a mapped index
  8096. - } break;
  8097. -
  8098. - // these bytecodes have a two-byte constant pool index
  8099. - case Bytecodes::_anewarray : // fall through
  8100. - case Bytecodes::_checkcast : // fall through
  8101. - case Bytecodes::_getfield : // fall through
  8102. - case Bytecodes::_getstatic : // fall through
  8103. - case Bytecodes::_instanceof : // fall through
  8104. - case Bytecodes::_invokeinterface: // fall through
  8105. - case Bytecodes::_invokespecial : // fall through
  8106. - case Bytecodes::_invokestatic : // fall through
  8107. - case Bytecodes::_invokevirtual : // fall through
  8108. - case Bytecodes::_ldc_w : // fall through
  8109. - case Bytecodes::_ldc2_w : // fall through
  8110. - case Bytecodes::_multianewarray : // fall through
  8111. - case Bytecodes::_new : // fall through
  8112. - case Bytecodes::_putfield : // fall through
  8113. - case Bytecodes::_putstatic :
  8114. - {
  8115. - address p = bcp + 1;
  8116. - int cp_index = Bytes::get_Java_u2(p);
  8117. - int new_index = find_new_index(cp_index);
  8118. - if (new_index != 0) {
  8119. - // the original index is mapped so update w/ new value
  8120. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8121. - ("%s@" INTPTR_FORMAT " old=%d, new=%d", Bytecodes::name(c),
  8122. - bcp, cp_index, new_index));
  8123. - // Rewriter::rewrite_method() uses put_native_u2() in this
  8124. - // situation because it is reusing the constant pool index
  8125. - // location for a native index into the constantPoolCache.
  8126. - // Since we are updating the constant pool index prior to
  8127. - // verification and constantPoolCache initialization, we
  8128. - // need to keep the new index in Java byte order.
  8129. - Bytes::put_Java_u2(p, new_index);
  8130. - }
  8131. - } break;
  8132. - }
  8133. - } // end for each bytecode
  8134. -} // end rewrite_cp_refs_in_method()
  8135. -
  8136. -
  8137. -// Rewrite constant pool references in the class_annotations field.
  8138. -bool VM_RedefineClasses::rewrite_cp_refs_in_class_annotations(
  8139. - instanceKlassHandle scratch_class, TRAPS) {
  8140. -
  8141. - typeArrayHandle class_annotations(THREAD,
  8142. - scratch_class->class_annotations());
  8143. - if (class_annotations.is_null() || class_annotations->length() == 0) {
  8144. - // no class_annotations so nothing to do
  8145. - return true;
  8146. - }
  8147. -
  8148. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8149. - ("class_annotations length=%d", class_annotations->length()));
  8150. -
  8151. - int byte_i = 0; // byte index into class_annotations
  8152. - return rewrite_cp_refs_in_annotations_typeArray(class_annotations, byte_i,
  8153. - THREAD);
  8154. -}
  8155. -
  8156. -
  8157. -// Rewrite constant pool references in an annotations typeArray. This
  8158. -// "structure" is adapted from the RuntimeVisibleAnnotations_attribute
  8159. -// that is described in section 4.8.15 of the 2nd-edition of the VM spec:
  8160. -//
  8161. -// annotations_typeArray {
  8162. -// u2 num_annotations;
  8163. -// annotation annotations[num_annotations];
  8164. -// }
  8165. -//
  8166. -bool VM_RedefineClasses::rewrite_cp_refs_in_annotations_typeArray(
  8167. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  8168. -
  8169. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  8170. - // not enough room for num_annotations field
  8171. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8172. - ("length() is too small for num_annotations field"));
  8173. - return false;
  8174. - }
  8175. -
  8176. - u2 num_annotations = Bytes::get_Java_u2((address)
  8177. - annotations_typeArray->byte_at_addr(byte_i_ref));
  8178. - byte_i_ref += 2;
  8179. -
  8180. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8181. - ("num_annotations=%d", num_annotations));
  8182. -
  8183. - int calc_num_annotations = 0;
  8184. - for (; calc_num_annotations < num_annotations; calc_num_annotations++) {
  8185. - if (!rewrite_cp_refs_in_annotation_struct(annotations_typeArray,
  8186. - byte_i_ref, THREAD)) {
  8187. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8188. - ("bad annotation_struct at %d", calc_num_annotations));
  8189. - // propagate failure back to caller
  8190. - return false;
  8191. - }
  8192. - }
  8193. - assert(num_annotations == calc_num_annotations, "sanity check");
  8194. -
  8195. - return true;
  8196. -} // end rewrite_cp_refs_in_annotations_typeArray()
  8197. -
  8198. -
  8199. -// Rewrite constant pool references in the annotation struct portion of
  8200. -// an annotations_typeArray. This "structure" is from section 4.8.15 of
  8201. -// the 2nd-edition of the VM spec:
  8202. -//
  8203. -// struct annotation {
  8204. -// u2 type_index;
  8205. -// u2 num_element_value_pairs;
  8206. -// {
  8207. -// u2 element_name_index;
  8208. -// element_value value;
  8209. -// } element_value_pairs[num_element_value_pairs];
  8210. -// }
  8211. -//
  8212. -bool VM_RedefineClasses::rewrite_cp_refs_in_annotation_struct(
  8213. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  8214. - if ((byte_i_ref + 2 + 2) > annotations_typeArray->length()) {
  8215. - // not enough room for smallest annotation_struct
  8216. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8217. - ("length() is too small for annotation_struct"));
  8218. - return false;
  8219. - }
  8220. -
  8221. - u2 type_index = rewrite_cp_ref_in_annotation_data(annotations_typeArray,
  8222. - byte_i_ref, "mapped old type_index=%d", THREAD);
  8223. -
  8224. - u2 num_element_value_pairs = Bytes::get_Java_u2((address)
  8225. - annotations_typeArray->byte_at_addr(
  8226. - byte_i_ref));
  8227. - byte_i_ref += 2;
  8228. -
  8229. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8230. - ("type_index=%d num_element_value_pairs=%d", type_index,
  8231. - num_element_value_pairs));
  8232. -
  8233. - int calc_num_element_value_pairs = 0;
  8234. - for (; calc_num_element_value_pairs < num_element_value_pairs;
  8235. - calc_num_element_value_pairs++) {
  8236. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  8237. - // not enough room for another element_name_index, let alone
  8238. - // the rest of another component
  8239. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8240. - ("length() is too small for element_name_index"));
  8241. - return false;
  8242. - }
  8243. -
  8244. - u2 element_name_index = rewrite_cp_ref_in_annotation_data(
  8245. - annotations_typeArray, byte_i_ref,
  8246. - "mapped old element_name_index=%d", THREAD);
  8247. -
  8248. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8249. - ("element_name_index=%d", element_name_index));
  8250. -
  8251. - if (!rewrite_cp_refs_in_element_value(annotations_typeArray,
  8252. - byte_i_ref, THREAD)) {
  8253. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8254. - ("bad element_value at %d", calc_num_element_value_pairs));
  8255. - // propagate failure back to caller
  8256. - return false;
  8257. - }
  8258. - } // end for each component
  8259. - assert(num_element_value_pairs == calc_num_element_value_pairs,
  8260. - "sanity check");
  8261. -
  8262. - return true;
  8263. -} // end rewrite_cp_refs_in_annotation_struct()
  8264. -
  8265. -
  8266. -// Rewrite a constant pool reference at the current position in
  8267. -// annotations_typeArray if needed. Returns the original constant
  8268. -// pool reference if a rewrite was not needed or the new constant
  8269. -// pool reference if a rewrite was needed.
  8270. -u2 VM_RedefineClasses::rewrite_cp_ref_in_annotation_data(
  8271. - typeArrayHandle annotations_typeArray, int &byte_i_ref,
  8272. - const char * trace_mesg, TRAPS) {
  8273. -
  8274. - address cp_index_addr = (address)
  8275. - annotations_typeArray->byte_at_addr(byte_i_ref);
  8276. - u2 old_cp_index = Bytes::get_Java_u2(cp_index_addr);
  8277. - u2 new_cp_index = find_new_index(old_cp_index);
  8278. - if (new_cp_index != 0) {
  8279. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, (trace_mesg, old_cp_index));
  8280. - Bytes::put_Java_u2(cp_index_addr, new_cp_index);
  8281. - old_cp_index = new_cp_index;
  8282. - }
  8283. - byte_i_ref += 2;
  8284. - return old_cp_index;
  8285. -}
  8286. -
  8287. -
  8288. -// Rewrite constant pool references in the element_value portion of an
  8289. -// annotations_typeArray. This "structure" is from section 4.8.15.1 of
  8290. -// the 2nd-edition of the VM spec:
  8291. -//
  8292. -// struct element_value {
  8293. -// u1 tag;
  8294. -// union {
  8295. -// u2 const_value_index;
  8296. -// {
  8297. -// u2 type_name_index;
  8298. -// u2 const_name_index;
  8299. -// } enum_const_value;
  8300. -// u2 class_info_index;
  8301. -// annotation annotation_value;
  8302. -// struct {
  8303. -// u2 num_values;
  8304. -// element_value values[num_values];
  8305. -// } array_value;
  8306. -// } value;
  8307. -// }
  8308. -//
  8309. -bool VM_RedefineClasses::rewrite_cp_refs_in_element_value(
  8310. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  8311. -
  8312. - if ((byte_i_ref + 1) > annotations_typeArray->length()) {
  8313. - // not enough room for a tag let alone the rest of an element_value
  8314. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8315. - ("length() is too small for a tag"));
  8316. - return false;
  8317. - }
  8318. -
  8319. - u1 tag = annotations_typeArray->byte_at(byte_i_ref);
  8320. - byte_i_ref++;
  8321. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("tag='%c'", tag));
  8322. -
  8323. - switch (tag) {
  8324. - // These BaseType tag values are from Table 4.2 in VM spec:
  8325. - case 'B': // byte
  8326. - case 'C': // char
  8327. - case 'D': // double
  8328. - case 'F': // float
  8329. - case 'I': // int
  8330. - case 'J': // long
  8331. - case 'S': // short
  8332. - case 'Z': // boolean
  8333. -
  8334. - // The remaining tag values are from Table 4.8 in the 2nd-edition of
  8335. - // the VM spec:
  8336. - case 's':
  8337. - {
  8338. - // For the above tag values (including the BaseType values),
  8339. - // value.const_value_index is right union field.
  8340. -
  8341. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  8342. - // not enough room for a const_value_index
  8343. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8344. - ("length() is too small for a const_value_index"));
  8345. - return false;
  8346. - }
  8347. -
  8348. - u2 const_value_index = rewrite_cp_ref_in_annotation_data(
  8349. - annotations_typeArray, byte_i_ref,
  8350. - "mapped old const_value_index=%d", THREAD);
  8351. -
  8352. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8353. - ("const_value_index=%d", const_value_index));
  8354. - } break;
  8355. -
  8356. - case 'e':
  8357. - {
  8358. - // for the above tag value, value.enum_const_value is right union field
  8359. -
  8360. - if ((byte_i_ref + 4) > annotations_typeArray->length()) {
  8361. - // not enough room for a enum_const_value
  8362. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8363. - ("length() is too small for a enum_const_value"));
  8364. - return false;
  8365. - }
  8366. -
  8367. - u2 type_name_index = rewrite_cp_ref_in_annotation_data(
  8368. - annotations_typeArray, byte_i_ref,
  8369. - "mapped old type_name_index=%d", THREAD);
  8370. -
  8371. - u2 const_name_index = rewrite_cp_ref_in_annotation_data(
  8372. - annotations_typeArray, byte_i_ref,
  8373. - "mapped old const_name_index=%d", THREAD);
  8374. -
  8375. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8376. - ("type_name_index=%d const_name_index=%d", type_name_index,
  8377. - const_name_index));
  8378. - } break;
  8379. -
  8380. - case 'c':
  8381. - {
  8382. - // for the above tag value, value.class_info_index is right union field
  8383. -
  8384. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  8385. - // not enough room for a class_info_index
  8386. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8387. - ("length() is too small for a class_info_index"));
  8388. - return false;
  8389. - }
  8390. -
  8391. - u2 class_info_index = rewrite_cp_ref_in_annotation_data(
  8392. - annotations_typeArray, byte_i_ref,
  8393. - "mapped old class_info_index=%d", THREAD);
  8394. -
  8395. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8396. - ("class_info_index=%d", class_info_index));
  8397. - } break;
  8398. -
  8399. - case '@':
  8400. - // For the above tag value, value.attr_value is the right union
  8401. - // field. This is a nested annotation.
  8402. - if (!rewrite_cp_refs_in_annotation_struct(annotations_typeArray,
  8403. - byte_i_ref, THREAD)) {
  8404. - // propagate failure back to caller
  8405. - return false;
  8406. - }
  8407. - break;
  8408. -
  8409. - case '[':
  8410. - {
  8411. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  8412. - // not enough room for a num_values field
  8413. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8414. - ("length() is too small for a num_values field"));
  8415. - return false;
  8416. - }
  8417. -
  8418. - // For the above tag value, value.array_value is the right union
  8419. - // field. This is an array of nested element_value.
  8420. - u2 num_values = Bytes::get_Java_u2((address)
  8421. - annotations_typeArray->byte_at_addr(byte_i_ref));
  8422. - byte_i_ref += 2;
  8423. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("num_values=%d", num_values));
  8424. -
  8425. - int calc_num_values = 0;
  8426. - for (; calc_num_values < num_values; calc_num_values++) {
  8427. - if (!rewrite_cp_refs_in_element_value(
  8428. - annotations_typeArray, byte_i_ref, THREAD)) {
  8429. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8430. - ("bad nested element_value at %d", calc_num_values));
  8431. - // propagate failure back to caller
  8432. - return false;
  8433. - }
  8434. - }
  8435. - assert(num_values == calc_num_values, "sanity check");
  8436. - } break;
  8437. -
  8438. - default:
  8439. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("bad tag=0x%x", tag));
  8440. - return false;
  8441. - } // end decode tag field
  8442. -
  8443. - return true;
  8444. -} // end rewrite_cp_refs_in_element_value()
  8445. -
  8446. -
  8447. -// Rewrite constant pool references in a fields_annotations field.
  8448. -bool VM_RedefineClasses::rewrite_cp_refs_in_fields_annotations(
  8449. - instanceKlassHandle scratch_class, TRAPS) {
  8450. -
  8451. - objArrayHandle fields_annotations(THREAD,
  8452. - scratch_class->fields_annotations());
  8453. -
  8454. - if (fields_annotations.is_null() || fields_annotations->length() == 0) {
  8455. - // no fields_annotations so nothing to do
  8456. - return true;
  8457. - }
  8458. -
  8459. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8460. - ("fields_annotations length=%d", fields_annotations->length()));
  8461. -
  8462. - for (int i = 0; i < fields_annotations->length(); i++) {
  8463. - typeArrayHandle field_annotations(THREAD,
  8464. - (typeArrayOop)fields_annotations->obj_at(i));
  8465. - if (field_annotations.is_null() || field_annotations->length() == 0) {
  8466. - // this field does not have any annotations so skip it
  8467. - continue;
  8468. - }
  8469. -
  8470. - int byte_i = 0; // byte index into field_annotations
  8471. - if (!rewrite_cp_refs_in_annotations_typeArray(field_annotations, byte_i,
  8472. - THREAD)) {
  8473. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8474. - ("bad field_annotations at %d", i));
  8475. - // propagate failure back to caller
  8476. - return false;
  8477. - }
  8478. - }
  8479. -
  8480. - return true;
  8481. -} // end rewrite_cp_refs_in_fields_annotations()
  8482. -
  8483. -
  8484. -// Rewrite constant pool references in a methods_annotations field.
  8485. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_annotations(
  8486. - instanceKlassHandle scratch_class, TRAPS) {
  8487. -
  8488. - objArrayHandle methods_annotations(THREAD,
  8489. - scratch_class->methods_annotations());
  8490. -
  8491. - if (methods_annotations.is_null() || methods_annotations->length() == 0) {
  8492. - // no methods_annotations so nothing to do
  8493. - return true;
  8494. - }
  8495. -
  8496. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8497. - ("methods_annotations length=%d", methods_annotations->length()));
  8498. -
  8499. - for (int i = 0; i < methods_annotations->length(); i++) {
  8500. - typeArrayHandle method_annotations(THREAD,
  8501. - (typeArrayOop)methods_annotations->obj_at(i));
  8502. - if (method_annotations.is_null() || method_annotations->length() == 0) {
  8503. - // this method does not have any annotations so skip it
  8504. - continue;
  8505. - }
  8506. -
  8507. - int byte_i = 0; // byte index into method_annotations
  8508. - if (!rewrite_cp_refs_in_annotations_typeArray(method_annotations, byte_i,
  8509. - THREAD)) {
  8510. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8511. - ("bad method_annotations at %d", i));
  8512. - // propagate failure back to caller
  8513. - return false;
  8514. - }
  8515. - }
  8516. -
  8517. - return true;
  8518. -} // end rewrite_cp_refs_in_methods_annotations()
  8519. -
  8520. -
  8521. -// Rewrite constant pool references in a methods_parameter_annotations
  8522. -// field. This "structure" is adapted from the
  8523. -// RuntimeVisibleParameterAnnotations_attribute described in section
  8524. -// 4.8.17 of the 2nd-edition of the VM spec:
  8525. -//
  8526. -// methods_parameter_annotations_typeArray {
  8527. -// u1 num_parameters;
  8528. -// {
  8529. -// u2 num_annotations;
  8530. -// annotation annotations[num_annotations];
  8531. -// } parameter_annotations[num_parameters];
  8532. -// }
  8533. -//
  8534. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_parameter_annotations(
  8535. - instanceKlassHandle scratch_class, TRAPS) {
  8536. -
  8537. - objArrayHandle methods_parameter_annotations(THREAD,
  8538. - scratch_class->methods_parameter_annotations());
  8539. -
  8540. - if (methods_parameter_annotations.is_null()
  8541. - || methods_parameter_annotations->length() == 0) {
  8542. - // no methods_parameter_annotations so nothing to do
  8543. - return true;
  8544. - }
  8545. -
  8546. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8547. - ("methods_parameter_annotations length=%d",
  8548. - methods_parameter_annotations->length()));
  8549. -
  8550. - for (int i = 0; i < methods_parameter_annotations->length(); i++) {
  8551. - typeArrayHandle method_parameter_annotations(THREAD,
  8552. - (typeArrayOop)methods_parameter_annotations->obj_at(i));
  8553. - if (method_parameter_annotations.is_null()
  8554. - || method_parameter_annotations->length() == 0) {
  8555. - // this method does not have any parameter annotations so skip it
  8556. - continue;
  8557. - }
  8558. -
  8559. - if (method_parameter_annotations->length() < 1) {
  8560. - // not enough room for a num_parameters field
  8561. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8562. - ("length() is too small for a num_parameters field at %d", i));
  8563. - return false;
  8564. - }
  8565. -
  8566. - int byte_i = 0; // byte index into method_parameter_annotations
  8567. -
  8568. - u1 num_parameters = method_parameter_annotations->byte_at(byte_i);
  8569. - byte_i++;
  8570. -
  8571. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8572. - ("num_parameters=%d", num_parameters));
  8573. -
  8574. - int calc_num_parameters = 0;
  8575. - for (; calc_num_parameters < num_parameters; calc_num_parameters++) {
  8576. - if (!rewrite_cp_refs_in_annotations_typeArray(
  8577. - method_parameter_annotations, byte_i, THREAD)) {
  8578. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8579. - ("bad method_parameter_annotations at %d", calc_num_parameters));
  8580. - // propagate failure back to caller
  8581. - return false;
  8582. - }
  8583. - }
  8584. - assert(num_parameters == calc_num_parameters, "sanity check");
  8585. - }
  8586. -
  8587. - return true;
  8588. -} // end rewrite_cp_refs_in_methods_parameter_annotations()
  8589. -
  8590. -
  8591. -// Rewrite constant pool references in a methods_default_annotations
  8592. -// field. This "structure" is adapted from the AnnotationDefault_attribute
  8593. -// that is described in section 4.8.19 of the 2nd-edition of the VM spec:
  8594. -//
  8595. -// methods_default_annotations_typeArray {
  8596. -// element_value default_value;
  8597. -// }
  8598. -//
  8599. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_default_annotations(
  8600. - instanceKlassHandle scratch_class, TRAPS) {
  8601. -
  8602. - objArrayHandle methods_default_annotations(THREAD,
  8603. - scratch_class->methods_default_annotations());
  8604. -
  8605. - if (methods_default_annotations.is_null()
  8606. - || methods_default_annotations->length() == 0) {
  8607. - // no methods_default_annotations so nothing to do
  8608. - return true;
  8609. - }
  8610. -
  8611. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8612. - ("methods_default_annotations length=%d",
  8613. - methods_default_annotations->length()));
  8614. -
  8615. - for (int i = 0; i < methods_default_annotations->length(); i++) {
  8616. - typeArrayHandle method_default_annotations(THREAD,
  8617. - (typeArrayOop)methods_default_annotations->obj_at(i));
  8618. - if (method_default_annotations.is_null()
  8619. - || method_default_annotations->length() == 0) {
  8620. - // this method does not have any default annotations so skip it
  8621. - continue;
  8622. - }
  8623. -
  8624. - int byte_i = 0; // byte index into method_default_annotations
  8625. -
  8626. - if (!rewrite_cp_refs_in_element_value(
  8627. - method_default_annotations, byte_i, THREAD)) {
  8628. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8629. - ("bad default element_value at %d", i));
  8630. - // propagate failure back to caller
  8631. - return false;
  8632. - }
  8633. - }
  8634. -
  8635. - return true;
  8636. -} // end rewrite_cp_refs_in_methods_default_annotations()
  8637. -
  8638. -
  8639. -// Rewrite constant pool references in the method's stackmap table.
  8640. -// These "structures" are adapted from the StackMapTable_attribute that
  8641. -// is described in section 4.8.4 of the 6.0 version of the VM spec
  8642. -// (dated 2005.10.26):
  8643. -// file:///net/quincunx.sfbay/export/gbracha/ClassFile-Java6.pdf
  8644. -//
  8645. -// stack_map {
  8646. -// u2 number_of_entries;
  8647. -// stack_map_frame entries[number_of_entries];
  8648. -// }
  8649. -//
  8650. -void VM_RedefineClasses::rewrite_cp_refs_in_stack_map_table(
  8651. - methodHandle method, TRAPS) {
  8652. -
  8653. - if (!method->has_stackmap_table()) {
  8654. - return;
  8655. - }
  8656. -
  8657. - typeArrayOop stackmap_data = method->stackmap_data();
  8658. - address stackmap_p = (address)stackmap_data->byte_at_addr(0);
  8659. - address stackmap_end = stackmap_p + stackmap_data->length();
  8660. -
  8661. - assert(stackmap_p + 2 <= stackmap_end, "no room for number_of_entries");
  8662. - u2 number_of_entries = Bytes::get_Java_u2(stackmap_p);
  8663. - stackmap_p += 2;
  8664. -
  8665. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  8666. - ("number_of_entries=%u", number_of_entries));
  8667. -
  8668. - // walk through each stack_map_frame
  8669. - u2 calc_number_of_entries = 0;
  8670. - for (; calc_number_of_entries < number_of_entries; calc_number_of_entries++) {
  8671. - // The stack_map_frame structure is a u1 frame_type followed by
  8672. - // 0 or more bytes of data:
  8673. - //
  8674. - // union stack_map_frame {
  8675. - // same_frame;
  8676. - // same_locals_1_stack_item_frame;
  8677. - // same_locals_1_stack_item_frame_extended;
  8678. - // chop_frame;
  8679. - // same_frame_extended;
  8680. - // append_frame;
  8681. - // full_frame;
  8682. - // }
  8683. -
  8684. - assert(stackmap_p + 1 <= stackmap_end, "no room for frame_type");
  8685. - // The Linux compiler does not like frame_type to be u1 or u2. It
  8686. - // issues the following warning for the first if-statement below:
  8687. - //
  8688. - // "warning: comparison is always true due to limited range of data type"
  8689. - //
  8690. - u4 frame_type = *stackmap_p;
  8691. - stackmap_p++;
  8692. -
  8693. - // same_frame {
  8694. - // u1 frame_type = SAME; /* 0-63 */
  8695. - // }
  8696. - if (frame_type >= 0 && frame_type <= 63) {
  8697. - // nothing more to do for same_frame
  8698. - }
  8699. -
  8700. - // same_locals_1_stack_item_frame {
  8701. - // u1 frame_type = SAME_LOCALS_1_STACK_ITEM; /* 64-127 */
  8702. - // verification_type_info stack[1];
  8703. - // }
  8704. - else if (frame_type >= 64 && frame_type <= 127) {
  8705. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8706. - calc_number_of_entries, frame_type, THREAD);
  8707. - }
  8708. -
  8709. - // reserved for future use
  8710. - else if (frame_type >= 128 && frame_type <= 246) {
  8711. - // nothing more to do for reserved frame_types
  8712. - }
  8713. -
  8714. - // same_locals_1_stack_item_frame_extended {
  8715. - // u1 frame_type = SAME_LOCALS_1_STACK_ITEM_EXTENDED; /* 247 */
  8716. - // u2 offset_delta;
  8717. - // verification_type_info stack[1];
  8718. - // }
  8719. - else if (frame_type == 247) {
  8720. - stackmap_p += 2;
  8721. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8722. - calc_number_of_entries, frame_type, THREAD);
  8723. - }
  8724. -
  8725. - // chop_frame {
  8726. - // u1 frame_type = CHOP; /* 248-250 */
  8727. - // u2 offset_delta;
  8728. - // }
  8729. - else if (frame_type >= 248 && frame_type <= 250) {
  8730. - stackmap_p += 2;
  8731. - }
  8732. -
  8733. - // same_frame_extended {
  8734. - // u1 frame_type = SAME_FRAME_EXTENDED; /* 251*/
  8735. - // u2 offset_delta;
  8736. - // }
  8737. - else if (frame_type == 251) {
  8738. - stackmap_p += 2;
  8739. - }
  8740. -
  8741. - // append_frame {
  8742. - // u1 frame_type = APPEND; /* 252-254 */
  8743. - // u2 offset_delta;
  8744. - // verification_type_info locals[frame_type - 251];
  8745. - // }
  8746. - else if (frame_type >= 252 && frame_type <= 254) {
  8747. - assert(stackmap_p + 2 <= stackmap_end,
  8748. - "no room for offset_delta");
  8749. - stackmap_p += 2;
  8750. - u1 len = frame_type - 251;
  8751. - for (u1 i = 0; i < len; i++) {
  8752. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8753. - calc_number_of_entries, frame_type, THREAD);
  8754. - }
  8755. - }
  8756. -
  8757. - // full_frame {
  8758. - // u1 frame_type = FULL_FRAME; /* 255 */
  8759. - // u2 offset_delta;
  8760. - // u2 number_of_locals;
  8761. - // verification_type_info locals[number_of_locals];
  8762. - // u2 number_of_stack_items;
  8763. - // verification_type_info stack[number_of_stack_items];
  8764. - // }
  8765. - else if (frame_type == 255) {
  8766. - assert(stackmap_p + 2 + 2 <= stackmap_end,
  8767. - "no room for smallest full_frame");
  8768. - stackmap_p += 2;
  8769. -
  8770. - u2 number_of_locals = Bytes::get_Java_u2(stackmap_p);
  8771. - stackmap_p += 2;
  8772. -
  8773. - for (u2 locals_i = 0; locals_i < number_of_locals; locals_i++) {
  8774. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8775. - calc_number_of_entries, frame_type, THREAD);
  8776. - }
  8777. -
  8778. - // Use the largest size for the number_of_stack_items, but only get
  8779. - // the right number of bytes.
  8780. - u2 number_of_stack_items = Bytes::get_Java_u2(stackmap_p);
  8781. - stackmap_p += 2;
  8782. -
  8783. - for (u2 stack_i = 0; stack_i < number_of_stack_items; stack_i++) {
  8784. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8785. - calc_number_of_entries, frame_type, THREAD);
  8786. - }
  8787. - }
  8788. - } // end while there is a stack_map_frame
  8789. - assert(number_of_entries == calc_number_of_entries, "sanity check");
  8790. -} // end rewrite_cp_refs_in_stack_map_table()
  8791. -
  8792. -
  8793. -// Rewrite constant pool references in the verification type info
  8794. -// portion of the method's stackmap table. These "structures" are
  8795. -// adapted from the StackMapTable_attribute that is described in
  8796. -// section 4.8.4 of the 6.0 version of the VM spec (dated 2005.10.26):
  8797. -// file:///net/quincunx.sfbay/export/gbracha/ClassFile-Java6.pdf
  8798. -//
  8799. -// The verification_type_info structure is a u1 tag followed by 0 or
  8800. -// more bytes of data:
  8801. -//
  8802. -// union verification_type_info {
  8803. -// Top_variable_info;
  8804. -// Integer_variable_info;
  8805. -// Float_variable_info;
  8806. -// Long_variable_info;
  8807. -// Double_variable_info;
  8808. -// Null_variable_info;
  8809. -// UninitializedThis_variable_info;
  8810. -// Object_variable_info;
  8811. -// Uninitialized_variable_info;
  8812. -// }
  8813. -//
  8814. -void VM_RedefineClasses::rewrite_cp_refs_in_verification_type_info(
  8815. - address& stackmap_p_ref, address stackmap_end, u2 frame_i,
  8816. - u1 frame_type, TRAPS) {
  8817. -
  8818. - assert(stackmap_p_ref + 1 <= stackmap_end, "no room for tag");
  8819. - u1 tag = *stackmap_p_ref;
  8820. - stackmap_p_ref++;
  8821. -
  8822. - switch (tag) {
  8823. - // Top_variable_info {
  8824. - // u1 tag = ITEM_Top; /* 0 */
  8825. - // }
  8826. - // verificationType.hpp has zero as ITEM_Bogus instead of ITEM_Top
  8827. - case 0: // fall through
  8828. -
  8829. - // Integer_variable_info {
  8830. - // u1 tag = ITEM_Integer; /* 1 */
  8831. - // }
  8832. - case ITEM_Integer: // fall through
  8833. -
  8834. - // Float_variable_info {
  8835. - // u1 tag = ITEM_Float; /* 2 */
  8836. - // }
  8837. - case ITEM_Float: // fall through
  8838. -
  8839. - // Double_variable_info {
  8840. - // u1 tag = ITEM_Double; /* 3 */
  8841. - // }
  8842. - case ITEM_Double: // fall through
  8843. -
  8844. - // Long_variable_info {
  8845. - // u1 tag = ITEM_Long; /* 4 */
  8846. - // }
  8847. - case ITEM_Long: // fall through
  8848. -
  8849. - // Null_variable_info {
  8850. - // u1 tag = ITEM_Null; /* 5 */
  8851. - // }
  8852. - case ITEM_Null: // fall through
  8853. -
  8854. - // UninitializedThis_variable_info {
  8855. - // u1 tag = ITEM_UninitializedThis; /* 6 */
  8856. - // }
  8857. - case ITEM_UninitializedThis:
  8858. - // nothing more to do for the above tag types
  8859. - break;
  8860. -
  8861. - // Object_variable_info {
  8862. - // u1 tag = ITEM_Object; /* 7 */
  8863. - // u2 cpool_index;
  8864. - // }
  8865. - case ITEM_Object:
  8866. - {
  8867. - assert(stackmap_p_ref + 2 <= stackmap_end, "no room for cpool_index");
  8868. - u2 cpool_index = Bytes::get_Java_u2(stackmap_p_ref);
  8869. - u2 new_cp_index = find_new_index(cpool_index);
  8870. - if (new_cp_index != 0) {
  8871. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  8872. - ("mapped old cpool_index=%d", cpool_index));
  8873. - Bytes::put_Java_u2(stackmap_p_ref, new_cp_index);
  8874. - cpool_index = new_cp_index;
  8875. - }
  8876. - stackmap_p_ref += 2;
  8877. -
  8878. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  8879. - ("frame_i=%u, frame_type=%u, cpool_index=%d", frame_i,
  8880. - frame_type, cpool_index));
  8881. - } break;
  8882. -
  8883. - // Uninitialized_variable_info {
  8884. - // u1 tag = ITEM_Uninitialized; /* 8 */
  8885. - // u2 offset;
  8886. - // }
  8887. - case ITEM_Uninitialized:
  8888. - assert(stackmap_p_ref + 2 <= stackmap_end, "no room for offset");
  8889. - stackmap_p_ref += 2;
  8890. - break;
  8891. -
  8892. - default:
  8893. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  8894. - ("frame_i=%u, frame_type=%u, bad tag=0x%x", frame_i, frame_type, tag));
  8895. - ShouldNotReachHere();
  8896. - break;
  8897. - } // end switch (tag)
  8898. -} // end rewrite_cp_refs_in_verification_type_info()
  8899. -
  8900. -
  8901. -// Change the constant pool associated with klass scratch_class to
  8902. -// scratch_cp. If shrink is true, then scratch_cp_length elements
  8903. -// are copied from scratch_cp to a smaller constant pool and the
  8904. -// smaller constant pool is associated with scratch_class.
  8905. -void VM_RedefineClasses::set_new_constant_pool(
  8906. - instanceKlassHandle scratch_class, constantPoolHandle scratch_cp,
  8907. - int scratch_cp_length, bool shrink, TRAPS) {
  8908. - assert(!shrink || scratch_cp->length() >= scratch_cp_length, "sanity check");
  8909. -
  8910. - if (shrink) {
  8911. - // scratch_cp is a merged constant pool and has enough space for a
  8912. - // worst case merge situation. We want to associate the minimum
  8913. - // sized constant pool with the klass to save space.
  8914. - constantPoolHandle smaller_cp(THREAD,
  8915. - oopFactory::new_constantPool(scratch_cp_length,
  8916. - oopDesc::IsUnsafeConc,
  8917. - THREAD));
  8918. - // preserve orig_length() value in the smaller copy
  8919. - int orig_length = scratch_cp->orig_length();
  8920. - assert(orig_length != 0, "sanity check");
  8921. - smaller_cp->set_orig_length(orig_length);
  8922. - scratch_cp->copy_cp_to(1, scratch_cp_length - 1, smaller_cp, 1, THREAD);
  8923. - scratch_cp = smaller_cp;
  8924. - smaller_cp()->set_is_conc_safe(true);
  8925. - }
  8926. -
  8927. - // attach new constant pool to klass
  8928. - scratch_cp->set_pool_holder(scratch_class());
  8929. -
  8930. - // attach klass to new constant pool
  8931. - scratch_class->set_constants(scratch_cp());
  8932. -
  8933. - int i; // for portability
  8934. -
  8935. - // update each field in klass to use new constant pool indices as needed
  8936. - for (JavaFieldStream fs(scratch_class); !fs.done(); fs.next()) {
  8937. - jshort cur_index = fs.name_index();
  8938. - jshort new_index = find_new_index(cur_index);
  8939. - if (new_index != 0) {
  8940. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8941. - ("field-name_index change: %d to %d", cur_index, new_index));
  8942. - fs.set_name_index(new_index);
  8943. - }
  8944. - cur_index = fs.signature_index();
  8945. - new_index = find_new_index(cur_index);
  8946. - if (new_index != 0) {
  8947. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8948. - ("field-signature_index change: %d to %d", cur_index, new_index));
  8949. - fs.set_signature_index(new_index);
  8950. - }
  8951. - cur_index = fs.initval_index();
  8952. - new_index = find_new_index(cur_index);
  8953. - if (new_index != 0) {
  8954. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8955. - ("field-initval_index change: %d to %d", cur_index, new_index));
  8956. - fs.set_initval_index(new_index);
  8957. - }
  8958. - cur_index = fs.generic_signature_index();
  8959. - new_index = find_new_index(cur_index);
  8960. - if (new_index != 0) {
  8961. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8962. - ("field-generic_signature change: %d to %d", cur_index, new_index));
  8963. - fs.set_generic_signature_index(new_index);
  8964. - }
  8965. - } // end for each field
  8966. -
  8967. - // Update constant pool indices in the inner classes info to use
  8968. - // new constant indices as needed. The inner classes info is a
  8969. - // quadruple:
  8970. - // (inner_class_info, outer_class_info, inner_name, inner_access_flags)
  8971. - InnerClassesIterator iter(scratch_class);
  8972. - for (; !iter.done(); iter.next()) {
  8973. - int cur_index = iter.inner_class_info_index();
  8974. - if (cur_index == 0) {
  8975. - continue; // JVM spec. allows null inner class refs so skip it
  8976. - }
  8977. - int new_index = find_new_index(cur_index);
  8978. - if (new_index != 0) {
  8979. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8980. - ("inner_class_info change: %d to %d", cur_index, new_index));
  8981. - iter.set_inner_class_info_index(new_index);
  8982. - }
  8983. - cur_index = iter.outer_class_info_index();
  8984. - new_index = find_new_index(cur_index);
  8985. - if (new_index != 0) {
  8986. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8987. - ("outer_class_info change: %d to %d", cur_index, new_index));
  8988. - iter.set_outer_class_info_index(new_index);
  8989. - }
  8990. - cur_index = iter.inner_name_index();
  8991. - new_index = find_new_index(cur_index);
  8992. - if (new_index != 0) {
  8993. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8994. - ("inner_name change: %d to %d", cur_index, new_index));
  8995. - iter.set_inner_name_index(new_index);
  8996. - }
  8997. - } // end for each inner class
  8998. -
  8999. - // Attach each method in klass to the new constant pool and update
  9000. - // to use new constant pool indices as needed:
  9001. - objArrayHandle methods(THREAD, scratch_class->methods());
  9002. - for (i = methods->length() - 1; i >= 0; i--) {
  9003. - methodHandle method(THREAD, (methodOop)methods->obj_at(i));
  9004. - method->set_constants(scratch_cp());
  9005. -
  9006. - int new_index = find_new_index(method->name_index());
  9007. - if (new_index != 0) {
  9008. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  9009. - ("method-name_index change: %d to %d", method->name_index(),
  9010. - new_index));
  9011. - method->set_name_index(new_index);
  9012. - }
  9013. - new_index = find_new_index(method->signature_index());
  9014. - if (new_index != 0) {
  9015. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  9016. - ("method-signature_index change: %d to %d",
  9017. - method->signature_index(), new_index));
  9018. - method->set_signature_index(new_index);
  9019. - }
  9020. - new_index = find_new_index(method->generic_signature_index());
  9021. - if (new_index != 0) {
  9022. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  9023. - ("method-generic_signature_index change: %d to %d",
  9024. - method->generic_signature_index(), new_index));
  9025. - method->set_generic_signature_index(new_index);
  9026. - }
  9027. -
  9028. - // Update constant pool indices in the method's checked exception
  9029. - // table to use new constant indices as needed.
  9030. - int cext_length = method->checked_exceptions_length();
  9031. - if (cext_length > 0) {
  9032. - CheckedExceptionElement * cext_table =
  9033. - method->checked_exceptions_start();
  9034. - for (int j = 0; j < cext_length; j++) {
  9035. - int cur_index = cext_table[j].class_cp_index;
  9036. - int new_index = find_new_index(cur_index);
  9037. - if (new_index != 0) {
  9038. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  9039. - ("cext-class_cp_index change: %d to %d", cur_index, new_index));
  9040. - cext_table[j].class_cp_index = (u2)new_index;
  9041. - }
  9042. - } // end for each checked exception table entry
  9043. - } // end if there are checked exception table entries
  9044. -
  9045. - // Update each catch type index in the method's exception table
  9046. - // to use new constant pool indices as needed. The exception table
  9047. - // holds quadruple entries of the form:
  9048. - // (beg_bci, end_bci, handler_bci, klass_index)
  9049. -
  9050. - ExceptionTable ex_table(method());
  9051. - int ext_length = ex_table.length();
  9052. -
  9053. - for (int j = 0; j < ext_length; j ++) {
  9054. - int cur_index = ex_table.catch_type_index(j);
  9055. - int new_index = find_new_index(cur_index);
  9056. - if (new_index != 0) {
  9057. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  9058. - ("ext-klass_index change: %d to %d", cur_index, new_index));
  9059. - ex_table.set_catch_type_index(j, new_index);
  9060. - }
  9061. - } // end for each exception table entry
  9062. -
  9063. - // Update constant pool indices in the method's local variable
  9064. - // table to use new constant indices as needed. The local variable
  9065. - // table hold sextuple entries of the form:
  9066. - // (start_pc, length, name_index, descriptor_index, signature_index, slot)
  9067. - int lvt_length = method->localvariable_table_length();
  9068. - if (lvt_length > 0) {
  9069. - LocalVariableTableElement * lv_table =
  9070. - method->localvariable_table_start();
  9071. - for (int j = 0; j < lvt_length; j++) {
  9072. - int cur_index = lv_table[j].name_cp_index;
  9073. - int new_index = find_new_index(cur_index);
  9074. - if (new_index != 0) {
  9075. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  9076. - ("lvt-name_cp_index change: %d to %d", cur_index, new_index));
  9077. - lv_table[j].name_cp_index = (u2)new_index;
  9078. - }
  9079. - cur_index = lv_table[j].descriptor_cp_index;
  9080. - new_index = find_new_index(cur_index);
  9081. - if (new_index != 0) {
  9082. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  9083. - ("lvt-descriptor_cp_index change: %d to %d", cur_index,
  9084. - new_index));
  9085. - lv_table[j].descriptor_cp_index = (u2)new_index;
  9086. - }
  9087. - cur_index = lv_table[j].signature_cp_index;
  9088. - new_index = find_new_index(cur_index);
  9089. - if (new_index != 0) {
  9090. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  9091. - ("lvt-signature_cp_index change: %d to %d", cur_index, new_index));
  9092. - lv_table[j].signature_cp_index = (u2)new_index;
  9093. - }
  9094. - } // end for each local variable table entry
  9095. - } // end if there are local variable table entries
  9096. -
  9097. - rewrite_cp_refs_in_stack_map_table(method, THREAD);
  9098. - } // end for each method
  9099. - assert(scratch_cp()->is_conc_safe(), "Just checking");
  9100. -} // end set_new_constant_pool()
  9101. -
  9102. -
  9103. -// Unevolving classes may point to methods of the_class directly
  9104. +// Unevolving classes may point to old methods directly
  9105. // from their constant pool caches, itables, and/or vtables. We
  9106. // use the SystemDictionary::classes_do() facility and this helper
  9107. -// to fix up these pointers.
  9108. +// to fix up these pointers. Additional field offsets and vtable indices
  9109. +// in the constant pool cache entries are fixed.
  9110. //
  9111. // Note: We currently don't support updating the vtable in
  9112. // arrayKlassOops. See Open Issues in jvmtiRedefineClasses.hpp.
  9113. -void VM_RedefineClasses::adjust_cpool_cache_and_vtable(klassOop k_oop,
  9114. - oop initiating_loader, TRAPS) {
  9115. +void VM_RedefineClasses::adjust_cpool_cache(klassOop k_oop_latest, oop initiating_loader, TRAPS) {
  9116. + klassOop k_oop = k_oop_latest;
  9117. + while (k_oop != NULL) {
  9118. + //tty->print_cr("name=%s", k_oop->klass_part()->name()->as_C_string());
  9119. +/*
  9120. + methodOop *matching_old_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  9121. + methodOop *matching_new_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  9122. +
  9123. + for (int i=0; i<_matching_methods_length; i++) {
  9124. + matching_old_methods[i] = (methodOop)_old_methods->obj_at(_matching_old_methods[i]);
  9125. + matching_new_methods[i] = (methodOop)_new_methods->obj_at(_matching_new_methods[i]);
  9126. + }*/
  9127. +
  9128. + Klass *k = k_oop->klass_part();
  9129. + if (k->oop_is_instance()) {
  9130. + HandleMark hm(THREAD);
  9131. + instanceKlass *ik = (instanceKlass *) k;
  9132. +
  9133. + constantPoolHandle other_cp;
  9134. + constantPoolCacheOop cp_cache;
  9135. +
  9136. + other_cp = constantPoolHandle(ik->constants());
  9137. +
  9138. + for (int i=0; i<other_cp->length(); i++) {
  9139. + if (other_cp->tag_at(i).is_klass()) {
  9140. + klassOop klass = other_cp->klass_at(i, THREAD);
  9141. + if (klass->klass_part()->new_version() != NULL) {
  9142. +
  9143. + // (tw) TODO: check why/if this is necessary
  9144. + other_cp->klass_at_put(i, klass->klass_part()->new_version());
  9145. + }
  9146. + klass = other_cp->klass_at(i, THREAD);
  9147. + assert(klass->klass_part()->new_version() == NULL, "Must be new klass!");
  9148. + }
  9149. + }
  9150. +
  9151. + cp_cache = other_cp->cache();
  9152. +
  9153. + if (cp_cache != NULL) {
  9154. + cp_cache->adjust_entries(NULL,
  9155. + NULL,
  9156. + 0);
  9157. + }
  9158. +
  9159. + // If bytecode rewriting is enabled, we also need to unpatch bytecode to force resolution of zeroied entries
  9160. + if (RewriteBytecodes) {
  9161. + ik->methods_do(unpatch_bytecode);
  9162. + }
  9163. + }
  9164. + k_oop = k_oop->klass_part()->old_version();
  9165. + }
  9166. +}
  9167. +
  9168. +void VM_RedefineClasses::update_jmethod_ids() {
  9169. + for (int j = 0; j < _matching_methods_length; ++j) {
  9170. + methodOop old_method = (methodOop)_old_methods->obj_at(_matching_old_methods[j]);
  9171. + RC_TRACE(0x00008000, ("matching method %s", old_method->name_and_sig_as_C_string()));
  9172. +
  9173. + jmethodID jmid = old_method->find_jmethod_id_or_null();
  9174. + if (old_method->new_version() != NULL && jmid == NULL) {
  9175. + // (tw) Have to create jmethodID in this case
  9176. + jmid = old_method->jmethod_id();
  9177. + }
  9178. +
  9179. + if (jmid != NULL) {
  9180. + // There is a jmethodID, change it to point to the new method
  9181. + methodHandle new_method_h((methodOop)_new_methods->obj_at(_matching_new_methods[j]));
  9182. + if (old_method->new_version() == NULL) {
  9183. + methodHandle old_method_h((methodOop)_old_methods->obj_at(_matching_old_methods[j]));
  9184. + jmethodID new_jmethod_id = JNIHandles::make_jmethod_id(old_method_h);
  9185. + bool result = instanceKlass::cast(old_method_h->method_holder())->update_jmethod_id(old_method_h(), new_jmethod_id);
  9186. + //RC_TRACE(0x00008000, ("Changed jmethodID for old method assigned to %d / result=%d", new_jmethod_id, result);
  9187. + //RC_TRACE(0x00008000, ("jmethodID new method: %d jmethodID old method: %d", new_method_h->jmethod_id(), old_method->jmethod_id());
  9188. + } else {
  9189. + jmethodID mid = new_method_h->jmethod_id();
  9190. + bool result = instanceKlass::cast(new_method_h->method_holder())->update_jmethod_id(new_method_h(), jmid);
  9191. + //RC_TRACE(0x00008000, ("Changed jmethodID for new method assigned to %d / result=%d", jmid, result);
  9192. +
  9193. + }
  9194. + JNIHandles::change_method_associated_with_jmethod_id(jmid, new_method_h);
  9195. + //RC_TRACE(0x00008000, ("changing method associated with jmethod id %d to %s", (int)jmid, new_method_h->name()->as_C_string());
  9196. + assert(JNIHandles::resolve_jmethod_id(jmid) == (methodOop)_new_methods->obj_at(_matching_new_methods[j]), "should be replaced");
  9197. + jmethodID mid = ((methodOop)_new_methods->obj_at(_matching_new_methods[j]))->jmethod_id();
  9198. + assert(JNIHandles::resolve_non_null((jobject)mid) == new_method_h(), "must match!");
  9199. +
  9200. + //RC_TRACE(0x00008000, ("jmethodID new method: %d jmethodID old method: %d", new_method_h->jmethod_id(), old_method->jmethod_id());
  9201. + }
  9202. + }
  9203. +}
  9204. +
  9205. +
  9206. +// Deoptimize all compiled code that depends on this class.
  9207. +//
  9208. +// If the can_redefine_classes capability is obtained in the onload
  9209. +// phase then the compiler has recorded all dependencies from startup.
  9210. +// In that case we need only deoptimize and throw away all compiled code
  9211. +// that depends on the class.
  9212. +//
  9213. +// If can_redefine_classes is obtained sometime after the onload
  9214. +// phase then the dependency information may be incomplete. In that case
  9215. +// the first call to RedefineClasses causes all compiled code to be
  9216. +// thrown away. As can_redefine_classes has been obtained then
  9217. +// all future compilations will record dependencies so second and
  9218. +// subsequent calls to RedefineClasses need only throw away code
  9219. +// that depends on the class.
  9220. +//
  9221. +void VM_RedefineClasses::flush_dependent_code(instanceKlassHandle k_h, TRAPS) {
  9222. + assert_locked_or_safepoint(Compile_lock);
  9223. +
  9224. + // All dependencies have been recorded from startup or this is a second or
  9225. + // subsequent use of RedefineClasses
  9226. +
  9227. + // For now deopt all
  9228. + // (tw) TODO: Improve the dependency system such that we can safely deopt only a subset of the methods
  9229. + if (0 && JvmtiExport::all_dependencies_are_recorded()) {
  9230. + Universe::flush_evol_dependents_on(k_h);
  9231. + } else {
  9232. + CodeCache::mark_all_nmethods_for_deoptimization();
  9233. +
  9234. + ResourceMark rm(THREAD);
  9235. + DeoptimizationMarker dm;
  9236. +
  9237. + // Deoptimize all activations depending on marked nmethods
  9238. + Deoptimization::deoptimize_dependents();
  9239. +
  9240. + // Make the dependent methods not entrant (in VM_Deoptimize they are made zombies)
  9241. + CodeCache::make_marked_nmethods_not_entrant();
  9242. +
  9243. + // From now on we know that the dependency information is complete
  9244. + JvmtiExport::set_all_dependencies_are_recorded(true);
  9245. + }
  9246. +}
  9247. +
  9248. +void VM_RedefineClasses::compute_added_deleted_matching_methods() {
  9249. + methodOop old_method;
  9250. + methodOop new_method;
  9251. +
  9252. + _matching_old_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  9253. + _matching_new_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  9254. + _added_methods = NEW_RESOURCE_ARRAY(int, _new_methods->length());
  9255. + _deleted_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  9256. +
  9257. + _matching_methods_length = 0;
  9258. + _deleted_methods_length = 0;
  9259. + _added_methods_length = 0;
  9260. +
  9261. + int nj = 0;
  9262. + int oj = 0;
  9263. + while (true) {
  9264. + if (oj >= _old_methods->length()) {
  9265. + if (nj >= _new_methods->length()) {
  9266. + break; // we've looked at everything, done
  9267. + }
  9268. + // New method at the end
  9269. + new_method = (methodOop) _new_methods->obj_at(nj);
  9270. + _added_methods[_added_methods_length++] = nj;
  9271. + ++nj;
  9272. + } else if (nj >= _new_methods->length()) {
  9273. + // Old method, at the end, is deleted
  9274. + old_method = (methodOop) _old_methods->obj_at(oj);
  9275. + _deleted_methods[_deleted_methods_length++] = oj;
  9276. + ++oj;
  9277. + } else {
  9278. + old_method = (methodOop) _old_methods->obj_at(oj);
  9279. + new_method = (methodOop) _new_methods->obj_at(nj);
  9280. + if (old_method->name() == new_method->name()) {
  9281. + if (old_method->signature() == new_method->signature()) {
  9282. + _matching_old_methods[_matching_methods_length ] = oj;//old_method;
  9283. + _matching_new_methods[_matching_methods_length++] = nj;//new_method;
  9284. + ++nj;
  9285. + ++oj;
  9286. + } else {
  9287. + // added overloaded have already been moved to the end,
  9288. + // so this is a deleted overloaded method
  9289. + _deleted_methods[_deleted_methods_length++] = oj;//old_method;
  9290. + ++oj;
  9291. + }
  9292. + } else { // names don't match
  9293. + if (old_method->name()->fast_compare(new_method->name()) > 0) {
  9294. + // new method
  9295. + _added_methods[_added_methods_length++] = nj;//new_method;
  9296. + ++nj;
  9297. + } else {
  9298. + // deleted method
  9299. + _deleted_methods[_deleted_methods_length++] = oj;//old_method;
  9300. + ++oj;
  9301. + }
  9302. + }
  9303. + }
  9304. + }
  9305. + assert(_matching_methods_length + _deleted_methods_length == _old_methods->length(), "sanity");
  9306. + assert(_matching_methods_length + _added_methods_length == _new_methods->length(), "sanity");
  9307. + RC_TRACE(0x00008000, ("Matching methods = %d / deleted methods = %d / added methods = %d",
  9308. + _matching_methods_length, _deleted_methods_length, _added_methods_length));
  9309. +}
  9310. +
  9311. +
  9312. +
  9313. +// Install the redefinition of a class:
  9314. +// - house keeping (flushing breakpoints and caches, deoptimizing
  9315. +// dependent compiled code)
  9316. +// - adjusting constant pool caches and vtables in other classes
  9317. +void VM_RedefineClasses::redefine_single_class(instanceKlassHandle the_new_class, TRAPS) {
  9318. +
  9319. + ResourceMark rm(THREAD);
  9320. +
  9321. + assert(the_new_class->old_version() != NULL, "Must not be null");
  9322. + assert(the_new_class->old_version()->klass_part()->new_version() == the_new_class(), "Must equal");
  9323. +
  9324. + instanceKlassHandle the_old_class = instanceKlassHandle(THREAD, the_new_class->old_version());
  9325. +
  9326. +#ifndef JVMTI_KERNEL
  9327. + // Remove all breakpoints in methods of this class
  9328. + JvmtiBreakpoints& jvmti_breakpoints = JvmtiCurrentBreakpoints::get_jvmti_breakpoints();
  9329. + jvmti_breakpoints.clearall_in_class_at_safepoint(the_old_class());
  9330. +#endif // !JVMTI_KERNEL
  9331. +
  9332. + if (the_old_class() == Universe::reflect_invoke_cache()->klass()) {
  9333. + // We are redefining java.lang.reflect.Method. Method.invoke() is
  9334. + // cached and users of the cache care about each active version of
  9335. + // the method so we have to track this previous version.
  9336. + // Do this before methods get switched
  9337. + Universe::reflect_invoke_cache()->add_previous_version(
  9338. + the_old_class->method_with_idnum(Universe::reflect_invoke_cache()->method_idnum()));
  9339. + }
  9340. +
  9341. + _old_methods = the_old_class->methods();
  9342. + _new_methods = the_new_class->methods();
  9343. + _the_class_oop = the_old_class();
  9344. + compute_added_deleted_matching_methods();
  9345. +
  9346. + // track which methods are EMCP for add_previous_version() call below
  9347. +
  9348. + // (tw) TODO: Check if we need the concept of EMCP?
  9349. + BitMap emcp_methods(_old_methods->length());
  9350. + int emcp_method_count = 0;
  9351. + emcp_methods.clear(); // clears 0..(length() - 1)
  9352. +
  9353. + // We need to mark methods as old!!
  9354. + check_methods_and_mark_as_obsolete(&emcp_methods, &emcp_method_count);
  9355. + update_jmethod_ids();
  9356. +
  9357. + // keep track of previous versions of this class
  9358. + the_new_class->add_previous_version(the_old_class, &emcp_methods,
  9359. + emcp_method_count);
  9360. +
  9361. + // TODO:
  9362. + transfer_old_native_function_registrations(the_old_class);
  9363. +
  9364. +
  9365. +#ifdef ASSERT
  9366. +
  9367. +// klassOop systemLookup1 = SystemDictionary::resolve_or_null(the_old_class->name(), the_old_class->class_loader(), the_old_class->protection_domain(), THREAD);
  9368. +// assert(systemLookup1 == the_new_class(), "New class must be in system dictionary!");
  9369. +
  9370. + //JNIHandles::verify();
  9371. +
  9372. +// klassOop systemLookup = SystemDictionary::resolve_or_null(the_old_class->name(), the_old_class->class_loader(), the_old_class->protection_domain(), THREAD);
  9373. +
  9374. +// assert(systemLookup == the_new_class(), "New class must be in system dictionary!");
  9375. + assert(the_new_class->old_version() != NULL, "Must not be null");
  9376. + assert(the_new_class->old_version()->klass_part()->new_version() == the_new_class(), "Must equal");
  9377. +
  9378. + for (int i=0; i<the_new_class->methods()->length(); i++) {
  9379. + assert(((methodOop)the_new_class->methods()->obj_at(i))->method_holder() == the_new_class(), "method holder must match!");
  9380. + }
  9381. +
  9382. + _old_methods->verify();
  9383. + _new_methods->verify();
  9384. +
  9385. + the_new_class->vtable()->verify(tty);
  9386. + the_old_class->vtable()->verify(tty);
  9387. +
  9388. +#endif
  9389. +
  9390. + // increment the classRedefinedCount field in the_class and in any
  9391. + // direct and indirect subclasses of the_class
  9392. + increment_class_counter((instanceKlass *)the_old_class()->klass_part(), THREAD);
  9393. +
  9394. +}
  9395. +
  9396. +
  9397. +void VM_RedefineClasses::check_methods_and_mark_as_obsolete(BitMap *emcp_methods, int * emcp_method_count_p) {
  9398. + RC_TRACE(0x00008000, ("Checking matching methods for EMCP"));
  9399. + *emcp_method_count_p = 0;
  9400. + int obsolete_count = 0;
  9401. + int old_index = 0;
  9402. + for (int j = 0; j < _matching_methods_length; ++j, ++old_index) {
  9403. + methodOop old_method = (methodOop)_old_methods->obj_at(_matching_old_methods[j]);
  9404. + methodOop new_method = (methodOop)_new_methods->obj_at(_matching_new_methods[j]);
  9405. + methodOop old_array_method;
  9406. +
  9407. + // Maintain an old_index into the _old_methods array by skipping
  9408. + // deleted methods
  9409. + while ((old_array_method = (methodOop) _old_methods->obj_at(old_index))
  9410. + != old_method) {
  9411. + ++old_index;
  9412. + }
  9413. +
  9414. + if (MethodComparator::methods_EMCP(old_method, new_method)) {
  9415. + // The EMCP definition from JSR-163 requires the bytecodes to be
  9416. + // the same with the exception of constant pool indices which may
  9417. + // differ. However, the constants referred to by those indices
  9418. + // must be the same.
  9419. + //
  9420. + // We use methods_EMCP() for comparison since constant pool
  9421. + // merging can remove duplicate constant pool entries that were
  9422. + // present in the old method and removed from the rewritten new
  9423. + // method. A faster binary comparison function would consider the
  9424. + // old and new methods to be different when they are actually
  9425. + // EMCP.
  9426. +
  9427. + // track which methods are EMCP for add_previous_version() call
  9428. + emcp_methods->set_bit(old_index);
  9429. + (*emcp_method_count_p)++;
  9430. +
  9431. + // An EMCP method is _not_ obsolete. An obsolete method has a
  9432. + // different jmethodID than the current method. An EMCP method
  9433. + // has the same jmethodID as the current method. Having the
  9434. + // same jmethodID for all EMCP versions of a method allows for
  9435. + // a consistent view of the EMCP methods regardless of which
  9436. + // EMCP method you happen to have in hand. For example, a
  9437. + // breakpoint set in one EMCP method will work for all EMCP
  9438. + // versions of the method including the current one.
  9439. +
  9440. + old_method->set_new_version(new_method);
  9441. + new_method->set_old_version(old_method);
  9442. +
  9443. + RC_TRACE(0x00008000, ("Found EMCP method %s", old_method->name_and_sig_as_C_string()));
  9444. +
  9445. + // Transfer breakpoints
  9446. + instanceKlass *ik = instanceKlass::cast(old_method->method_holder());
  9447. + for (BreakpointInfo* bp = ik->breakpoints(); bp != NULL; bp = bp->next()) {
  9448. + RC_TRACE(0x00000002, ("Checking breakpoint"));
  9449. + RC_TRACE(0x00000002, ("%d / %d",
  9450. + bp->match(old_method), bp->match(new_method)));
  9451. + if (bp->match(old_method)) {
  9452. + assert(bp->match(new_method), "if old method is method, then new method must match too");
  9453. + RC_TRACE(0x00000002, ("Found a breakpoint in an old EMCP method"));
  9454. + new_method->set_breakpoint(bp->bci());
  9455. + }
  9456. + }
  9457. +
  9458. +
  9459. +
  9460. + } else {
  9461. + // mark obsolete methods as such
  9462. + old_method->set_is_obsolete();
  9463. + obsolete_count++;
  9464. +
  9465. + // With tracing we try not to "yack" too much. The position of
  9466. + // this trace assumes there are fewer obsolete methods than
  9467. + // EMCP methods.
  9468. + RC_TRACE(0x00008000, ("mark %s(%s) as obsolete",
  9469. + old_method->name()->as_C_string(),
  9470. + old_method->signature()->as_C_string()));
  9471. + }
  9472. + old_method->set_is_old();
  9473. + }
  9474. + for (int i = 0; i < _deleted_methods_length; ++i) {
  9475. + methodOop old_method = (methodOop)_old_methods->obj_at(_deleted_methods[i]);
  9476. +
  9477. + //assert(old_method->vtable_index() < 0,
  9478. + // "cannot delete methods with vtable entries");;
  9479. +
  9480. + // Mark all deleted methods as old and obsolete
  9481. + old_method->set_is_old();
  9482. + old_method->set_is_obsolete();
  9483. + ++obsolete_count;
  9484. + // With tracing we try not to "yack" too much. The position of
  9485. + // this trace assumes there are fewer obsolete methods than
  9486. + // EMCP methods.
  9487. + RC_TRACE(0x00008000, ("mark deleted %s(%s) as obsolete",
  9488. + old_method->name()->as_C_string(),
  9489. + old_method->signature()->as_C_string()));
  9490. + }
  9491. + //assert((*emcp_method_count_p + obsolete_count) == _old_methods->length(), "sanity check");
  9492. + RC_TRACE(0x00008000, ("EMCP_cnt=%d, obsolete_cnt=%d !", *emcp_method_count_p, obsolete_count));
  9493. +}
  9494. +
  9495. +// Increment the classRedefinedCount field in the specific instanceKlass
  9496. +// and in all direct and indirect subclasses.
  9497. +void VM_RedefineClasses::increment_class_counter(instanceKlass *ik, TRAPS) {
  9498. + oop class_mirror = ik->java_mirror();
  9499. + klassOop class_oop = java_lang_Class::as_klassOop(class_mirror);
  9500. + int new_count = java_lang_Class::classRedefinedCount(class_mirror) + 1;
  9501. + java_lang_Class::set_classRedefinedCount(class_mirror, new_count);
  9502. + RC_TRACE(0x00008000, ("updated count for class=%s to %d", ik->external_name(), new_count));
  9503. +}
  9504. +
  9505. +#ifndef PRODUCT
  9506. +void VM_RedefineClasses::check_class(klassOop k_oop, TRAPS) {
  9507. Klass *k = k_oop->klass_part();
  9508. if (k->oop_is_instance()) {
  9509. HandleMark hm(THREAD);
  9510. instanceKlass *ik = (instanceKlass *) k;
  9511. -
  9512. - // HotSpot specific optimization! HotSpot does not currently
  9513. - // support delegation from the bootstrap class loader to a
  9514. - // user-defined class loader. This means that if the bootstrap
  9515. - // class loader is the initiating class loader, then it will also
  9516. - // be the defining class loader. This also means that classes
  9517. - // loaded by the bootstrap class loader cannot refer to classes
  9518. - // loaded by a user-defined class loader. Note: a user-defined
  9519. - // class loader can delegate to the bootstrap class loader.
  9520. - //
  9521. - // If the current class being redefined has a user-defined class
  9522. - // loader as its defining class loader, then we can skip all
  9523. - // classes loaded by the bootstrap class loader.
  9524. - bool is_user_defined =
  9525. - instanceKlass::cast(_the_class_oop)->class_loader() != NULL;
  9526. - if (is_user_defined && ik->class_loader() == NULL) {
  9527. - return;
  9528. - }
  9529. -
  9530. - // This is a very busy routine. We don't want too much tracing
  9531. - // printed out.
  9532. - bool trace_name_printed = false;
  9533. -
  9534. - // Very noisy: only enable this call if you are trying to determine
  9535. - // that a specific class gets found by this routine.
  9536. - // RC_TRACE macro has an embedded ResourceMark
  9537. - // RC_TRACE_WITH_THREAD(0x00100000, THREAD,
  9538. - // ("adjust check: name=%s", ik->external_name()));
  9539. - // trace_name_printed = true;
  9540. -
  9541. - // Fix the vtable embedded in the_class and subclasses of the_class,
  9542. - // if one exists. We discard scratch_class and we don't keep an
  9543. - // instanceKlass around to hold obsolete methods so we don't have
  9544. - // any other instanceKlass embedded vtables to update. The vtable
  9545. - // holds the methodOops for virtual (but not final) methods.
  9546. - if (ik->vtable_length() > 0 && ik->is_subtype_of(_the_class_oop)) {
  9547. - // ik->vtable() creates a wrapper object; rm cleans it up
  9548. + assert(ik->is_newest_version(), "must be latest version in system dictionary");
  9549. +
  9550. + if (ik->vtable_length() > 0) {
  9551. ResourceMark rm(THREAD);
  9552. - ik->vtable()->adjust_method_entries(_matching_old_methods,
  9553. - _matching_new_methods,
  9554. - _matching_methods_length,
  9555. - &trace_name_printed);
  9556. - }
  9557. -
  9558. - // If the current class has an itable and we are either redefining an
  9559. - // interface or if the current class is a subclass of the_class, then
  9560. - // we potentially have to fix the itable. If we are redefining an
  9561. - // interface, then we have to call adjust_method_entries() for
  9562. - // every instanceKlass that has an itable since there isn't a
  9563. - // subclass relationship between an interface and an instanceKlass.
  9564. - if (ik->itable_length() > 0 && (Klass::cast(_the_class_oop)->is_interface()
  9565. - || ik->is_subclass_of(_the_class_oop))) {
  9566. - // ik->itable() creates a wrapper object; rm cleans it up
  9567. - ResourceMark rm(THREAD);
  9568. - ik->itable()->adjust_method_entries(_matching_old_methods,
  9569. - _matching_new_methods,
  9570. - _matching_methods_length,
  9571. - &trace_name_printed);
  9572. - }
  9573. -
  9574. - // The constant pools in other classes (other_cp) can refer to
  9575. - // methods in the_class. We have to update method information in
  9576. - // other_cp's cache. If other_cp has a previous version, then we
  9577. - // have to repeat the process for each previous version. The
  9578. - // constant pool cache holds the methodOops for non-virtual
  9579. - // methods and for virtual, final methods.
  9580. - //
  9581. - // Special case: if the current class is the_class, then new_cp
  9582. - // has already been attached to the_class and old_cp has already
  9583. - // been added as a previous version. The new_cp doesn't have any
  9584. - // cached references to old methods so it doesn't need to be
  9585. - // updated. We can simply start with the previous version(s) in
  9586. - // that case.
  9587. - constantPoolHandle other_cp;
  9588. - constantPoolCacheOop cp_cache;
  9589. -
  9590. - if (k_oop != _the_class_oop) {
  9591. - // this klass' constant pool cache may need adjustment
  9592. - other_cp = constantPoolHandle(ik->constants());
  9593. - cp_cache = other_cp->cache();
  9594. - if (cp_cache != NULL) {
  9595. - cp_cache->adjust_method_entries(_matching_old_methods,
  9596. - _matching_new_methods,
  9597. - _matching_methods_length,
  9598. - &trace_name_printed);
  9599. + if (!ik->vtable()->check_no_old_entries()) {
  9600. + RC_TRACE(0x00000001, ("size of class: %d\n",
  9601. + k_oop->size()));
  9602. + RC_TRACE(0x00000001, ("klassVtable::check_no_old_entries failure -- OLD method found -- class: %s",
  9603. + ik->signature_name()));
  9604. + assert(false, "OLD method found");
  9605. }
  9606. - }
  9607. - {
  9608. - ResourceMark rm(THREAD);
  9609. - // PreviousVersionInfo objects returned via PreviousVersionWalker
  9610. - // contain a GrowableArray of handles. We have to clean up the
  9611. - // GrowableArray _after_ the PreviousVersionWalker destructor
  9612. - // has destroyed the handles.
  9613. - {
  9614. - // the previous versions' constant pool caches may need adjustment
  9615. - PreviousVersionWalker pvw(ik);
  9616. - for (PreviousVersionInfo * pv_info = pvw.next_previous_version();
  9617. - pv_info != NULL; pv_info = pvw.next_previous_version()) {
  9618. - other_cp = pv_info->prev_constant_pool_handle();
  9619. - cp_cache = other_cp->cache();
  9620. - if (cp_cache != NULL) {
  9621. - cp_cache->adjust_method_entries(_matching_old_methods,
  9622. - _matching_new_methods,
  9623. - _matching_methods_length,
  9624. - &trace_name_printed);
  9625. - }
  9626. - }
  9627. - } // pvw is cleaned up
  9628. - } // rm is cleaned up
  9629. - }
  9630. -}
  9631. -
  9632. -void VM_RedefineClasses::update_jmethod_ids() {
  9633. - for (int j = 0; j < _matching_methods_length; ++j) {
  9634. - methodOop old_method = _matching_old_methods[j];
  9635. - jmethodID jmid = old_method->find_jmethod_id_or_null();
  9636. - if (jmid != NULL) {
  9637. - // There is a jmethodID, change it to point to the new method
  9638. - methodHandle new_method_h(_matching_new_methods[j]);
  9639. - JNIHandles::change_method_associated_with_jmethod_id(jmid, new_method_h);
  9640. - assert(JNIHandles::resolve_jmethod_id(jmid) == _matching_new_methods[j],
  9641. - "should be replaced");
  9642. +
  9643. + ik->vtable()->verify(tty, true);
  9644. }
  9645. }
  9646. }
  9647. -void VM_RedefineClasses::check_methods_and_mark_as_obsolete(
  9648. - BitMap *emcp_methods, int * emcp_method_count_p) {
  9649. - *emcp_method_count_p = 0;
  9650. - int obsolete_count = 0;
  9651. - int old_index = 0;
  9652. - for (int j = 0; j < _matching_methods_length; ++j, ++old_index) {
  9653. - methodOop old_method = _matching_old_methods[j];
  9654. - methodOop new_method = _matching_new_methods[j];
  9655. - methodOop old_array_method;
  9656. -
  9657. - // Maintain an old_index into the _old_methods array by skipping
  9658. - // deleted methods
  9659. - while ((old_array_method = (methodOop) _old_methods->obj_at(old_index))
  9660. - != old_method) {
  9661. - ++old_index;
  9662. +#endif
  9663. +
  9664. +VM_RedefineClasses::FindAffectedKlassesClosure::FindAffectedKlassesClosure( GrowableArray<instanceKlassHandle> *original_klasses, GrowableArray<instanceKlassHandle> *result )
  9665. +{
  9666. + assert(original_klasses != NULL && result != NULL, "");
  9667. + this->_original_klasses = original_klasses;
  9668. + this->_result = result;
  9669. + SystemDictionary::classes_do(this);
  9670. +}
  9671. +
  9672. +void VM_RedefineClasses::FindAffectedKlassesClosure::do_object( oop obj )
  9673. +{
  9674. + klassOop klass = (klassOop)obj;
  9675. + assert(!_result->contains(klass), "must not occur more than once!");
  9676. + assert(klass->klass_part()->new_version() == NULL, "Only last version is valid entry in system dictionary");
  9677. +
  9678. + for(int i=0; i<_original_klasses->length(); i++) {
  9679. + instanceKlassHandle cur = _original_klasses->at(i);
  9680. + if (cur() != klass && klass->klass_part()->is_subtype_of(cur()) && !_original_klasses->contains(klass)) {
  9681. + RC_TRACE(0x00008000, ("Found affected class: %s", klass->klass_part()->name()->as_C_string()));
  9682. + _result->append(klass);
  9683. + break;
  9684. }
  9685. -
  9686. - if (MethodComparator::methods_EMCP(old_method, new_method)) {
  9687. - // The EMCP definition from JSR-163 requires the bytecodes to be
  9688. - // the same with the exception of constant pool indices which may
  9689. - // differ. However, the constants referred to by those indices
  9690. - // must be the same.
  9691. - //
  9692. - // We use methods_EMCP() for comparison since constant pool
  9693. - // merging can remove duplicate constant pool entries that were
  9694. - // present in the old method and removed from the rewritten new
  9695. - // method. A faster binary comparison function would consider the
  9696. - // old and new methods to be different when they are actually
  9697. - // EMCP.
  9698. - //
  9699. - // The old and new methods are EMCP and you would think that we
  9700. - // could get rid of one of them here and now and save some space.
  9701. - // However, the concept of EMCP only considers the bytecodes and
  9702. - // the constant pool entries in the comparison. Other things,
  9703. - // e.g., the line number table (LNT) or the local variable table
  9704. - // (LVT) don't count in the comparison. So the new (and EMCP)
  9705. - // method can have a new LNT that we need so we can't just
  9706. - // overwrite the new method with the old method.
  9707. - //
  9708. - // When this routine is called, we have already attached the new
  9709. - // methods to the_class so the old methods are effectively
  9710. - // overwritten. However, if an old method is still executing,
  9711. - // then the old method cannot be collected until sometime after
  9712. - // the old method call has returned. So the overwriting of old
  9713. - // methods by new methods will save us space except for those
  9714. - // (hopefully few) old methods that are still executing.
  9715. - //
  9716. - // A method refers to a constMethodOop and this presents another
  9717. - // possible avenue to space savings. The constMethodOop in the
  9718. - // new method contains possibly new attributes (LNT, LVT, etc).
  9719. - // At first glance, it seems possible to save space by replacing
  9720. - // the constMethodOop in the old method with the constMethodOop
  9721. - // from the new method. The old and new methods would share the
  9722. - // same constMethodOop and we would save the space occupied by
  9723. - // the old constMethodOop. However, the constMethodOop contains
  9724. - // a back reference to the containing method. Sharing the
  9725. - // constMethodOop between two methods could lead to confusion in
  9726. - // the code that uses the back reference. This would lead to
  9727. - // brittle code that could be broken in non-obvious ways now or
  9728. - // in the future.
  9729. - //
  9730. - // Another possibility is to copy the constMethodOop from the new
  9731. - // method to the old method and then overwrite the new method with
  9732. - // the old method. Since the constMethodOop contains the bytecodes
  9733. - // for the method embedded in the oop, this option would change
  9734. - // the bytecodes out from under any threads executing the old
  9735. - // method and make the thread's bcp invalid. Since EMCP requires
  9736. - // that the bytecodes be the same modulo constant pool indices, it
  9737. - // is straight forward to compute the correct new bcp in the new
  9738. - // constMethodOop from the old bcp in the old constMethodOop. The
  9739. - // time consuming part would be searching all the frames in all
  9740. - // of the threads to find all of the calls to the old method.
  9741. - //
  9742. - // It looks like we will have to live with the limited savings
  9743. - // that we get from effectively overwriting the old methods
  9744. - // when the new methods are attached to the_class.
  9745. -
  9746. - // track which methods are EMCP for add_previous_version() call
  9747. - emcp_methods->set_bit(old_index);
  9748. - (*emcp_method_count_p)++;
  9749. -
  9750. - // An EMCP method is _not_ obsolete. An obsolete method has a
  9751. - // different jmethodID than the current method. An EMCP method
  9752. - // has the same jmethodID as the current method. Having the
  9753. - // same jmethodID for all EMCP versions of a method allows for
  9754. - // a consistent view of the EMCP methods regardless of which
  9755. - // EMCP method you happen to have in hand. For example, a
  9756. - // breakpoint set in one EMCP method will work for all EMCP
  9757. - // versions of the method including the current one.
  9758. - } else {
  9759. - // mark obsolete methods as such
  9760. - old_method->set_is_obsolete();
  9761. - obsolete_count++;
  9762. -
  9763. - // obsolete methods need a unique idnum
  9764. - u2 num = instanceKlass::cast(_the_class_oop)->next_method_idnum();
  9765. - if (num != constMethodOopDesc::UNSET_IDNUM) {
  9766. -// u2 old_num = old_method->method_idnum();
  9767. - old_method->set_method_idnum(num);
  9768. -// TO DO: attach obsolete annotations to obsolete method's new idnum
  9769. + }
  9770. +}
  9771. +
  9772. +jvmtiError VM_RedefineClasses::do_topological_class_sorting( const jvmtiClassDefinition *class_defs, int class_count, GrowableArray<instanceKlassHandle> *affected, GrowableArray<instanceKlassHandle> *arr, TRAPS)
  9773. +{
  9774. + GrowableArray< Pair<klassOop, klassOop> > *links = new GrowableArray< Pair<klassOop, klassOop> >();
  9775. +
  9776. + for (int i=0; i<class_count; i++) {
  9777. +
  9778. + oop mirror = JNIHandles::resolve_non_null(class_defs[i].klass);
  9779. + klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
  9780. + instanceKlassHandle the_class(THREAD, the_class_oop);
  9781. + Handle the_class_loader(THREAD, the_class->class_loader());
  9782. + Handle protection_domain(THREAD, the_class->protection_domain());
  9783. +
  9784. + ClassFileStream st((u1*) class_defs[i].class_bytes,
  9785. + class_defs[i].class_byte_count, (char *)"__VM_RedefineClasses__");
  9786. + ClassFileParser cfp(&st);
  9787. +
  9788. + GrowableArray<Symbol*> symbolArr;
  9789. + RC_TRACE(0x00000002, ("Before find super symbols of class %s",
  9790. + the_class->name()->as_C_string()));
  9791. + cfp.findSuperSymbols(the_class->name(), the_class_loader, protection_domain, the_class, symbolArr, THREAD);
  9792. +
  9793. + for (int j=0; j<symbolArr.length(); j++) {
  9794. + Symbol* sym = symbolArr.at(j);
  9795. +
  9796. + RC_TRACE(0x00008000, ("Before adding link to super class %s", sym->as_C_string()));
  9797. +
  9798. + for (int k=0; k<arr->length(); k++) {
  9799. + klassOop curOop = arr->at(k)();
  9800. + // (tw) TODO: Check if we get aliasing problems with different class loaders?
  9801. + if (curOop->klass_part()->name() == sym /*&& curOop->klass_part()->class_loader() == the_class_loader()*/) {
  9802. + RC_TRACE(0x00000002, ("Found class to link"));
  9803. + links->append(Pair<klassOop, klassOop>(curOop, the_class()));
  9804. + break;
  9805. + }
  9806. }
  9807. - // With tracing we try not to "yack" too much. The position of
  9808. - // this trace assumes there are fewer obsolete methods than
  9809. - // EMCP methods.
  9810. - RC_TRACE(0x00000100, ("mark %s(%s) as obsolete",
  9811. - old_method->name()->as_C_string(),
  9812. - old_method->signature()->as_C_string()));
  9813. }
  9814. - old_method->set_is_old();
  9815. }
  9816. - for (int i = 0; i < _deleted_methods_length; ++i) {
  9817. - methodOop old_method = _deleted_methods[i];
  9818. -
  9819. - assert(old_method->vtable_index() < 0,
  9820. - "cannot delete methods with vtable entries");;
  9821. -
  9822. - // Mark all deleted methods as old and obsolete
  9823. - old_method->set_is_old();
  9824. - old_method->set_is_obsolete();
  9825. - ++obsolete_count;
  9826. - // With tracing we try not to "yack" too much. The position of
  9827. - // this trace assumes there are fewer obsolete methods than
  9828. - // EMCP methods.
  9829. - RC_TRACE(0x00000100, ("mark deleted %s(%s) as obsolete",
  9830. - old_method->name()->as_C_string(),
  9831. - old_method->signature()->as_C_string()));
  9832. +
  9833. +
  9834. + RC_TRACE(0x00000001, ("Identified links between classes! "));
  9835. +
  9836. + for (int i=0; i<affected->length(); i++) {
  9837. +
  9838. + instanceKlassHandle klass = affected->at(i);
  9839. +
  9840. + klassOop superKlass = klass->super();
  9841. + if (affected->contains(superKlass)) {
  9842. + links->append(Pair<klassOop, klassOop>(superKlass, klass()));
  9843. + }
  9844. +
  9845. + objArrayOop superInterfaces = klass->local_interfaces();
  9846. + for (int j=0; j<superInterfaces->length(); j++) {
  9847. + klassOop interfaceKlass = (klassOop)superInterfaces->obj_at(j);
  9848. + if (arr->contains(interfaceKlass)) {
  9849. + links->append(Pair<klassOop, klassOop>(interfaceKlass, klass()));
  9850. + }
  9851. + }
  9852. }
  9853. - assert((*emcp_method_count_p + obsolete_count) == _old_methods->length(),
  9854. - "sanity check");
  9855. - RC_TRACE(0x00000100, ("EMCP_cnt=%d, obsolete_cnt=%d", *emcp_method_count_p,
  9856. - obsolete_count));
  9857. +
  9858. + if (RC_TRACE_ENABLED(0x00000002)) {
  9859. + RC_TRACE(0x00000002, ("Identified links: "));
  9860. + for (int i=0; i<links->length(); i++) {
  9861. + RC_TRACE(0x00000002, ("%s to %s",
  9862. + links->at(i).left()->klass_part()->name()->as_C_string(),
  9863. + links->at(i).right()->klass_part()->name()->as_C_string()));
  9864. + }
  9865. + }
  9866. +
  9867. + for (int i=0; i<arr->length(); i++) {
  9868. +
  9869. + int j;
  9870. + for (j=i; j<arr->length(); j++) {
  9871. +
  9872. + int k;
  9873. + for (k=0; k<links->length(); k++) {
  9874. +
  9875. + klassOop k1 = links->adr_at(k)->right();
  9876. + klassOop k2 = arr->at(j)();
  9877. + if (k1 == k2) {
  9878. + break;
  9879. + }
  9880. + }
  9881. +
  9882. + if (k == links->length()) {
  9883. + break;
  9884. + }
  9885. + }
  9886. +
  9887. + if (j == arr->length()) {
  9888. + // circle detected
  9889. + return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  9890. + }
  9891. +
  9892. + for (int k=0; k<links->length(); k++) {
  9893. + if (links->adr_at(k)->left() == arr->at(j)()) {
  9894. + links->at_put(k, links->at(links->length() - 1));
  9895. + links->remove_at(links->length() - 1);
  9896. + k--;
  9897. + }
  9898. + }
  9899. +
  9900. + instanceKlassHandle tmp = arr->at(j);
  9901. + arr->at_put(j, arr->at(i));
  9902. + arr->at_put(i, tmp);
  9903. + }
  9904. +
  9905. + return JVMTI_ERROR_NONE;
  9906. }
  9907. +void VM_RedefineClasses::oops_do(OopClosure *closure) {
  9908. +
  9909. + if (_updated_oops != NULL) {
  9910. + for (int i=0; i<_updated_oops->length(); i++) {
  9911. + closure->do_oop(_updated_oops->adr_at(i));
  9912. + }
  9913. + }
  9914. +}
  9915. +
  9916. +void VM_RedefineClasses::transfer_special_access_flags(fieldDescriptor *from, fieldDescriptor *to) {
  9917. + to->set_is_field_modification_watched(from->is_field_modification_watched());
  9918. + to->set_is_field_access_watched(from->is_field_access_watched());
  9919. + if (from->is_field_modification_watched() || from->is_field_access_watched()) {
  9920. + RC_TRACE(0x00000002, ("Transferred watch for field %s",
  9921. + from->name()->as_C_string()));
  9922. + }
  9923. + update_klass_field_access_flag(to);
  9924. +}
  9925. +
  9926. +void VM_RedefineClasses::update_klass_field_access_flag(fieldDescriptor *fd) {
  9927. + instanceKlass* ik = instanceKlass::cast(fd->field_holder());
  9928. + FieldInfo* fi = FieldInfo::from_field_array(ik->fields(), fd->index());
  9929. + fi->set_access_flags(fd->access_flags().as_short());
  9930. +}
  9931. +
  9932. +
  9933. // This internal class transfers the native function registration from old methods
  9934. // to new methods. It is designed to handle both the simple case of unchanged
  9935. // native methods and the complex cases of native method prefixes being added and/or
  9936. @@ -2832,7 +3161,7 @@
  9937. // Same, caused by prefix removal only 3_2_1_m -> 3_2_m
  9938. //
  9939. class TransferNativeFunctionRegistration {
  9940. - private:
  9941. +private:
  9942. instanceKlassHandle the_class;
  9943. int prefix_count;
  9944. char** prefixes;
  9945. @@ -2845,42 +3174,42 @@
  9946. // (2) with the prefix.
  9947. // where 'prefix' is the prefix at that 'depth' (first prefix, second prefix,...)
  9948. methodOop search_prefix_name_space(int depth, char* name_str, size_t name_len,
  9949. - Symbol* signature) {
  9950. - TempNewSymbol name_symbol = SymbolTable::probe(name_str, (int)name_len);
  9951. - if (name_symbol != NULL) {
  9952. - methodOop method = Klass::cast(the_class())->lookup_method(name_symbol, signature);
  9953. - if (method != NULL) {
  9954. - // Even if prefixed, intermediate methods must exist.
  9955. - if (method->is_native()) {
  9956. - // Wahoo, we found a (possibly prefixed) version of the method, return it.
  9957. - return method;
  9958. - }
  9959. - if (depth < prefix_count) {
  9960. - // Try applying further prefixes (other than this one).
  9961. - method = search_prefix_name_space(depth+1, name_str, name_len, signature);
  9962. - if (method != NULL) {
  9963. - return method; // found
  9964. + Symbol* signature) {
  9965. + Symbol* name_symbol = SymbolTable::probe(name_str, (int)name_len);
  9966. + if (name_symbol != NULL) {
  9967. + methodOop method = Klass::cast(the_class()->klass_part()->new_version())->lookup_method(name_symbol, signature);
  9968. + if (method != NULL) {
  9969. + // Even if prefixed, intermediate methods must exist.
  9970. + if (method->is_native()) {
  9971. + // Wahoo, we found a (possibly prefixed) version of the method, return it.
  9972. + return method;
  9973. }
  9974. -
  9975. - // Try adding this prefix to the method name and see if it matches
  9976. - // another method name.
  9977. - char* prefix = prefixes[depth];
  9978. - size_t prefix_len = strlen(prefix);
  9979. - size_t trial_len = name_len + prefix_len;
  9980. - char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1);
  9981. - strcpy(trial_name_str, prefix);
  9982. - strcat(trial_name_str, name_str);
  9983. - method = search_prefix_name_space(depth+1, trial_name_str, trial_len,
  9984. - signature);
  9985. - if (method != NULL) {
  9986. - // If found along this branch, it was prefixed, mark as such
  9987. - method->set_is_prefixed_native();
  9988. - return method; // found
  9989. + if (depth < prefix_count) {
  9990. + // Try applying further prefixes (other than this one).
  9991. + method = search_prefix_name_space(depth+1, name_str, name_len, signature);
  9992. + if (method != NULL) {
  9993. + return method; // found
  9994. + }
  9995. +
  9996. + // Try adding this prefix to the method name and see if it matches
  9997. + // another method name.
  9998. + char* prefix = prefixes[depth];
  9999. + size_t prefix_len = strlen(prefix);
  10000. + size_t trial_len = name_len + prefix_len;
  10001. + char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1);
  10002. + strcpy(trial_name_str, prefix);
  10003. + strcat(trial_name_str, name_str);
  10004. + method = search_prefix_name_space(depth+1, trial_name_str, trial_len,
  10005. + signature);
  10006. + if (method != NULL) {
  10007. + // If found along this branch, it was prefixed, mark as such
  10008. + method->set_is_prefixed_native();
  10009. + return method; // found
  10010. + }
  10011. }
  10012. }
  10013. }
  10014. - }
  10015. - return NULL; // This whole branch bore nothing
  10016. + return NULL; // This whole branch bore nothing
  10017. }
  10018. // Return the method name with old prefixes stripped away.
  10019. @@ -2905,10 +3234,10 @@
  10020. ResourceMark rm;
  10021. char* name_str = method_name_without_prefixes(method);
  10022. return search_prefix_name_space(0, name_str, strlen(name_str),
  10023. - method->signature());
  10024. + method->signature());
  10025. }
  10026. - public:
  10027. +public:
  10028. // Construct a native method transfer processor for this class.
  10029. TransferNativeFunctionRegistration(instanceKlassHandle _the_class) {
  10030. @@ -2919,9 +3248,9 @@
  10031. }
  10032. // Attempt to transfer any of the old or deleted methods that are native
  10033. - void transfer_registrations(methodOop* old_methods, int methods_length) {
  10034. + void transfer_registrations(instanceKlassHandle old_klass, int* old_methods, int methods_length) {
  10035. for (int j = 0; j < methods_length; j++) {
  10036. - methodOop old_method = old_methods[j];
  10037. + methodOop old_method = (methodOop)old_klass->methods()->obj_at(old_methods[j]);
  10038. if (old_method->is_native() && old_method->has_native_function()) {
  10039. methodOop new_method = strip_and_search_for_new_native(old_method);
  10040. @@ -2930,7 +3259,9 @@
  10041. // Redefine does not send events (except CFLH), certainly not this
  10042. // behind the scenes re-registration.
  10043. new_method->set_native_function(old_method->native_function(),
  10044. - !methodOopDesc::native_bind_event_is_interesting);
  10045. + !methodOopDesc::native_bind_event_is_interesting);
  10046. +
  10047. + RC_TRACE(0x00008000, ("Transferring native function for method %s", old_method->name()->as_C_string()));
  10048. }
  10049. }
  10050. }
  10051. @@ -2938,534 +3269,8 @@
  10052. };
  10053. // Don't lose the association between a native method and its JNI function.
  10054. -void VM_RedefineClasses::transfer_old_native_function_registrations(instanceKlassHandle the_class) {
  10055. - TransferNativeFunctionRegistration transfer(the_class);
  10056. - transfer.transfer_registrations(_deleted_methods, _deleted_methods_length);
  10057. - transfer.transfer_registrations(_matching_old_methods, _matching_methods_length);
  10058. +void VM_RedefineClasses::transfer_old_native_function_registrations(instanceKlassHandle old_klass) {
  10059. + TransferNativeFunctionRegistration transfer(old_klass);
  10060. + transfer.transfer_registrations(old_klass, _deleted_methods, _deleted_methods_length);
  10061. + transfer.transfer_registrations(old_klass, _matching_old_methods, _matching_methods_length);
  10062. }
  10063. -
  10064. -// Deoptimize all compiled code that depends on this class.
  10065. -//
  10066. -// If the can_redefine_classes capability is obtained in the onload
  10067. -// phase then the compiler has recorded all dependencies from startup.
  10068. -// In that case we need only deoptimize and throw away all compiled code
  10069. -// that depends on the class.
  10070. -//
  10071. -// If can_redefine_classes is obtained sometime after the onload
  10072. -// phase then the dependency information may be incomplete. In that case
  10073. -// the first call to RedefineClasses causes all compiled code to be
  10074. -// thrown away. As can_redefine_classes has been obtained then
  10075. -// all future compilations will record dependencies so second and
  10076. -// subsequent calls to RedefineClasses need only throw away code
  10077. -// that depends on the class.
  10078. -//
  10079. -void VM_RedefineClasses::flush_dependent_code(instanceKlassHandle k_h, TRAPS) {
  10080. - assert_locked_or_safepoint(Compile_lock);
  10081. -
  10082. - // All dependencies have been recorded from startup or this is a second or
  10083. - // subsequent use of RedefineClasses
  10084. - if (JvmtiExport::all_dependencies_are_recorded()) {
  10085. - Universe::flush_evol_dependents_on(k_h);
  10086. - } else {
  10087. - CodeCache::mark_all_nmethods_for_deoptimization();
  10088. -
  10089. - ResourceMark rm(THREAD);
  10090. - DeoptimizationMarker dm;
  10091. -
  10092. - // Deoptimize all activations depending on marked nmethods
  10093. - Deoptimization::deoptimize_dependents();
  10094. -
  10095. - // Make the dependent methods not entrant (in VM_Deoptimize they are made zombies)
  10096. - CodeCache::make_marked_nmethods_not_entrant();
  10097. -
  10098. - // From now on we know that the dependency information is complete
  10099. - JvmtiExport::set_all_dependencies_are_recorded(true);
  10100. - }
  10101. -}
  10102. -
  10103. -void VM_RedefineClasses::compute_added_deleted_matching_methods() {
  10104. - methodOop old_method;
  10105. - methodOop new_method;
  10106. -
  10107. - _matching_old_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  10108. - _matching_new_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  10109. - _added_methods = NEW_RESOURCE_ARRAY(methodOop, _new_methods->length());
  10110. - _deleted_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  10111. -
  10112. - _matching_methods_length = 0;
  10113. - _deleted_methods_length = 0;
  10114. - _added_methods_length = 0;
  10115. -
  10116. - int nj = 0;
  10117. - int oj = 0;
  10118. - while (true) {
  10119. - if (oj >= _old_methods->length()) {
  10120. - if (nj >= _new_methods->length()) {
  10121. - break; // we've looked at everything, done
  10122. - }
  10123. - // New method at the end
  10124. - new_method = (methodOop) _new_methods->obj_at(nj);
  10125. - _added_methods[_added_methods_length++] = new_method;
  10126. - ++nj;
  10127. - } else if (nj >= _new_methods->length()) {
  10128. - // Old method, at the end, is deleted
  10129. - old_method = (methodOop) _old_methods->obj_at(oj);
  10130. - _deleted_methods[_deleted_methods_length++] = old_method;
  10131. - ++oj;
  10132. - } else {
  10133. - old_method = (methodOop) _old_methods->obj_at(oj);
  10134. - new_method = (methodOop) _new_methods->obj_at(nj);
  10135. - if (old_method->name() == new_method->name()) {
  10136. - if (old_method->signature() == new_method->signature()) {
  10137. - _matching_old_methods[_matching_methods_length ] = old_method;
  10138. - _matching_new_methods[_matching_methods_length++] = new_method;
  10139. - ++nj;
  10140. - ++oj;
  10141. - } else {
  10142. - // added overloaded have already been moved to the end,
  10143. - // so this is a deleted overloaded method
  10144. - _deleted_methods[_deleted_methods_length++] = old_method;
  10145. - ++oj;
  10146. - }
  10147. - } else { // names don't match
  10148. - if (old_method->name()->fast_compare(new_method->name()) > 0) {
  10149. - // new method
  10150. - _added_methods[_added_methods_length++] = new_method;
  10151. - ++nj;
  10152. - } else {
  10153. - // deleted method
  10154. - _deleted_methods[_deleted_methods_length++] = old_method;
  10155. - ++oj;
  10156. - }
  10157. - }
  10158. - }
  10159. - }
  10160. - assert(_matching_methods_length + _deleted_methods_length == _old_methods->length(), "sanity");
  10161. - assert(_matching_methods_length + _added_methods_length == _new_methods->length(), "sanity");
  10162. -}
  10163. -
  10164. -
  10165. -
  10166. -// Install the redefinition of a class:
  10167. -// - house keeping (flushing breakpoints and caches, deoptimizing
  10168. -// dependent compiled code)
  10169. -// - replacing parts in the_class with parts from scratch_class
  10170. -// - adding a weak reference to track the obsolete but interesting
  10171. -// parts of the_class
  10172. -// - adjusting constant pool caches and vtables in other classes
  10173. -// that refer to methods in the_class. These adjustments use the
  10174. -// SystemDictionary::classes_do() facility which only allows
  10175. -// a helper method to be specified. The interesting parameters
  10176. -// that we would like to pass to the helper method are saved in
  10177. -// static global fields in the VM operation.
  10178. -void VM_RedefineClasses::redefine_single_class(jclass the_jclass,
  10179. - instanceKlassHandle scratch_class, TRAPS) {
  10180. -
  10181. - RC_TIMER_START(_timer_rsc_phase1);
  10182. -
  10183. - oop the_class_mirror = JNIHandles::resolve_non_null(the_jclass);
  10184. - klassOop the_class_oop = java_lang_Class::as_klassOop(the_class_mirror);
  10185. - instanceKlassHandle the_class = instanceKlassHandle(THREAD, the_class_oop);
  10186. -
  10187. - // Remove all breakpoints in methods of this class
  10188. - JvmtiBreakpoints& jvmti_breakpoints = JvmtiCurrentBreakpoints::get_jvmti_breakpoints();
  10189. - jvmti_breakpoints.clearall_in_class_at_safepoint(the_class_oop);
  10190. -
  10191. - if (the_class_oop == Universe::reflect_invoke_cache()->klass()) {
  10192. - // We are redefining java.lang.reflect.Method. Method.invoke() is
  10193. - // cached and users of the cache care about each active version of
  10194. - // the method so we have to track this previous version.
  10195. - // Do this before methods get switched
  10196. - Universe::reflect_invoke_cache()->add_previous_version(
  10197. - the_class->method_with_idnum(Universe::reflect_invoke_cache()->method_idnum()));
  10198. - }
  10199. -
  10200. - // Deoptimize all compiled code that depends on this class
  10201. - flush_dependent_code(the_class, THREAD);
  10202. -
  10203. - _old_methods = the_class->methods();
  10204. - _new_methods = scratch_class->methods();
  10205. - _the_class_oop = the_class_oop;
  10206. - compute_added_deleted_matching_methods();
  10207. - update_jmethod_ids();
  10208. -
  10209. - // Attach new constant pool to the original klass. The original
  10210. - // klass still refers to the old constant pool (for now).
  10211. - scratch_class->constants()->set_pool_holder(the_class());
  10212. -
  10213. -#if 0
  10214. - // In theory, with constant pool merging in place we should be able
  10215. - // to save space by using the new, merged constant pool in place of
  10216. - // the old constant pool(s). By "pool(s)" I mean the constant pool in
  10217. - // the klass version we are replacing now and any constant pool(s) in
  10218. - // previous versions of klass. Nice theory, doesn't work in practice.
  10219. - // When this code is enabled, even simple programs throw NullPointer
  10220. - // exceptions. I'm guessing that this is caused by some constant pool
  10221. - // cache difference between the new, merged constant pool and the
  10222. - // constant pool that was just being used by the klass. I'm keeping
  10223. - // this code around to archive the idea, but the code has to remain
  10224. - // disabled for now.
  10225. -
  10226. - // Attach each old method to the new constant pool. This can be
  10227. - // done here since we are past the bytecode verification and
  10228. - // constant pool optimization phases.
  10229. - for (int i = _old_methods->length() - 1; i >= 0; i--) {
  10230. - methodOop method = (methodOop)_old_methods->obj_at(i);
  10231. - method->set_constants(scratch_class->constants());
  10232. - }
  10233. -
  10234. - {
  10235. - // walk all previous versions of the klass
  10236. - instanceKlass *ik = (instanceKlass *)the_class()->klass_part();
  10237. - PreviousVersionWalker pvw(ik);
  10238. - instanceKlassHandle ikh;
  10239. - do {
  10240. - ikh = pvw.next_previous_version();
  10241. - if (!ikh.is_null()) {
  10242. - ik = ikh();
  10243. -
  10244. - // attach previous version of klass to the new constant pool
  10245. - ik->set_constants(scratch_class->constants());
  10246. -
  10247. - // Attach each method in the previous version of klass to the
  10248. - // new constant pool
  10249. - objArrayOop prev_methods = ik->methods();
  10250. - for (int i = prev_methods->length() - 1; i >= 0; i--) {
  10251. - methodOop method = (methodOop)prev_methods->obj_at(i);
  10252. - method->set_constants(scratch_class->constants());
  10253. - }
  10254. - }
  10255. - } while (!ikh.is_null());
  10256. - }
  10257. -#endif
  10258. -
  10259. - // Replace methods and constantpool
  10260. - the_class->set_methods(_new_methods);
  10261. - scratch_class->set_methods(_old_methods); // To prevent potential GCing of the old methods,
  10262. - // and to be able to undo operation easily.
  10263. -
  10264. - constantPoolOop old_constants = the_class->constants();
  10265. - the_class->set_constants(scratch_class->constants());
  10266. - scratch_class->set_constants(old_constants); // See the previous comment.
  10267. -#if 0
  10268. - // We are swapping the guts of "the new class" with the guts of "the
  10269. - // class". Since the old constant pool has just been attached to "the
  10270. - // new class", it seems logical to set the pool holder in the old
  10271. - // constant pool also. However, doing this will change the observable
  10272. - // class hierarchy for any old methods that are still executing. A
  10273. - // method can query the identity of its "holder" and this query uses
  10274. - // the method's constant pool link to find the holder. The change in
  10275. - // holding class from "the class" to "the new class" can confuse
  10276. - // things.
  10277. - //
  10278. - // Setting the old constant pool's holder will also cause
  10279. - // verification done during vtable initialization below to fail.
  10280. - // During vtable initialization, the vtable's class is verified to be
  10281. - // a subtype of the method's holder. The vtable's class is "the
  10282. - // class" and the method's holder is gotten from the constant pool
  10283. - // link in the method itself. For "the class"'s directly implemented
  10284. - // methods, the method holder is "the class" itself (as gotten from
  10285. - // the new constant pool). The check works fine in this case. The
  10286. - // check also works fine for methods inherited from super classes.
  10287. - //
  10288. - // Miranda methods are a little more complicated. A miranda method is
  10289. - // provided by an interface when the class implementing the interface
  10290. - // does not provide its own method. These interfaces are implemented
  10291. - // internally as an instanceKlass. These special instanceKlasses
  10292. - // share the constant pool of the class that "implements" the
  10293. - // interface. By sharing the constant pool, the method holder of a
  10294. - // miranda method is the class that "implements" the interface. In a
  10295. - // non-redefine situation, the subtype check works fine. However, if
  10296. - // the old constant pool's pool holder is modified, then the check
  10297. - // fails because there is no class hierarchy relationship between the
  10298. - // vtable's class and "the new class".
  10299. -
  10300. - old_constants->set_pool_holder(scratch_class());
  10301. -#endif
  10302. -
  10303. - // track which methods are EMCP for add_previous_version() call below
  10304. - BitMap emcp_methods(_old_methods->length());
  10305. - int emcp_method_count = 0;
  10306. - emcp_methods.clear(); // clears 0..(length() - 1)
  10307. - check_methods_and_mark_as_obsolete(&emcp_methods, &emcp_method_count);
  10308. - transfer_old_native_function_registrations(the_class);
  10309. -
  10310. - // The class file bytes from before any retransformable agents mucked
  10311. - // with them was cached on the scratch class, move to the_class.
  10312. - // Note: we still want to do this if nothing needed caching since it
  10313. - // should get cleared in the_class too.
  10314. - if (the_class->get_cached_class_file_bytes() == 0) {
  10315. - // the_class doesn't have a cache yet so copy it
  10316. - the_class->set_cached_class_file(
  10317. - scratch_class->get_cached_class_file_bytes(),
  10318. - scratch_class->get_cached_class_file_len());
  10319. - }
  10320. -#ifndef PRODUCT
  10321. - else {
  10322. - assert(the_class->get_cached_class_file_bytes() ==
  10323. - scratch_class->get_cached_class_file_bytes(), "cache ptrs must match");
  10324. - assert(the_class->get_cached_class_file_len() ==
  10325. - scratch_class->get_cached_class_file_len(), "cache lens must match");
  10326. - }
  10327. -#endif
  10328. -
  10329. - // Replace inner_classes
  10330. - typeArrayOop old_inner_classes = the_class->inner_classes();
  10331. - the_class->set_inner_classes(scratch_class->inner_classes());
  10332. - scratch_class->set_inner_classes(old_inner_classes);
  10333. -
  10334. - // Initialize the vtable and interface table after
  10335. - // methods have been rewritten
  10336. - {
  10337. - ResourceMark rm(THREAD);
  10338. - // no exception should happen here since we explicitly
  10339. - // do not check loader constraints.
  10340. - // compare_and_normalize_class_versions has already checked:
  10341. - // - classloaders unchanged, signatures unchanged
  10342. - // - all instanceKlasses for redefined classes reused & contents updated
  10343. - the_class->vtable()->initialize_vtable(false, THREAD);
  10344. - the_class->itable()->initialize_itable(false, THREAD);
  10345. - assert(!HAS_PENDING_EXCEPTION || (THREAD->pending_exception()->is_a(SystemDictionary::ThreadDeath_klass())), "redefine exception");
  10346. - }
  10347. -
  10348. - // Leave arrays of jmethodIDs and itable index cache unchanged
  10349. -
  10350. - // Copy the "source file name" attribute from new class version
  10351. - the_class->set_source_file_name(scratch_class->source_file_name());
  10352. -
  10353. - // Copy the "source debug extension" attribute from new class version
  10354. - the_class->set_source_debug_extension(
  10355. - scratch_class->source_debug_extension(),
  10356. - scratch_class->source_debug_extension() == NULL ? 0 :
  10357. - (int)strlen(scratch_class->source_debug_extension()));
  10358. -
  10359. - // Use of javac -g could be different in the old and the new
  10360. - if (scratch_class->access_flags().has_localvariable_table() !=
  10361. - the_class->access_flags().has_localvariable_table()) {
  10362. -
  10363. - AccessFlags flags = the_class->access_flags();
  10364. - if (scratch_class->access_flags().has_localvariable_table()) {
  10365. - flags.set_has_localvariable_table();
  10366. - } else {
  10367. - flags.clear_has_localvariable_table();
  10368. - }
  10369. - the_class->set_access_flags(flags);
  10370. - }
  10371. -
  10372. - // Replace class annotation fields values
  10373. - typeArrayOop old_class_annotations = the_class->class_annotations();
  10374. - the_class->set_class_annotations(scratch_class->class_annotations());
  10375. - scratch_class->set_class_annotations(old_class_annotations);
  10376. -
  10377. - // Replace fields annotation fields values
  10378. - objArrayOop old_fields_annotations = the_class->fields_annotations();
  10379. - the_class->set_fields_annotations(scratch_class->fields_annotations());
  10380. - scratch_class->set_fields_annotations(old_fields_annotations);
  10381. -
  10382. - // Replace methods annotation fields values
  10383. - objArrayOop old_methods_annotations = the_class->methods_annotations();
  10384. - the_class->set_methods_annotations(scratch_class->methods_annotations());
  10385. - scratch_class->set_methods_annotations(old_methods_annotations);
  10386. -
  10387. - // Replace methods parameter annotation fields values
  10388. - objArrayOop old_methods_parameter_annotations =
  10389. - the_class->methods_parameter_annotations();
  10390. - the_class->set_methods_parameter_annotations(
  10391. - scratch_class->methods_parameter_annotations());
  10392. - scratch_class->set_methods_parameter_annotations(old_methods_parameter_annotations);
  10393. -
  10394. - // Replace methods default annotation fields values
  10395. - objArrayOop old_methods_default_annotations =
  10396. - the_class->methods_default_annotations();
  10397. - the_class->set_methods_default_annotations(
  10398. - scratch_class->methods_default_annotations());
  10399. - scratch_class->set_methods_default_annotations(old_methods_default_annotations);
  10400. -
  10401. - // Replace minor version number of class file
  10402. - u2 old_minor_version = the_class->minor_version();
  10403. - the_class->set_minor_version(scratch_class->minor_version());
  10404. - scratch_class->set_minor_version(old_minor_version);
  10405. -
  10406. - // Replace major version number of class file
  10407. - u2 old_major_version = the_class->major_version();
  10408. - the_class->set_major_version(scratch_class->major_version());
  10409. - scratch_class->set_major_version(old_major_version);
  10410. -
  10411. - // Replace CP indexes for class and name+type of enclosing method
  10412. - u2 old_class_idx = the_class->enclosing_method_class_index();
  10413. - u2 old_method_idx = the_class->enclosing_method_method_index();
  10414. - the_class->set_enclosing_method_indices(
  10415. - scratch_class->enclosing_method_class_index(),
  10416. - scratch_class->enclosing_method_method_index());
  10417. - scratch_class->set_enclosing_method_indices(old_class_idx, old_method_idx);
  10418. -
  10419. - // keep track of previous versions of this class
  10420. - the_class->add_previous_version(scratch_class, &emcp_methods,
  10421. - emcp_method_count);
  10422. -
  10423. - RC_TIMER_STOP(_timer_rsc_phase1);
  10424. - RC_TIMER_START(_timer_rsc_phase2);
  10425. -
  10426. - // Adjust constantpool caches and vtables for all classes
  10427. - // that reference methods of the evolved class.
  10428. - SystemDictionary::classes_do(adjust_cpool_cache_and_vtable, THREAD);
  10429. -
  10430. - if (the_class->oop_map_cache() != NULL) {
  10431. - // Flush references to any obsolete methods from the oop map cache
  10432. - // so that obsolete methods are not pinned.
  10433. - the_class->oop_map_cache()->flush_obsolete_entries();
  10434. - }
  10435. -
  10436. - // increment the classRedefinedCount field in the_class and in any
  10437. - // direct and indirect subclasses of the_class
  10438. - increment_class_counter((instanceKlass *)the_class()->klass_part(), THREAD);
  10439. -
  10440. - // RC_TRACE macro has an embedded ResourceMark
  10441. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  10442. - ("redefined name=%s, count=%d (avail_mem=" UINT64_FORMAT "K)",
  10443. - the_class->external_name(),
  10444. - java_lang_Class::classRedefinedCount(the_class_mirror),
  10445. - os::available_memory() >> 10));
  10446. -
  10447. - RC_TIMER_STOP(_timer_rsc_phase2);
  10448. -} // end redefine_single_class()
  10449. -
  10450. -
  10451. -// Increment the classRedefinedCount field in the specific instanceKlass
  10452. -// and in all direct and indirect subclasses.
  10453. -void VM_RedefineClasses::increment_class_counter(instanceKlass *ik, TRAPS) {
  10454. - oop class_mirror = ik->java_mirror();
  10455. - klassOop class_oop = java_lang_Class::as_klassOop(class_mirror);
  10456. - int new_count = java_lang_Class::classRedefinedCount(class_mirror) + 1;
  10457. - java_lang_Class::set_classRedefinedCount(class_mirror, new_count);
  10458. -
  10459. - if (class_oop != _the_class_oop) {
  10460. - // _the_class_oop count is printed at end of redefine_single_class()
  10461. - RC_TRACE_WITH_THREAD(0x00000008, THREAD,
  10462. - ("updated count in subclass=%s to %d", ik->external_name(), new_count));
  10463. - }
  10464. -
  10465. - for (Klass *subk = ik->subklass(); subk != NULL;
  10466. - subk = subk->next_sibling()) {
  10467. - if (subk->oop_is_instance()) {
  10468. - // Only update instanceKlasses
  10469. - instanceKlass *subik = (instanceKlass*)subk;
  10470. - // recursively do subclasses of the current subclass
  10471. - increment_class_counter(subik, THREAD);
  10472. - }
  10473. - }
  10474. -}
  10475. -
  10476. -void VM_RedefineClasses::check_class(klassOop k_oop,
  10477. - oop initiating_loader, TRAPS) {
  10478. - Klass *k = k_oop->klass_part();
  10479. - if (k->oop_is_instance()) {
  10480. - HandleMark hm(THREAD);
  10481. - instanceKlass *ik = (instanceKlass *) k;
  10482. - bool no_old_methods = true; // be optimistic
  10483. - ResourceMark rm(THREAD);
  10484. -
  10485. - // a vtable should never contain old or obsolete methods
  10486. - if (ik->vtable_length() > 0 &&
  10487. - !ik->vtable()->check_no_old_or_obsolete_entries()) {
  10488. - if (RC_TRACE_ENABLED(0x00004000)) {
  10489. - RC_TRACE_WITH_THREAD(0x00004000, THREAD,
  10490. - ("klassVtable::check_no_old_or_obsolete_entries failure"
  10491. - " -- OLD or OBSOLETE method found -- class: %s",
  10492. - ik->signature_name()));
  10493. - ik->vtable()->dump_vtable();
  10494. - }
  10495. - no_old_methods = false;
  10496. - }
  10497. -
  10498. - // an itable should never contain old or obsolete methods
  10499. - if (ik->itable_length() > 0 &&
  10500. - !ik->itable()->check_no_old_or_obsolete_entries()) {
  10501. - if (RC_TRACE_ENABLED(0x00004000)) {
  10502. - RC_TRACE_WITH_THREAD(0x00004000, THREAD,
  10503. - ("klassItable::check_no_old_or_obsolete_entries failure"
  10504. - " -- OLD or OBSOLETE method found -- class: %s",
  10505. - ik->signature_name()));
  10506. - ik->itable()->dump_itable();
  10507. - }
  10508. - no_old_methods = false;
  10509. - }
  10510. -
  10511. - // the constant pool cache should never contain old or obsolete methods
  10512. - if (ik->constants() != NULL &&
  10513. - ik->constants()->cache() != NULL &&
  10514. - !ik->constants()->cache()->check_no_old_or_obsolete_entries()) {
  10515. - if (RC_TRACE_ENABLED(0x00004000)) {
  10516. - RC_TRACE_WITH_THREAD(0x00004000, THREAD,
  10517. - ("cp-cache::check_no_old_or_obsolete_entries failure"
  10518. - " -- OLD or OBSOLETE method found -- class: %s",
  10519. - ik->signature_name()));
  10520. - ik->constants()->cache()->dump_cache();
  10521. - }
  10522. - no_old_methods = false;
  10523. - }
  10524. -
  10525. - if (!no_old_methods) {
  10526. - if (RC_TRACE_ENABLED(0x00004000)) {
  10527. - dump_methods();
  10528. - } else {
  10529. - tty->print_cr("INFO: use the '-XX:TraceRedefineClasses=16384' option "
  10530. - "to see more info about the following guarantee() failure.");
  10531. - }
  10532. - guarantee(false, "OLD and/or OBSOLETE method(s) found");
  10533. - }
  10534. - }
  10535. -}
  10536. -
  10537. -void VM_RedefineClasses::dump_methods() {
  10538. - int j;
  10539. - RC_TRACE(0x00004000, ("_old_methods --"));
  10540. - for (j = 0; j < _old_methods->length(); ++j) {
  10541. - methodOop m = (methodOop) _old_methods->obj_at(j);
  10542. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  10543. - m->access_flags().print_on(tty);
  10544. - tty->print(" -- ");
  10545. - m->print_name(tty);
  10546. - tty->cr();
  10547. - }
  10548. - RC_TRACE(0x00004000, ("_new_methods --"));
  10549. - for (j = 0; j < _new_methods->length(); ++j) {
  10550. - methodOop m = (methodOop) _new_methods->obj_at(j);
  10551. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  10552. - m->access_flags().print_on(tty);
  10553. - tty->print(" -- ");
  10554. - m->print_name(tty);
  10555. - tty->cr();
  10556. - }
  10557. - RC_TRACE(0x00004000, ("_matching_(old/new)_methods --"));
  10558. - for (j = 0; j < _matching_methods_length; ++j) {
  10559. - methodOop m = _matching_old_methods[j];
  10560. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  10561. - m->access_flags().print_on(tty);
  10562. - tty->print(" -- ");
  10563. - m->print_name(tty);
  10564. - tty->cr();
  10565. - m = _matching_new_methods[j];
  10566. - RC_TRACE_NO_CR(0x00004000, (" (%5d) ", m->vtable_index()));
  10567. - m->access_flags().print_on(tty);
  10568. - tty->cr();
  10569. - }
  10570. - RC_TRACE(0x00004000, ("_deleted_methods --"));
  10571. - for (j = 0; j < _deleted_methods_length; ++j) {
  10572. - methodOop m = _deleted_methods[j];
  10573. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  10574. - m->access_flags().print_on(tty);
  10575. - tty->print(" -- ");
  10576. - m->print_name(tty);
  10577. - tty->cr();
  10578. - }
  10579. - RC_TRACE(0x00004000, ("_added_methods --"));
  10580. - for (j = 0; j < _added_methods_length; ++j) {
  10581. - methodOop m = _added_methods[j];
  10582. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  10583. - m->access_flags().print_on(tty);
  10584. - tty->print(" -- ");
  10585. - m->print_name(tty);
  10586. - tty->cr();
  10587. - }
  10588. -}
  10589. diff -r 6c6a2299029a src/share/vm/prims/jvmtiRedefineClasses.hpp
  10590. --- a/src/share/vm/prims/jvmtiRedefineClasses.hpp Sat Dec 14 11:51:15 2013 -0800
  10591. +++ b/src/share/vm/prims/jvmtiRedefineClasses.hpp Mon Apr 28 13:12:30 2014 -0700
  10592. @@ -1,26 +1,29 @@
  10593. /*
  10594. - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
  10595. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  10596. - *
  10597. - * This code is free software; you can redistribute it and/or modify it
  10598. - * under the terms of the GNU General Public License version 2 only, as
  10599. - * published by the Free Software Foundation.
  10600. - *
  10601. - * This code is distributed in the hope that it will be useful, but WITHOUT
  10602. - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10603. - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  10604. - * version 2 for more details (a copy is included in the LICENSE file that
  10605. - * accompanied this code).
  10606. - *
  10607. - * You should have received a copy of the GNU General Public License version
  10608. - * 2 along with this work; if not, write to the Free Software Foundation,
  10609. - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  10610. - *
  10611. - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  10612. - * or visit www.oracle.com if you need additional information or have any
  10613. - * questions.
  10614. - *
  10615. - */
  10616. +* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  10617. +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  10618. +*
  10619. +* This code is free software; you can redistribute it and/or modify it
  10620. +* under the terms of the GNU General Public License version 2 only, as
  10621. +* published by the Free Software Foundation.
  10622. +*
  10623. +* This code is distributed in the hope that it will be useful, but WITHOUT
  10624. +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10625. +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  10626. +* version 2 for more details (a copy is included in the LICENSE file that
  10627. +* accompanied this code).
  10628. +*
  10629. +* You should have received a copy of the GNU General Public License version
  10630. +* 2 along with this work; if not, write to the Free Software Foundation,
  10631. +* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  10632. +*
  10633. +* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  10634. +* or visit www.oracle.com if you need additional information or have any
  10635. +* questions.
  10636. +*
  10637. +*/
  10638. +
  10639. +// New version that allows arbitrary changes to already loaded classes.
  10640. +// Modifications done by: Thomas Wuerthinger <thomas.wuerthinger@gmail.com>
  10641. #ifndef SHARE_VM_PRIMS_JVMTIREDEFINECLASSES_HPP
  10642. #define SHARE_VM_PRIMS_JVMTIREDEFINECLASSES_HPP
  10643. @@ -32,331 +35,28 @@
  10644. #include "oops/objArrayOop.hpp"
  10645. #include "prims/jvmtiRedefineClassesTrace.hpp"
  10646. #include "runtime/vm_operations.hpp"
  10647. +#include "gc_implementation/shared/vmGCOperations.hpp"
  10648. -// Introduction:
  10649. -//
  10650. -// The RedefineClasses() API is used to change the definition of one or
  10651. -// more classes. While the API supports redefining more than one class
  10652. -// in a single call, in general, the API is discussed in the context of
  10653. -// changing the definition of a single current class to a single new
  10654. -// class. For clarity, the current class is will always be called
  10655. -// "the_class" and the new class will always be called "scratch_class".
  10656. -//
  10657. -// The name "the_class" is used because there is only one structure
  10658. -// that represents a specific class; redefinition does not replace the
  10659. -// structure, but instead replaces parts of the structure. The name
  10660. -// "scratch_class" is used because the structure that represents the
  10661. -// new definition of a specific class is simply used to carry around
  10662. -// the parts of the new definition until they are used to replace the
  10663. -// appropriate parts in the_class. Once redefinition of a class is
  10664. -// complete, scratch_class is thrown away.
  10665. -//
  10666. -//
  10667. -// Implementation Overview:
  10668. -//
  10669. -// The RedefineClasses() API is mostly a wrapper around the VM op that
  10670. -// does the real work. The work is split in varying degrees between
  10671. -// doit_prologue(), doit() and doit_epilogue().
  10672. -//
  10673. -// 1) doit_prologue() is called by the JavaThread on the way to a
  10674. -// safepoint. It does parameter verification and loads scratch_class
  10675. -// which involves:
  10676. -// - parsing the incoming class definition using the_class' class
  10677. -// loader and security context
  10678. -// - linking scratch_class
  10679. -// - merging constant pools and rewriting bytecodes as needed
  10680. -// for the merged constant pool
  10681. -// - verifying the bytecodes in scratch_class
  10682. -// - setting up the constant pool cache and rewriting bytecodes
  10683. -// as needed to use the cache
  10684. -// - finally, scratch_class is compared to the_class to verify
  10685. -// that it is a valid replacement class
  10686. -// - if everything is good, then scratch_class is saved in an
  10687. -// instance field in the VM operation for the doit() call
  10688. -//
  10689. -// Note: A JavaThread must do the above work.
  10690. -//
  10691. -// 2) doit() is called by the VMThread during a safepoint. It installs
  10692. -// the new class definition(s) which involves:
  10693. -// - retrieving the scratch_class from the instance field in the
  10694. -// VM operation
  10695. -// - house keeping (flushing breakpoints and caches, deoptimizing
  10696. -// dependent compiled code)
  10697. -// - replacing parts in the_class with parts from scratch_class
  10698. -// - adding weak reference(s) to track the obsolete but interesting
  10699. -// parts of the_class
  10700. -// - adjusting constant pool caches and vtables in other classes
  10701. -// that refer to methods in the_class. These adjustments use the
  10702. -// SystemDictionary::classes_do() facility which only allows
  10703. -// a helper method to be specified. The interesting parameters
  10704. -// that we would like to pass to the helper method are saved in
  10705. -// static global fields in the VM operation.
  10706. -// - telling the SystemDictionary to notice our changes
  10707. -//
  10708. -// Note: the above work must be done by the VMThread to be safe.
  10709. -//
  10710. -// 3) doit_epilogue() is called by the JavaThread after the VM op
  10711. -// is finished and the safepoint is done. It simply cleans up
  10712. -// memory allocated in doit_prologue() and used in doit().
  10713. -//
  10714. -//
  10715. -// Constant Pool Details:
  10716. -//
  10717. -// When the_class is redefined, we cannot just replace the constant
  10718. -// pool in the_class with the constant pool from scratch_class because
  10719. -// that could confuse obsolete methods that may still be running.
  10720. -// Instead, the constant pool from the_class, old_cp, is merged with
  10721. -// the constant pool from scratch_class, scratch_cp. The resulting
  10722. -// constant pool, merge_cp, replaces old_cp in the_class.
  10723. -//
  10724. -// The key part of any merging algorithm is the entry comparison
  10725. -// function so we have to know the types of entries in a constant pool
  10726. -// in order to merge two of them together. Constant pools can contain
  10727. -// up to 12 different kinds of entries; the JVM_CONSTANT_Unicode entry
  10728. -// is not presently used so we only have to worry about the other 11
  10729. -// entry types. For the purposes of constant pool merging, it is
  10730. -// helpful to know that the 11 entry types fall into 3 different
  10731. -// subtypes: "direct", "indirect" and "double-indirect".
  10732. -//
  10733. -// Direct CP entries contain data and do not contain references to
  10734. -// other CP entries. The following are direct CP entries:
  10735. -// JVM_CONSTANT_{Double,Float,Integer,Long,Utf8}
  10736. -//
  10737. -// Indirect CP entries contain 1 or 2 references to a direct CP entry
  10738. -// and no other data. The following are indirect CP entries:
  10739. -// JVM_CONSTANT_{Class,NameAndType,String}
  10740. -//
  10741. -// Double-indirect CP entries contain two references to indirect CP
  10742. -// entries and no other data. The following are double-indirect CP
  10743. -// entries:
  10744. -// JVM_CONSTANT_{Fieldref,InterfaceMethodref,Methodref}
  10745. -//
  10746. -// When comparing entries between two constant pools, the entry types
  10747. -// are compared first and if they match, then further comparisons are
  10748. -// made depending on the entry subtype. Comparing direct CP entries is
  10749. -// simply a matter of comparing the data associated with each entry.
  10750. -// Comparing both indirect and double-indirect CP entries requires
  10751. -// recursion.
  10752. -//
  10753. -// Fortunately, the recursive combinations are limited because indirect
  10754. -// CP entries can only refer to direct CP entries and double-indirect
  10755. -// CP entries can only refer to indirect CP entries. The following is
  10756. -// an example illustration of the deepest set of indirections needed to
  10757. -// access the data associated with a JVM_CONSTANT_Fieldref entry:
  10758. -//
  10759. -// JVM_CONSTANT_Fieldref {
  10760. -// class_index => JVM_CONSTANT_Class {
  10761. -// name_index => JVM_CONSTANT_Utf8 {
  10762. -// <data-1>
  10763. -// }
  10764. -// }
  10765. -// name_and_type_index => JVM_CONSTANT_NameAndType {
  10766. -// name_index => JVM_CONSTANT_Utf8 {
  10767. -// <data-2>
  10768. -// }
  10769. -// descriptor_index => JVM_CONSTANT_Utf8 {
  10770. -// <data-3>
  10771. -// }
  10772. -// }
  10773. -// }
  10774. -//
  10775. -// The above illustration is not a data structure definition for any
  10776. -// computer language. The curly braces ('{' and '}') are meant to
  10777. -// delimit the context of the "fields" in the CP entry types shown.
  10778. -// Each indirection from the JVM_CONSTANT_Fieldref entry is shown via
  10779. -// "=>", e.g., the class_index is used to indirectly reference a
  10780. -// JVM_CONSTANT_Class entry where the name_index is used to indirectly
  10781. -// reference a JVM_CONSTANT_Utf8 entry which contains the interesting
  10782. -// <data-1>. In order to understand a JVM_CONSTANT_Fieldref entry, we
  10783. -// have to do a total of 5 indirections just to get to the CP entries
  10784. -// that contain the interesting pieces of data and then we have to
  10785. -// fetch the three pieces of data. This means we have to do a total of
  10786. -// (5 + 3) * 2 == 16 dereferences to compare two JVM_CONSTANT_Fieldref
  10787. -// entries.
  10788. -//
  10789. -// Here is the indirection, data and dereference count for each entry
  10790. -// type:
  10791. -//
  10792. -// JVM_CONSTANT_Class 1 indir, 1 data, 2 derefs
  10793. -// JVM_CONSTANT_Double 0 indir, 1 data, 1 deref
  10794. -// JVM_CONSTANT_Fieldref 2 indir, 3 data, 8 derefs
  10795. -// JVM_CONSTANT_Float 0 indir, 1 data, 1 deref
  10796. -// JVM_CONSTANT_Integer 0 indir, 1 data, 1 deref
  10797. -// JVM_CONSTANT_InterfaceMethodref 2 indir, 3 data, 8 derefs
  10798. -// JVM_CONSTANT_Long 0 indir, 1 data, 1 deref
  10799. -// JVM_CONSTANT_Methodref 2 indir, 3 data, 8 derefs
  10800. -// JVM_CONSTANT_NameAndType 1 indir, 2 data, 4 derefs
  10801. -// JVM_CONSTANT_String 1 indir, 1 data, 2 derefs
  10802. -// JVM_CONSTANT_Utf8 0 indir, 1 data, 1 deref
  10803. -//
  10804. -// So different subtypes of CP entries require different amounts of
  10805. -// work for a proper comparison.
  10806. -//
  10807. -// Now that we've talked about the different entry types and how to
  10808. -// compare them we need to get back to merging. This is not a merge in
  10809. -// the "sort -u" sense or even in the "sort" sense. When we merge two
  10810. -// constant pools, we copy all the entries from old_cp to merge_cp,
  10811. -// preserving entry order. Next we append all the unique entries from
  10812. -// scratch_cp to merge_cp and we track the index changes from the
  10813. -// location in scratch_cp to the possibly new location in merge_cp.
  10814. -// When we are done, any obsolete code that is still running that
  10815. -// uses old_cp should not be able to observe any difference if it
  10816. -// were to use merge_cp. As for the new code in scratch_class, it is
  10817. -// modified to use the appropriate index values in merge_cp before it
  10818. -// is used to replace the code in the_class.
  10819. -//
  10820. -// There is one small complication in copying the entries from old_cp
  10821. -// to merge_cp. Two of the CP entry types are special in that they are
  10822. -// lazily resolved. Before explaining the copying complication, we need
  10823. -// to digress into CP entry resolution.
  10824. -//
  10825. -// JVM_CONSTANT_Class and JVM_CONSTANT_String entries are present in
  10826. -// the class file, but are not stored in memory as such until they are
  10827. -// resolved. The entries are not resolved unless they are used because
  10828. -// resolution is expensive. During class file parsing the entries are
  10829. -// initially stored in memory as JVM_CONSTANT_ClassIndex and
  10830. -// JVM_CONSTANT_StringIndex entries. These special CP entry types
  10831. -// indicate that the JVM_CONSTANT_Class and JVM_CONSTANT_String entries
  10832. -// have been parsed, but the index values in the entries have not been
  10833. -// validated. After the entire constant pool has been parsed, the index
  10834. -// values can be validated and then the entries are converted into
  10835. -// JVM_CONSTANT_UnresolvedClass and JVM_CONSTANT_UnresolvedString
  10836. -// entries. During this conversion process, the UTF8 values that are
  10837. -// indirectly referenced by the JVM_CONSTANT_ClassIndex and
  10838. -// JVM_CONSTANT_StringIndex entries are changed into Symbol*s and the
  10839. -// entries are modified to refer to the Symbol*s. This optimization
  10840. -// eliminates one level of indirection for those two CP entry types and
  10841. -// gets the entries ready for verification. During class file parsing
  10842. -// it is also possible for JVM_CONSTANT_UnresolvedString entries to be
  10843. -// resolved into JVM_CONSTANT_String entries. Verification expects to
  10844. -// find JVM_CONSTANT_UnresolvedClass and either JVM_CONSTANT_String or
  10845. -// JVM_CONSTANT_UnresolvedString entries and not JVM_CONSTANT_Class
  10846. -// entries.
  10847. -//
  10848. -// Now we can get back to the copying complication. When we copy
  10849. -// entries from old_cp to merge_cp, we have to revert any
  10850. -// JVM_CONSTANT_Class entries to JVM_CONSTANT_UnresolvedClass entries
  10851. -// or verification will fail.
  10852. -//
  10853. -// It is important to explicitly state that the merging algorithm
  10854. -// effectively unresolves JVM_CONSTANT_Class entries that were in the
  10855. -// old_cp when they are changed into JVM_CONSTANT_UnresolvedClass
  10856. -// entries in the merge_cp. This is done both to make verification
  10857. -// happy and to avoid adding more brittleness between RedefineClasses
  10858. -// and the constant pool cache. By allowing the constant pool cache
  10859. -// implementation to (re)resolve JVM_CONSTANT_UnresolvedClass entries
  10860. -// into JVM_CONSTANT_Class entries, we avoid having to embed knowledge
  10861. -// about those algorithms in RedefineClasses.
  10862. -//
  10863. -// Appending unique entries from scratch_cp to merge_cp is straight
  10864. -// forward for direct CP entries and most indirect CP entries. For the
  10865. -// indirect CP entry type JVM_CONSTANT_NameAndType and for the double-
  10866. -// indirect CP entry types, the presence of more than one piece of
  10867. -// interesting data makes appending the entries more complicated.
  10868. -//
  10869. -// For the JVM_CONSTANT_{Double,Float,Integer,Long,Utf8} entry types,
  10870. -// the entry is simply copied from scratch_cp to the end of merge_cp.
  10871. -// If the index in scratch_cp is different than the destination index
  10872. -// in merge_cp, then the change in index value is tracked.
  10873. -//
  10874. -// Note: the above discussion for the direct CP entries also applies
  10875. -// to the JVM_CONSTANT_Unresolved{Class,String} entry types.
  10876. -//
  10877. -// For the JVM_CONSTANT_{Class,String} entry types, since there is only
  10878. -// one data element at the end of the recursion, we know that we have
  10879. -// either one or two unique entries. If the JVM_CONSTANT_Utf8 entry is
  10880. -// unique then it is appended to merge_cp before the current entry.
  10881. -// If the JVM_CONSTANT_Utf8 entry is not unique, then the current entry
  10882. -// is updated to refer to the duplicate entry in merge_cp before it is
  10883. -// appended to merge_cp. Again, any changes in index values are tracked
  10884. -// as needed.
  10885. -//
  10886. -// Note: the above discussion for JVM_CONSTANT_{Class,String} entry
  10887. -// types is theoretical. Since those entry types have already been
  10888. -// optimized into JVM_CONSTANT_Unresolved{Class,String} entry types,
  10889. -// they are handled as direct CP entries.
  10890. -//
  10891. -// For the JVM_CONSTANT_NameAndType entry type, since there are two
  10892. -// data elements at the end of the recursions, we know that we have
  10893. -// between one and three unique entries. Any unique JVM_CONSTANT_Utf8
  10894. -// entries are appended to merge_cp before the current entry. For any
  10895. -// JVM_CONSTANT_Utf8 entries that are not unique, the current entry is
  10896. -// updated to refer to the duplicate entry in merge_cp before it is
  10897. -// appended to merge_cp. Again, any changes in index values are tracked
  10898. -// as needed.
  10899. -//
  10900. -// For the JVM_CONSTANT_{Fieldref,InterfaceMethodref,Methodref} entry
  10901. -// types, since there are two indirect CP entries and three data
  10902. -// elements at the end of the recursions, we know that we have between
  10903. -// one and six unique entries. See the JVM_CONSTANT_Fieldref diagram
  10904. -// above for an example of all six entries. The uniqueness algorithm
  10905. -// for the JVM_CONSTANT_Class and JVM_CONSTANT_NameAndType entries is
  10906. -// covered above. Any unique entries are appended to merge_cp before
  10907. -// the current entry. For any entries that are not unique, the current
  10908. -// entry is updated to refer to the duplicate entry in merge_cp before
  10909. -// it is appended to merge_cp. Again, any changes in index values are
  10910. -// tracked as needed.
  10911. -//
  10912. -//
  10913. -// Other Details:
  10914. -//
  10915. -// Details for other parts of RedefineClasses need to be written.
  10916. -// This is a placeholder section.
  10917. -//
  10918. -//
  10919. -// Open Issues (in no particular order):
  10920. -//
  10921. -// - How do we serialize the RedefineClasses() API without deadlocking?
  10922. -//
  10923. -// - SystemDictionary::parse_stream() was called with a NULL protection
  10924. -// domain since the initial version. This has been changed to pass
  10925. -// the_class->protection_domain(). This change has been tested with
  10926. -// all NSK tests and nothing broke, but what will adding it now break
  10927. -// in ways that we don't test?
  10928. -//
  10929. -// - GenerateOopMap::rewrite_load_or_store() has a comment in its
  10930. -// (indirect) use of the Relocator class that the max instruction
  10931. -// size is 4 bytes. goto_w and jsr_w are 5 bytes and wide/iinc is
  10932. -// 6 bytes. Perhaps Relocator only needs a 4 byte buffer to do
  10933. -// what it does to the bytecodes. More investigation is needed.
  10934. -//
  10935. -// - java.lang.Object methods can be called on arrays. This is
  10936. -// implemented via the arrayKlassOop vtable which we don't
  10937. -// update. For example, if we redefine java.lang.Object.toString(),
  10938. -// then the new version of the method will not be called for array
  10939. -// objects.
  10940. -//
  10941. -// - How do we know if redefine_single_class() and the guts of
  10942. -// instanceKlass are out of sync? I don't think this can be
  10943. -// automated, but we should probably order the work in
  10944. -// redefine_single_class() to match the order of field
  10945. -// definitions in instanceKlass. We also need to add some
  10946. -// comments about keeping things in sync.
  10947. -//
  10948. -// - set_new_constant_pool() is huge and we should consider refactoring
  10949. -// it into smaller chunks of work.
  10950. -//
  10951. -// - The exception table update code in set_new_constant_pool() defines
  10952. -// const values that are also defined in a local context elsewhere.
  10953. -// The same literal values are also used in elsewhere. We need to
  10954. -// coordinate a cleanup of these constants with Runtime.
  10955. -//
  10956. +#define RC_ABORT(error) { _result = error; return false; }
  10957. -class VM_RedefineClasses: public VM_Operation {
  10958. +class VM_RedefineClasses: public VM_GC_Operation {
  10959. private:
  10960. +
  10961. // These static fields are needed by SystemDictionary::classes_do()
  10962. // facility and the adjust_cpool_cache_and_vtable() helper:
  10963. static objArrayOop _old_methods;
  10964. static objArrayOop _new_methods;
  10965. - static methodOop* _matching_old_methods;
  10966. - static methodOop* _matching_new_methods;
  10967. - static methodOop* _deleted_methods;
  10968. - static methodOop* _added_methods;
  10969. + static int* _matching_old_methods;
  10970. + static int* _matching_new_methods;
  10971. + static int* _deleted_methods;
  10972. + static int* _added_methods;
  10973. static int _matching_methods_length;
  10974. static int _deleted_methods_length;
  10975. static int _added_methods_length;
  10976. static klassOop _the_class_oop;
  10977. + static int _revision_number;
  10978. +
  10979. // The instance fields are used to pass information from
  10980. // doit_prologue() to doit() and doit_epilogue().
  10981. jint _class_count;
  10982. @@ -370,36 +70,29 @@
  10983. // _index_map_p contains any entries.
  10984. int _index_map_count;
  10985. intArray * _index_map_p;
  10986. - // ptr to _class_count scratch_classes
  10987. - instanceKlassHandle * _scratch_classes;
  10988. - jvmtiError _res;
  10989. + GrowableArray<instanceKlassHandle>* _new_classes;
  10990. + GrowableArray<oop>* _updated_oops;
  10991. + jvmtiError _result;
  10992. + int _max_redefinition_flags;
  10993. // Performance measurement support. These timers do not cover all
  10994. // the work done for JVM/TI RedefineClasses() but they do cover
  10995. // the heavy lifting.
  10996. - elapsedTimer _timer_rsc_phase1;
  10997. - elapsedTimer _timer_rsc_phase2;
  10998. - elapsedTimer _timer_vm_op_prologue;
  10999. + elapsedTimer _timer_total;
  11000. + elapsedTimer _timer_prologue;
  11001. + elapsedTimer _timer_class_linking;
  11002. + elapsedTimer _timer_class_loading;
  11003. + elapsedTimer _timer_check_type;
  11004. + elapsedTimer _timer_prepare_redefinition;
  11005. + elapsedTimer _timer_wait_for_locks;
  11006. + elapsedTimer _timer_redefinition;
  11007. + elapsedTimer _timer_vm_op_epilogue;
  11008. - // These routines are roughly in call order unless otherwise noted.
  11009. -
  11010. - // Load the caller's new class definition(s) into _scratch_classes.
  11011. - // Constant pool merging work is done here as needed. Also calls
  11012. - // compare_and_normalize_class_versions() to verify the class
  11013. - // definition(s).
  11014. + jvmtiError check_redefinition_allowed(instanceKlassHandle new_class);
  11015. + jvmtiError find_sorted_affected_classes(GrowableArray<instanceKlassHandle> *all_affected_klasses);
  11016. + jvmtiError find_class_bytes(instanceKlassHandle the_class, const unsigned char **class_bytes, jint *class_byte_count, jboolean *not_changed);
  11017. jvmtiError load_new_class_versions(TRAPS);
  11018. - // Verify that the caller provided class definition(s) that meet
  11019. - // the restrictions of RedefineClasses. Normalize the order of
  11020. - // overloaded methods as needed.
  11021. - jvmtiError compare_and_normalize_class_versions(
  11022. - instanceKlassHandle the_class, instanceKlassHandle scratch_class);
  11023. -
  11024. - // Swap annotations[i] with annotations[j]
  11025. - // Used by compare_and_normalize_class_versions() when normalizing
  11026. - // overloaded methods or changing idnum as when adding or deleting methods.
  11027. - void swap_all_method_annotations(int i, int j, instanceKlassHandle scratch_class);
  11028. -
  11029. // Figure out which new methods match old methods in name and signature,
  11030. // which methods have been added, and which are no longer present
  11031. void compute_added_deleted_matching_methods();
  11032. @@ -407,95 +100,100 @@
  11033. // Change jmethodIDs to point to the new methods
  11034. void update_jmethod_ids();
  11035. - // In addition to marking methods as obsolete, this routine
  11036. - // records which methods are EMCP (Equivalent Module Constant
  11037. - // Pool) in the emcp_methods BitMap and returns the number of
  11038. - // EMCP methods via emcp_method_count_p. This information is
  11039. - // used when information about the previous version of the_class
  11040. - // is squirreled away.
  11041. - void check_methods_and_mark_as_obsolete(BitMap *emcp_methods,
  11042. - int * emcp_method_count_p);
  11043. - void transfer_old_native_function_registrations(instanceKlassHandle the_class);
  11044. + class FindAffectedKlassesClosure : public ObjectClosure {
  11045. - // Unevolving classes may point to methods of the_class directly
  11046. - // from their constant pool caches, itables, and/or vtables. We
  11047. - // use the SystemDictionary::classes_do() facility and this helper
  11048. - // to fix up these pointers.
  11049. - static void adjust_cpool_cache_and_vtable(klassOop k_oop, oop loader, TRAPS);
  11050. + private:
  11051. + GrowableArray<instanceKlassHandle> *_original_klasses;
  11052. + GrowableArray<instanceKlassHandle> *_result;
  11053. +
  11054. + public:
  11055. + FindAffectedKlassesClosure(GrowableArray<instanceKlassHandle> *original_klasses, GrowableArray<instanceKlassHandle> *result);
  11056. +
  11057. + virtual void do_object(oop obj);
  11058. + };
  11059. +
  11060. +
  11061. + static jvmtiError do_topological_class_sorting(const jvmtiClassDefinition *class_definitions, int class_count, GrowableArray<instanceKlassHandle> *affected, GrowableArray<instanceKlassHandle> *arr, TRAPS);
  11062. // Install the redefinition of a class
  11063. - void redefine_single_class(jclass the_jclass,
  11064. - instanceKlassHandle scratch_class, TRAPS);
  11065. + void redefine_single_class(instanceKlassHandle the_new_class, TRAPS);
  11066. // Increment the classRedefinedCount field in the specific instanceKlass
  11067. // and in all direct and indirect subclasses.
  11068. void increment_class_counter(instanceKlass *ik, TRAPS);
  11069. - // Support for constant pool merging (these routines are in alpha
  11070. - // order):
  11071. - void append_entry(constantPoolHandle scratch_cp, int scratch_i,
  11072. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS);
  11073. - int find_new_index(int old_index);
  11074. - bool is_unresolved_class_mismatch(constantPoolHandle cp1, int index1,
  11075. - constantPoolHandle cp2, int index2);
  11076. - bool is_unresolved_string_mismatch(constantPoolHandle cp1, int index1,
  11077. - constantPoolHandle cp2, int index2);
  11078. - void map_index(constantPoolHandle scratch_cp, int old_index, int new_index);
  11079. - bool merge_constant_pools(constantPoolHandle old_cp,
  11080. - constantPoolHandle scratch_cp, constantPoolHandle *merge_cp_p,
  11081. - int *merge_cp_length_p, TRAPS);
  11082. - jvmtiError merge_cp_and_rewrite(instanceKlassHandle the_class,
  11083. - instanceKlassHandle scratch_class, TRAPS);
  11084. - u2 rewrite_cp_ref_in_annotation_data(
  11085. - typeArrayHandle annotations_typeArray, int &byte_i_ref,
  11086. - const char * trace_mesg, TRAPS);
  11087. - bool rewrite_cp_refs(instanceKlassHandle scratch_class, TRAPS);
  11088. - bool rewrite_cp_refs_in_annotation_struct(
  11089. - typeArrayHandle class_annotations, int &byte_i_ref, TRAPS);
  11090. - bool rewrite_cp_refs_in_annotations_typeArray(
  11091. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS);
  11092. - bool rewrite_cp_refs_in_class_annotations(
  11093. - instanceKlassHandle scratch_class, TRAPS);
  11094. - bool rewrite_cp_refs_in_element_value(
  11095. - typeArrayHandle class_annotations, int &byte_i_ref, TRAPS);
  11096. - bool rewrite_cp_refs_in_fields_annotations(
  11097. - instanceKlassHandle scratch_class, TRAPS);
  11098. - void rewrite_cp_refs_in_method(methodHandle method,
  11099. - methodHandle * new_method_p, TRAPS);
  11100. - bool rewrite_cp_refs_in_methods(instanceKlassHandle scratch_class, TRAPS);
  11101. - bool rewrite_cp_refs_in_methods_annotations(
  11102. - instanceKlassHandle scratch_class, TRAPS);
  11103. - bool rewrite_cp_refs_in_methods_default_annotations(
  11104. - instanceKlassHandle scratch_class, TRAPS);
  11105. - bool rewrite_cp_refs_in_methods_parameter_annotations(
  11106. - instanceKlassHandle scratch_class, TRAPS);
  11107. - void rewrite_cp_refs_in_stack_map_table(methodHandle method, TRAPS);
  11108. - void rewrite_cp_refs_in_verification_type_info(
  11109. - address& stackmap_addr_ref, address stackmap_end, u2 frame_i,
  11110. - u1 frame_size, TRAPS);
  11111. - void set_new_constant_pool(instanceKlassHandle scratch_class,
  11112. - constantPoolHandle scratch_cp, int scratch_cp_length, bool shrink, TRAPS);
  11113. void flush_dependent_code(instanceKlassHandle k_h, TRAPS);
  11114. - static void check_class(klassOop k_oop, oop initiating_loader, TRAPS);
  11115. - static void dump_methods();
  11116. + static void check_class(klassOop k_oop,/* oop initiating_loader,*/ TRAPS) PRODUCT_RETURN;
  11117. +
  11118. + static void adjust_cpool_cache(klassOop k_oop, oop initiating_loader, TRAPS);
  11119. +
  11120. +#ifdef ASSERT
  11121. + static void verify_classes(klassOop k_oop, oop initiating_loader, TRAPS);
  11122. +#endif
  11123. +
  11124. + int calculate_redefinition_flags(instanceKlassHandle new_version);
  11125. + void calculate_instance_update_information(klassOop new_version);
  11126. + void check_methods_and_mark_as_obsolete(BitMap *emcp_methods, int * emcp_method_count_p);
  11127. +
  11128. + static void calculate_type_check_information(klassOop k);
  11129. + static void clear_type_check_information(klassOop k);
  11130. public:
  11131. - VM_RedefineClasses(jint class_count,
  11132. - const jvmtiClassDefinition *class_defs,
  11133. - JvmtiClassLoadKind class_load_kind);
  11134. - VMOp_Type type() const { return VMOp_RedefineClasses; }
  11135. + VM_RedefineClasses(jint class_count, const jvmtiClassDefinition *class_defs, JvmtiClassLoadKind class_load_kind);
  11136. + virtual ~VM_RedefineClasses();
  11137. +
  11138. + bool check_arguments();
  11139. bool doit_prologue();
  11140. void doit();
  11141. void doit_epilogue();
  11142. + void rollback();
  11143. - bool allow_nested_vm_operations() const { return true; }
  11144. - jvmtiError check_error() { return _res; }
  11145. + jvmtiError check_exception() const;
  11146. + VMOp_Type type() const { return VMOp_RedefineClasses; }
  11147. + bool skip_operation() const { return false; }
  11148. + bool allow_nested_vm_operations() const { return true; }
  11149. + jvmtiError check_error() { return _result; }
  11150. +
  11151. + void update_active_methods();
  11152. +
  11153. + // Checks for type consistency after hierarchy change
  11154. + bool check_type_consistency();
  11155. + void calculate_type_check_information();
  11156. + bool check_field_value_types();
  11157. + void clear_type_check_information();
  11158. + bool check_method_stacks();
  11159. + bool check_loaded_methods();
  11160. + bool check_method(methodOop method);
  11161. + static Symbol* signature_to_class_name(Symbol* signature);
  11162. +
  11163. + void method_forwarding();
  11164. +
  11165. + void update_array_classes_to_newest_version(klassOop smallest_dimension);
  11166. // Modifiable test must be shared between IsModifiableClass query
  11167. // and redefine implementation
  11168. static bool is_modifiable_class(oop klass_mirror);
  11169. +
  11170. + // Method used during garbage collection, the VM operation must iterate over all oops.
  11171. + void oops_do(OopClosure* f);
  11172. +
  11173. + // Utility methods for transferring field access flags
  11174. +
  11175. + static void transfer_special_access_flags(fieldDescriptor *from, fieldDescriptor *to);
  11176. + static void update_klass_field_access_flag(fieldDescriptor *fd);
  11177. +
  11178. + void transfer_old_native_function_registrations(instanceKlassHandle the_class);
  11179. +
  11180. + void lock_threads();
  11181. + void unlock_threads();
  11182. +
  11183. + template <class T> static void do_oop_work(T* p);
  11184. +
  11185. + static void swap_marks(oop first, oop second);
  11186. +
  11187. };
  11188. #endif // SHARE_VM_PRIMS_JVMTIREDEFINECLASSES_HPP
  11189. +
  11190. diff -r 6c6a2299029a src/share/vm/prims/methodComparator.cpp
  11191. --- a/src/share/vm/prims/methodComparator.cpp Sat Dec 14 11:51:15 2013 -0800
  11192. +++ b/src/share/vm/prims/methodComparator.cpp Mon Apr 28 13:12:30 2014 -0700
  11193. @@ -65,6 +65,7 @@
  11194. if (! args_same(c_old, c_new))
  11195. return false;
  11196. }
  11197. +
  11198. return true;
  11199. }
  11200. diff -r 6c6a2299029a src/share/vm/prims/nativeLookup.cpp
  11201. --- a/src/share/vm/prims/nativeLookup.cpp Sat Dec 14 11:51:15 2013 -0800
  11202. +++ b/src/share/vm/prims/nativeLookup.cpp Mon Apr 28 13:12:30 2014 -0700
  11203. @@ -35,6 +35,7 @@
  11204. #include "oops/symbol.hpp"
  11205. #include "prims/jvm_misc.hpp"
  11206. #include "prims/nativeLookup.hpp"
  11207. +#include "prims/jvmtiRedefineClasses.hpp"
  11208. #include "runtime/arguments.hpp"
  11209. #include "runtime/handles.inline.hpp"
  11210. #include "runtime/javaCalls.hpp"
  11211. @@ -53,7 +54,6 @@
  11212. # include "os_bsd.inline.hpp"
  11213. #endif
  11214. -
  11215. static void mangle_name_on(outputStream* st, Symbol* name, int begin, int end) {
  11216. char* bytes = (char*)name->bytes() + begin;
  11217. char* end_bytes = (char*)name->bytes() + end;
  11218. @@ -138,6 +138,40 @@
  11219. { CC"Java_sun_hotspot_WhiteBox_registerNatives", NULL, FN_PTR(JVM_RegisterWhiteBoxMethods) },
  11220. };
  11221. +// Helper function to call redefineClasses from Java Code
  11222. +JVM_ENTRY(int, JVM_RedefineClassesHelper(JNIEnv *env, jclass cb, jclass target, jbyteArray bytes))
  11223. + ResourceMark rm(THREAD);
  11224. +
  11225. + JavaThread* current_thread = JavaThread::current();
  11226. + jbyte* bytecodes = NULL;
  11227. + const int class_count = 1;
  11228. + jvmtiClassDefinition* class_definitions = NEW_RESOURCE_ARRAY(jvmtiClassDefinition, class_count);
  11229. +
  11230. + {
  11231. + ThreadToNativeFromVM ttnfv(thread);
  11232. + jboolean is_copy = JNI_FALSE;
  11233. + bytecodes = env->GetByteArrayElements(bytes, &is_copy);
  11234. + class_definitions[0].klass = target;
  11235. + class_definitions[0].class_byte_count = env->GetArrayLength(bytes);
  11236. + class_definitions[0].class_bytes = (unsigned char*)bytecodes;
  11237. + }
  11238. +
  11239. + VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_retransform);
  11240. + VMThread::execute(&op);
  11241. + int result = op.check_error();
  11242. +
  11243. + {
  11244. + ThreadToNativeFromVM ttnfv(thread);
  11245. + if (env->ExceptionOccurred()) {
  11246. + return -1;
  11247. + }
  11248. + env->ReleaseByteArrayElements(bytes, bytecodes, 0);
  11249. + }
  11250. +
  11251. + return result;
  11252. +JVM_END
  11253. +
  11254. +
  11255. static address lookup_special_native(char* jni_name) {
  11256. int i = !JDK_Version::is_gte_jdk14x_version() ? 0 : 2; // see comment in lookup_special_native_methods
  11257. int count = sizeof(lookup_special_native_methods) / sizeof(JNINativeMethod);
  11258. @@ -177,6 +211,9 @@
  11259. return entry;
  11260. }
  11261. }
  11262. + if(strstr(jni_name, "Java_at_ssw_hotswap_ClassRedefinition_redefineClasses") != NULL) {
  11263. + return CAST_FROM_FN_PTR(address, JVM_RedefineClassesHelper);
  11264. + }
  11265. // Otherwise call static method findNative in ClassLoader
  11266. KlassHandle klass (THREAD, SystemDictionary::ClassLoader_klass());
  11267. diff -r 6c6a2299029a src/share/vm/runtime/arguments.cpp
  11268. --- a/src/share/vm/runtime/arguments.cpp Sat Dec 14 11:51:15 2013 -0800
  11269. +++ b/src/share/vm/runtime/arguments.cpp Mon Apr 28 13:12:30 2014 -0700
  11270. @@ -1792,6 +1792,15 @@
  11271. status = false;
  11272. }
  11273. + // (tw) Must use serial GC
  11274. + if (!UseSerialGC && i >= 1) {
  11275. + jio_fprintf(defaultStream::error_stream(),
  11276. + "Must use the serial GC in the Dynamic Code Evolution VM\n");
  11277. + status = false;
  11278. + } else {
  11279. + UseSerialGC = true;
  11280. + }
  11281. +
  11282. return status;
  11283. }
  11284. diff -r 6c6a2299029a src/share/vm/runtime/deoptimization.cpp
  11285. --- a/src/share/vm/runtime/deoptimization.cpp Sat Dec 14 11:51:15 2013 -0800
  11286. +++ b/src/share/vm/runtime/deoptimization.cpp Mon Apr 28 13:12:30 2014 -0700
  11287. @@ -599,6 +599,38 @@
  11288. // Cleanup thread deopt data
  11289. cleanup_deopt_info(thread, array);
  11290. + // (tw) Redefinition support: Check if we need to transfer method execution points to new versions
  11291. + {
  11292. + ResourceMark res_mark;
  11293. +
  11294. + // Verify that the just-unpacked frames match the interpreter's
  11295. + // notions of expression stack and locals
  11296. + vframeArray* cur_array = thread->vframe_array_last();
  11297. + RegisterMap rm(thread, false);
  11298. + rm.set_include_argument_oops(false);
  11299. + for (int i = 0; i < cur_array->frames(); i++) {
  11300. + vframeArrayElement* el = cur_array->element(i);
  11301. + frame* frame = el->iframe();
  11302. + guarantee(frame->is_interpreted_frame(), "Wrong frame type");
  11303. + RegisterMap reg_map(thread);
  11304. + vframe* vf = vframe::new_vframe(frame, &reg_map, thread);
  11305. + interpretedVFrame *iframe = (interpretedVFrame *)vf;
  11306. + methodOop method = iframe->method();
  11307. + int bci = iframe->bci();
  11308. + method = method->newest_version();
  11309. + iframe->set_method(method, bci);
  11310. +
  11311. + methodOop forward_method = method->forward_method();
  11312. + if (forward_method != NULL && method->is_in_code_section(bci)) {
  11313. + int new_bci = method->calculate_forward_bci(bci, forward_method);
  11314. + if (TraceRedefineClasses >= 2) {
  11315. + 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);
  11316. + }
  11317. + iframe->set_method(forward_method, new_bci);
  11318. + }
  11319. + }
  11320. + }
  11321. +
  11322. #ifndef PRODUCT
  11323. if (VerifyStack) {
  11324. ResourceMark res_mark;
  11325. diff -r 6c6a2299029a src/share/vm/runtime/frame.cpp
  11326. --- a/src/share/vm/runtime/frame.cpp Sat Dec 14 11:51:15 2013 -0800
  11327. +++ b/src/share/vm/runtime/frame.cpp Mon Apr 28 13:12:30 2014 -0700
  11328. @@ -407,6 +407,12 @@
  11329. *interpreter_frame_method_addr() = method;
  11330. }
  11331. +// (tw) Sets constant pool cache oop
  11332. +void frame::interpreter_frame_set_cache(constantPoolCacheOop cp) {
  11333. + assert(is_interpreted_frame(), "interpreted frame expected");
  11334. + *interpreter_frame_cache_addr() = cp;
  11335. +}
  11336. +
  11337. void frame::interpreter_frame_set_bcx(intptr_t bcx) {
  11338. assert(is_interpreted_frame(), "Not an interpreted frame");
  11339. if (ProfileInterpreter) {
  11340. @@ -422,19 +428,27 @@
  11341. // The bcx was just converted from bci to bcp.
  11342. // Convert the mdx in parallel.
  11343. methodDataOop mdo = interpreter_frame_method()->method_data();
  11344. - assert(mdo != NULL, "");
  11345. - int mdi = mdx - 1; // We distinguish valid mdi from zero by adding one.
  11346. - address mdp = mdo->di_to_dp(mdi);
  11347. - interpreter_frame_set_mdx((intptr_t)mdp);
  11348. + if (mdo == NULL) {
  11349. + interpreter_frame_set_mdx(0);
  11350. + } else {
  11351. + assert(mdo != NULL, "");
  11352. + int mdi = mdx - 1; // We distinguish valid mdi from zero by adding one.
  11353. + address mdp = mdo->di_to_dp(mdi);
  11354. + interpreter_frame_set_mdx((intptr_t)mdp);
  11355. + }
  11356. }
  11357. } else {
  11358. if (is_now_bci) {
  11359. // The bcx was just converted from bcp to bci.
  11360. // Convert the mdx in parallel.
  11361. methodDataOop mdo = interpreter_frame_method()->method_data();
  11362. - assert(mdo != NULL, "");
  11363. - int mdi = mdo->dp_to_di((address)mdx);
  11364. - interpreter_frame_set_mdx((intptr_t)mdi + 1); // distinguish valid from 0.
  11365. + if (mdo == NULL) {
  11366. + interpreter_frame_set_mdx(0);
  11367. + } else {
  11368. + assert(mdo != NULL, "");
  11369. + int mdi = mdo->dp_to_di((address)mdx);
  11370. + interpreter_frame_set_mdx((intptr_t)mdi + 1); // distinguish valid from 0.
  11371. + }
  11372. }
  11373. }
  11374. }
  11375. diff -r 6c6a2299029a src/share/vm/runtime/frame.hpp
  11376. --- a/src/share/vm/runtime/frame.hpp Sat Dec 14 11:51:15 2013 -0800
  11377. +++ b/src/share/vm/runtime/frame.hpp Mon Apr 28 13:12:30 2014 -0700
  11378. @@ -346,6 +346,7 @@
  11379. // Method & constant pool cache
  11380. methodOop interpreter_frame_method() const;
  11381. void interpreter_frame_set_method(methodOop method);
  11382. + void interpreter_frame_set_cache(constantPoolCacheOop method);
  11383. methodOop* interpreter_frame_method_addr() const;
  11384. constantPoolCacheOop* interpreter_frame_cache_addr() const;
  11385. #ifdef PPC
  11386. diff -r 6c6a2299029a src/share/vm/runtime/globals.hpp
  11387. --- a/src/share/vm/runtime/globals.hpp Sat Dec 14 11:51:15 2013 -0800
  11388. +++ b/src/share/vm/runtime/globals.hpp Mon Apr 28 13:12:30 2014 -0700
  11389. @@ -1227,9 +1227,23 @@
  11390. product(bool, StressLdcRewrite, false, \
  11391. "Force ldc -> ldc_w rewrite during RedefineClasses") \
  11392. \
  11393. + product(bool, UseMethodForwardPoints, false, \
  11394. + "Use method forward points") \
  11395. + \
  11396. + product(intx, MethodForwardPointsMaxLocals, 300, \
  11397. + "Maximum number of locals in forwarding method") \
  11398. + \
  11399. + product(intx, MethodForwardPointsMaxStack, 300, \
  11400. + "Maximum number of stack slots in forwarding method") \
  11401. + \
  11402. product(intx, TraceRedefineClasses, 0, \
  11403. "Trace level for JVMTI RedefineClasses") \
  11404. \
  11405. + product(bool, TimeRedefineClasses, false, \
  11406. + "Measure timing for JVMTI RedefineClasses") \
  11407. + \
  11408. + product(bool, AllowAdvancedClassRedefinition, true, \
  11409. + "Allow advanced class redefinition beyond swapping method bodies")\
  11410. develop(bool, StressMethodComparator, false, \
  11411. "run the MethodComparator on all loaded methods") \
  11412. \
  11413. diff -r 6c6a2299029a src/share/vm/runtime/interfaceSupport.hpp
  11414. --- a/src/share/vm/runtime/interfaceSupport.hpp Sat Dec 14 11:51:15 2013 -0800
  11415. +++ b/src/share/vm/runtime/interfaceSupport.hpp Mon Apr 28 13:12:30 2014 -0700
  11416. @@ -296,7 +296,7 @@
  11417. ThreadToNativeFromVM(JavaThread *thread) : ThreadStateTransition(thread) {
  11418. // We are leaving the VM at this point and going directly to native code.
  11419. // Block, if we are in the middle of a safepoint synchronization.
  11420. - assert(!thread->owns_locks(), "must release all locks when leaving VM");
  11421. + assert(!thread->owns_locks_but_redefine_classes_lock(), "must release all locks when leaving VM");
  11422. thread->frame_anchor()->make_walkable(thread);
  11423. trans_and_fence(_thread_in_vm, _thread_in_native);
  11424. // Check for pending. async. exceptions or suspends.
  11425. diff -r 6c6a2299029a src/share/vm/runtime/javaCalls.cpp
  11426. --- a/src/share/vm/runtime/javaCalls.cpp Sat Dec 14 11:51:15 2013 -0800
  11427. +++ b/src/share/vm/runtime/javaCalls.cpp Mon Apr 28 13:12:30 2014 -0700
  11428. @@ -60,7 +60,7 @@
  11429. bool clear_pending_exception = true;
  11430. guarantee(thread->is_Java_thread(), "crucial check - the VM thread cannot and must not escape to Java code");
  11431. - assert(!thread->owns_locks(), "must release all locks when leaving VM");
  11432. + assert(!thread->owns_locks_but_redefine_classes_lock(), "must release all locks when leaving VM");
  11433. guarantee(!thread->is_Compiler_thread(), "cannot make java calls from the compiler");
  11434. _result = result;
  11435. diff -r 6c6a2299029a src/share/vm/runtime/jniHandles.cpp
  11436. --- a/src/share/vm/runtime/jniHandles.cpp Sat Dec 14 11:51:15 2013 -0800
  11437. +++ b/src/share/vm/runtime/jniHandles.cpp Mon Apr 28 13:12:30 2014 -0700
  11438. @@ -112,6 +112,10 @@
  11439. }
  11440. jmethodID JNIHandles::make_jmethod_id(methodHandle mh) {
  11441. + if (mh->newest_version() != mh()) {
  11442. + methodHandle mh_new(Thread::current(), mh()->newest_version());
  11443. + return (jmethodID) make_weak_global(mh_new);
  11444. + }
  11445. return (jmethodID) make_weak_global(mh);
  11446. }
  11447. diff -r 6c6a2299029a src/share/vm/runtime/mutex.cpp
  11448. --- a/src/share/vm/runtime/mutex.cpp Sat Dec 14 11:51:15 2013 -0800
  11449. +++ b/src/share/vm/runtime/mutex.cpp Mon Apr 28 13:12:30 2014 -0700
  11450. @@ -1227,7 +1227,7 @@
  11451. // in increasing rank order (modulo any native ranks)
  11452. for (tmp = locks; tmp != NULL; tmp = tmp->next()) {
  11453. if (tmp->next() != NULL) {
  11454. - assert(tmp->rank() == Mutex::native ||
  11455. + assert(tmp->rank() == Mutex::native || tmp->rank() == Mutex::redefine_classes ||
  11456. tmp->rank() <= tmp->next()->rank(), "mutex rank anomaly?");
  11457. }
  11458. }
  11459. @@ -1247,7 +1247,7 @@
  11460. // in increasing rank order (modulo any native ranks)
  11461. for (tmp = locks; tmp != NULL; tmp = tmp->next()) {
  11462. if (tmp->next() != NULL) {
  11463. - assert(tmp->rank() == Mutex::native ||
  11464. + assert(tmp->rank() == Mutex::native || tmp->rank() == Mutex::redefine_classes ||
  11465. tmp->rank() <= tmp->next()->rank(), "mutex rank anomaly?");
  11466. }
  11467. }
  11468. @@ -1310,6 +1310,7 @@
  11469. // already hold Terminator_lock - may happen because of periodic safepoints
  11470. if (this->rank() != Mutex::native &&
  11471. this->rank() != Mutex::suspend_resume &&
  11472. + this->rank() != Mutex::redefine_classes &&
  11473. locks != NULL && locks->rank() <= this->rank() &&
  11474. !SafepointSynchronize::is_at_safepoint() &&
  11475. this != Interrupt_lock &&
  11476. diff -r 6c6a2299029a src/share/vm/runtime/mutex.hpp
  11477. --- a/src/share/vm/runtime/mutex.hpp Sat Dec 14 11:51:15 2013 -0800
  11478. +++ b/src/share/vm/runtime/mutex.hpp Mon Apr 28 13:12:30 2014 -0700
  11479. @@ -109,7 +109,8 @@
  11480. barrier = safepoint + 1,
  11481. nonleaf = barrier + 1,
  11482. max_nonleaf = nonleaf + 900,
  11483. - native = max_nonleaf + 1
  11484. + native = max_nonleaf + 1,
  11485. + redefine_classes = native + 1
  11486. };
  11487. // The WaitSet and EntryList linked lists are composed of ParkEvents.
  11488. diff -r 6c6a2299029a src/share/vm/runtime/mutexLocker.cpp
  11489. --- a/src/share/vm/runtime/mutexLocker.cpp Sat Dec 14 11:51:15 2013 -0800
  11490. +++ b/src/share/vm/runtime/mutexLocker.cpp Mon Apr 28 13:12:30 2014 -0700
  11491. @@ -49,6 +49,7 @@
  11492. // Consider using GCC's __read_mostly.
  11493. Mutex* Patching_lock = NULL;
  11494. +Mutex* RedefineClasses_lock = NULL;
  11495. Monitor* SystemDictionary_lock = NULL;
  11496. Mutex* PackageTable_lock = NULL;
  11497. Mutex* CompiledIC_lock = NULL;
  11498. @@ -90,6 +91,7 @@
  11499. Mutex* DirtyCardQ_FL_lock = NULL;
  11500. Monitor* DirtyCardQ_CBL_mon = NULL;
  11501. Mutex* Shared_DirtyCardQ_lock = NULL;
  11502. +Monitor* RedefinitionSync_lock = NULL;
  11503. Mutex* ParGCRareEvent_lock = NULL;
  11504. Mutex* EvacFailureStack_lock = NULL;
  11505. Mutex* DerivedPointerTableGC_lock = NULL;
  11506. @@ -207,6 +209,7 @@
  11507. def(HotCardCache_lock , Mutex , special , true );
  11508. def(EvacFailureStack_lock , Mutex , nonleaf , true );
  11509. }
  11510. + def(RedefinitionSync_lock , Monitor , leaf , false );
  11511. def(ParGCRareEvent_lock , Mutex , leaf , true );
  11512. def(DerivedPointerTableGC_lock , Mutex, leaf, true );
  11513. def(CodeCache_lock , Mutex , special, true );
  11514. @@ -281,6 +284,7 @@
  11515. def(Debug3_lock , Mutex , nonleaf+4, true );
  11516. def(CompileThread_lock , Monitor, nonleaf+5, false);
  11517. def(PeriodicTask_lock , Monitor, nonleaf+5, true);
  11518. + def(RedefineClasses_lock , Mutex , nonleaf+7, false ); // for ensuring that class redefinition is not done in parallel
  11519. #ifdef INCLUDE_TRACE
  11520. def(JfrMsg_lock , Monitor, leaf, true);
  11521. diff -r 6c6a2299029a src/share/vm/runtime/mutexLocker.hpp
  11522. --- a/src/share/vm/runtime/mutexLocker.hpp Sat Dec 14 11:51:15 2013 -0800
  11523. +++ b/src/share/vm/runtime/mutexLocker.hpp Mon Apr 28 13:12:30 2014 -0700
  11524. @@ -43,6 +43,8 @@
  11525. // Mutexes used in the VM.
  11526. extern Mutex* Patching_lock; // a lock used to guard code patching of compiled code
  11527. +extern Monitor* RedefinitionSync_lock; // a lock on synchronized class redefinition
  11528. +extern Mutex* RedefineClasses_lock; // a lock on class redefinition
  11529. extern Monitor* SystemDictionary_lock; // a lock on the system dictonary
  11530. extern Mutex* PackageTable_lock; // a lock on the class loader package table
  11531. extern Mutex* CompiledIC_lock; // a lock used to guard compiled IC patching and access
  11532. diff -r 6c6a2299029a src/share/vm/runtime/reflection.cpp
  11533. --- a/src/share/vm/runtime/reflection.cpp Sat Dec 14 11:51:15 2013 -0800
  11534. +++ b/src/share/vm/runtime/reflection.cpp Mon Apr 28 13:12:30 2014 -0700
  11535. @@ -468,7 +468,8 @@
  11536. // sun/reflect/MagicAccessorImpl subclasses to succeed trivially.
  11537. if ( JDK_Version::is_gte_jdk14x_version()
  11538. && UseNewReflection
  11539. - && Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass())) {
  11540. + && (Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()) ||
  11541. + Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()->klass_part()->newest_version()))) {
  11542. return true;
  11543. }
  11544. @@ -519,6 +520,12 @@
  11545. AccessFlags access,
  11546. bool classloader_only,
  11547. bool protected_restriction) {
  11548. +
  11549. + // (tw) Decide accessibility based on active version
  11550. + if (current_class != NULL) {
  11551. + current_class = current_class->klass_part()->active_version();
  11552. + }
  11553. +
  11554. // Verify that current_class can access a field of field_class, where that
  11555. // field's access bits are "access". We assume that we've already verified
  11556. // that current_class can access field_class.
  11557. @@ -560,7 +567,8 @@
  11558. // sun/reflect/MagicAccessorImpl subclasses to succeed trivially.
  11559. if ( JDK_Version::is_gte_jdk14x_version()
  11560. && UseNewReflection
  11561. - && Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass())) {
  11562. + && (Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()) ||
  11563. + Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()->klass_part()->newest_version()))) {
  11564. return true;
  11565. }
  11566. diff -r 6c6a2299029a src/share/vm/runtime/sharedRuntime.cpp
  11567. --- a/src/share/vm/runtime/sharedRuntime.cpp Sat Dec 14 11:51:15 2013 -0800
  11568. +++ b/src/share/vm/runtime/sharedRuntime.cpp Mon Apr 28 13:12:30 2014 -0700
  11569. @@ -1137,7 +1137,20 @@
  11570. if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
  11571. int retry_count = 0;
  11572. while (!HAS_PENDING_EXCEPTION && callee_method->is_old() &&
  11573. - callee_method->method_holder() != SystemDictionary::Object_klass()) {
  11574. + callee_method->method_holder()->klass_part()->newest_version() != SystemDictionary::Object_klass()->klass_part()->newest_version()) {
  11575. +
  11576. + // DCEVM: If we are executing an old method, this is OK!
  11577. + {
  11578. + ResourceMark rm(thread);
  11579. + RegisterMap cbl_map(thread, false);
  11580. + frame caller_frame = thread->last_frame().sender(&cbl_map);
  11581. +
  11582. + CodeBlob* caller_cb = caller_frame.cb();
  11583. + guarantee(caller_cb != NULL && caller_cb->is_nmethod(), "must be called from nmethod");
  11584. + nmethod* caller_nm = caller_cb->as_nmethod_or_null();
  11585. + if (caller_nm->method()->is_old()) break;
  11586. + }
  11587. +
  11588. // If has a pending exception then there is no need to re-try to
  11589. // resolve this method.
  11590. // If the method has been redefined, we need to try again.
  11591. diff -r 6c6a2299029a src/share/vm/runtime/thread.cpp
  11592. --- a/src/share/vm/runtime/thread.cpp Sat Dec 14 11:51:15 2013 -0800
  11593. +++ b/src/share/vm/runtime/thread.cpp Mon Apr 28 13:12:30 2014 -0700
  11594. @@ -216,6 +216,8 @@
  11595. set_self_raw_id(0);
  11596. set_lgrp_id(-1);
  11597. + _redefine_classes_mutex = new Mutex(Mutex::redefine_classes, "redefine classes lock", false);
  11598. +
  11599. // allocated data structures
  11600. set_osthread(NULL);
  11601. set_resource_area(new (mtThread)ResourceArea());
  11602. @@ -249,6 +251,7 @@
  11603. omFreeProvision = 32 ;
  11604. omInUseList = NULL ;
  11605. omInUseCount = 0 ;
  11606. + _pretend_new_universe = false;
  11607. #ifdef ASSERT
  11608. _visited_for_critical_count = false;
  11609. @@ -884,6 +887,15 @@
  11610. return false;
  11611. }
  11612. +bool Thread::owns_locks_but_redefine_classes_lock() const {
  11613. + for(Monitor *cur = _owned_locks; cur; cur = cur->next()) {
  11614. + if (cur != RedefineClasses_lock && cur->rank() != Mutex::redefine_classes) {
  11615. + return true;
  11616. + }
  11617. + }
  11618. + return false;
  11619. +}
  11620. +
  11621. #endif
  11622. @@ -1637,7 +1649,7 @@
  11623. ThreadStateTransition::transition_and_fence(this, _thread_new, _thread_in_vm);
  11624. assert(JavaThread::current() == this, "sanity check");
  11625. - assert(!Thread::current()->owns_locks(), "sanity check");
  11626. + assert(!Thread::current()->owns_locks_but_redefine_classes_lock(), "sanity check");
  11627. DTRACE_THREAD_PROBE(start, this);
  11628. @@ -3193,7 +3205,7 @@
  11629. // Create a CompilerThread
  11630. CompilerThread::CompilerThread(CompileQueue* queue, CompilerCounters* counters)
  11631. -: JavaThread(&compiler_thread_entry) {
  11632. +: JavaThread(&compiler_thread_entry), _should_bailout(false) {
  11633. _env = NULL;
  11634. _log = NULL;
  11635. _task = NULL;
  11636. @@ -3201,6 +3213,7 @@
  11637. _counters = counters;
  11638. _buffer_blob = NULL;
  11639. _scanned_nmethod = NULL;
  11640. + _compilation_mutex = new Mutex(Mutex::redefine_classes, "compilationMutex", false);
  11641. #ifndef PRODUCT
  11642. _ideal_graph_printer = NULL;
  11643. @@ -3230,6 +3243,7 @@
  11644. int Threads::_number_of_non_daemon_threads = 0;
  11645. int Threads::_return_code = 0;
  11646. size_t JavaThread::_stack_size_at_create = 0;
  11647. +bool Threads::_wait_at_instrumentation_entry = false;
  11648. // All JavaThreads
  11649. #define ALL_JAVA_THREADS(X) for (JavaThread* X = _thread_list; X; X = X->next())
  11650. diff -r 6c6a2299029a src/share/vm/runtime/thread.hpp
  11651. --- a/src/share/vm/runtime/thread.hpp Sat Dec 14 11:51:15 2013 -0800
  11652. +++ b/src/share/vm/runtime/thread.hpp Mon Apr 28 13:12:30 2014 -0700
  11653. @@ -203,11 +203,14 @@
  11654. void enter_signal_handler() { _num_nested_signal++; }
  11655. void leave_signal_handler() { _num_nested_signal--; }
  11656. bool is_inside_signal_handler() const { return _num_nested_signal > 0; }
  11657. + Mutex* redefine_classes_mutex() { return _redefine_classes_mutex; }
  11658. private:
  11659. // Debug tracing
  11660. static void trace(const char* msg, const Thread* const thread) PRODUCT_RETURN;
  11661. + Mutex* _redefine_classes_mutex;
  11662. +
  11663. // Active_handles points to a block of handles
  11664. JNIHandleBlock* _active_handles;
  11665. @@ -530,10 +533,15 @@
  11666. uintptr_t _self_raw_id; // used by get_thread (mutable)
  11667. int _lgrp_id;
  11668. +
  11669. + bool _pretend_new_universe;
  11670. +
  11671. public:
  11672. // Stack overflow support
  11673. address stack_base() const { assert(_stack_base != NULL,"Sanity check"); return _stack_base; }
  11674. + 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; } }
  11675. + bool pretend_new_universe() { return _pretend_new_universe; }
  11676. void set_stack_base(address base) { _stack_base = base; }
  11677. size_t stack_size() const { return _stack_size; }
  11678. void set_stack_size(size_t size) { _stack_size = size; }
  11679. @@ -570,6 +578,7 @@
  11680. void print_owned_locks() const { print_owned_locks_on(tty); }
  11681. Monitor* owned_locks() const { return _owned_locks; }
  11682. bool owns_locks() const { return owned_locks() != NULL; }
  11683. + bool owns_locks_but_redefine_classes_lock() const;
  11684. bool owns_locks_but_compiled_lock() const;
  11685. // Deadlock detection
  11686. @@ -1793,6 +1802,8 @@
  11687. CompileTask* _task;
  11688. CompileQueue* _queue;
  11689. BufferBlob* _buffer_blob;
  11690. + bool _should_bailout;
  11691. + Mutex* _compilation_mutex;
  11692. nmethod* _scanned_nmethod; // nmethod being scanned by the sweeper
  11693. @@ -1802,12 +1813,16 @@
  11694. CompilerThread(CompileQueue* queue, CompilerCounters* counters);
  11695. + bool should_bailout() const { return _should_bailout; }
  11696. + void set_should_bailout(bool b) { _should_bailout = false; }
  11697. +
  11698. bool is_Compiler_thread() const { return true; }
  11699. // Hide this compiler thread from external view.
  11700. bool is_hidden_from_external_view() const { return true; }
  11701. CompileQueue* queue() { return _queue; }
  11702. CompilerCounters* counters() { return _counters; }
  11703. + Mutex *compilation_mutex() { return _compilation_mutex; }
  11704. // Get/set the thread's compilation environment.
  11705. ciEnv* env() { return _env; }
  11706. @@ -1862,6 +1877,7 @@
  11707. static int _number_of_threads;
  11708. static int _number_of_non_daemon_threads;
  11709. static int _return_code;
  11710. + static bool _wait_at_instrumentation_entry;
  11711. public:
  11712. // Thread management
  11713. @@ -1873,6 +1889,9 @@
  11714. static JavaThread* first() { return _thread_list; }
  11715. static void threads_do(ThreadClosure* tc);
  11716. + static bool wait_at_instrumentation_entry() { return _wait_at_instrumentation_entry; }
  11717. + static void set_wait_at_instrumentation_entry(bool b) { _wait_at_instrumentation_entry = b; }
  11718. +
  11719. // Initializes the vm and creates the vm thread
  11720. static jint create_vm(JavaVMInitArgs* args, bool* canTryAgain);
  11721. static void convert_vm_init_libraries_to_agents();
  11722. diff -r 6c6a2299029a src/share/vm/runtime/vframe.cpp
  11723. --- a/src/share/vm/runtime/vframe.cpp Sat Dec 14 11:51:15 2013 -0800
  11724. +++ b/src/share/vm/runtime/vframe.cpp Mon Apr 28 13:12:30 2014 -0700
  11725. @@ -253,6 +253,46 @@
  11726. return fr().interpreter_frame_method();
  11727. }
  11728. +// (tw) Sets interpreter frame method.
  11729. +void interpretedVFrame::set_method(methodOop new_method, int new_bci) {
  11730. + methodOop old_method = fr().interpreter_frame_method();
  11731. + int old_stack_size = fr().interpreter_frame_expression_stack_size();
  11732. + if (old_method == new_method) return;
  11733. + u_char *old_bcp = bcp();
  11734. + int old_bci = bci();
  11735. + fr().interpreter_frame_set_method(new_method);
  11736. + fr().interpreter_frame_set_cache(new_method->constants()->cache());
  11737. + u_char *new_bcp = new_method->code_base() + new_bci;
  11738. + assert(new_method->bcp_from(new_bci) == new_bcp, "");
  11739. +
  11740. + set_bcp(new_bcp);
  11741. +
  11742. + Bytecodes::Code code = Bytecodes::java_code_at(old_method, old_bcp);
  11743. + assert(Bytecodes::java_code_at(new_method, new_bcp) == code, "must have same bytecode at this position");
  11744. +
  11745. + switch (code) {
  11746. + case Bytecodes::_invokevirtual :
  11747. + case Bytecodes::_invokespecial :
  11748. + case Bytecodes::_invokestatic :
  11749. + case Bytecodes::_invokeinterface: {
  11750. + int old_index = Bytes::get_native_u2(old_bcp+1);
  11751. + int new_index = Bytes::get_native_u2(new_bcp+1);
  11752. + new_method->constants()->cache()->entry_at(new_index)->copy_from(old_method->constants()->cache()->entry_at(old_index));
  11753. + break;
  11754. + }
  11755. +
  11756. + case Bytecodes::_invokedynamic: {
  11757. + int old_index = Bytes::get_native_u4(old_bcp+1);
  11758. + int new_index = Bytes::get_native_u4(new_bcp+1);
  11759. + new_method->constants()->cache()->secondary_entry_at(new_index)->copy_from(old_method->constants()->cache()->secondary_entry_at(old_index));
  11760. + break;
  11761. + }
  11762. + }
  11763. +
  11764. + int new_stack_size = fr().interpreter_frame_expression_stack_size();
  11765. + assert(new_method->validate_bci_from_bcx((intptr_t)new_bcp) == new_bci, "");
  11766. +}
  11767. +
  11768. StackValueCollection* interpretedVFrame::locals() const {
  11769. int length = method()->max_locals();
  11770. diff -r 6c6a2299029a src/share/vm/runtime/vframe.hpp
  11771. --- a/src/share/vm/runtime/vframe.hpp Sat Dec 14 11:51:15 2013 -0800
  11772. +++ b/src/share/vm/runtime/vframe.hpp Mon Apr 28 13:12:30 2014 -0700
  11773. @@ -163,6 +163,7 @@
  11774. StackValueCollection* locals() const;
  11775. StackValueCollection* expressions() const;
  11776. GrowableArray<MonitorInfo*>* monitors() const;
  11777. + void set_method(methodOop method, int new_bci);
  11778. void set_locals(StackValueCollection* values) const;
  11779. diff -r 6c6a2299029a src/share/vm/runtime/vmThread.cpp
  11780. --- a/src/share/vm/runtime/vmThread.cpp Sat Dec 14 11:51:15 2013 -0800
  11781. +++ b/src/share/vm/runtime/vmThread.cpp Mon Apr 28 13:12:30 2014 -0700
  11782. @@ -691,6 +691,10 @@
  11783. void VMThread::oops_do(OopClosure* f, CodeBlobClosure* cf) {
  11784. Thread::oops_do(f, cf);
  11785. _vm_queue->oops_do(f);
  11786. + // (DCEVM) need to update oops in VM_RedefineClasses!
  11787. + if (_cur_vm_operation != NULL) {
  11788. + _cur_vm_operation->oops_do(f);
  11789. + }
  11790. }
  11791. //------------------------------------------------------------------------------------------------------------------
  11792. diff -r 6c6a2299029a src/share/vm/utilities/exceptions.cpp
  11793. --- a/src/share/vm/utilities/exceptions.cpp Sat Dec 14 11:51:15 2013 -0800
  11794. +++ b/src/share/vm/utilities/exceptions.cpp Mon Apr 28 13:12:30 2014 -0700
  11795. @@ -254,6 +254,8 @@
  11796. assert(thread->is_Java_thread(), "can only be called by a Java thread");
  11797. assert(!thread->has_pending_exception(), "already has exception");
  11798. + bool old_pretend_value = Thread::current()->pretend_new_universe();
  11799. + Thread::current()->set_pretend_new_universe(false);
  11800. Handle h_exception;
  11801. // Resolve exception klass
  11802. @@ -285,6 +287,7 @@
  11803. h_exception = Handle(thread, thread->pending_exception());
  11804. thread->clear_pending_exception();
  11805. }
  11806. + Thread::current()->set_pretend_new_universe(old_pretend_value);
  11807. return h_exception;
  11808. }
  11809. @@ -295,6 +298,8 @@
  11810. Symbol* signature, JavaCallArguments *args,
  11811. Handle h_cause,
  11812. Handle h_loader, Handle h_protection_domain) {
  11813. + bool old_pretend_value = Thread::current()->pretend_new_universe();
  11814. + Thread::current()->set_pretend_new_universe(false);
  11815. Handle h_exception = new_exception(thread, name, signature, args, h_loader, h_protection_domain);
  11816. // Future: object initializer should take a cause argument
  11817. @@ -317,6 +322,8 @@
  11818. h_exception = Handle(thread, thread->pending_exception());
  11819. thread->clear_pending_exception();
  11820. }
  11821. +
  11822. + Thread::current()->set_pretend_new_universe(old_pretend_value);
  11823. return h_exception;
  11824. }
  11825. diff -r 6c6a2299029a src/share/vm/utilities/growableArray.hpp
  11826. --- a/src/share/vm/utilities/growableArray.hpp Sat Dec 14 11:51:15 2013 -0800
  11827. +++ b/src/share/vm/utilities/growableArray.hpp Mon Apr 28 13:12:30 2014 -0700
  11828. @@ -145,6 +145,33 @@
  11829. assert(on_stack(), "fast ResourceObj path only");
  11830. return (void*)resource_allocate_bytes(thread, elementSize * _max);
  11831. }
  11832. +
  11833. +};
  11834. +
  11835. +template<class E, class F> class Pair : public StackObj
  11836. +{
  11837. +private:
  11838. + E _left;
  11839. + F _right;
  11840. +
  11841. +public:
  11842. +
  11843. + Pair() {
  11844. +
  11845. + }
  11846. +
  11847. + Pair(E left, F right) {
  11848. + this->_left = left;
  11849. + this->_right = right;
  11850. + }
  11851. +
  11852. + E left() {
  11853. + return _left;
  11854. + }
  11855. +
  11856. + F right() {
  11857. + return _right;
  11858. + }
  11859. };
  11860. template<class E> class GrowableArray : public GenericGrowableArray {