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-jdk7u71-b01.patch 520KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176
  1. diff --git a/make/bsd/makefiles/gcc.make b/make/bsd/makefiles/gcc.make
  2. index 3de1dea..8bf7f94 100644
  3. --- a/make/bsd/makefiles/gcc.make
  4. +++ b/make/bsd/makefiles/gcc.make
  5. @@ -117,7 +117,10 @@ CFLAGS += $(VM_PICFLAG)
  6. CFLAGS += -fno-rtti
  7. CFLAGS += -fno-exceptions
  8. CFLAGS += -pthread
  9. -CFLAGS += -fcheck-new
  10. +## well, strictly speaking we should check for clang not Darwin
  11. +ifneq ($(OS_VENDOR), Darwin)
  12. + CFLAGS += -fcheck-new
  13. +endif
  14. # version 4 and above support fvisibility=hidden (matches jni_x86.h file)
  15. # except 4.1.2 gives pointless warnings that can't be disabled (afaik)
  16. ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0"
  17. diff --git a/src/cpu/x86/vm/templateTable_x86_32.cpp b/src/cpu/x86/vm/templateTable_x86_32.cpp
  18. index fc19edc..d2cddd3 100644
  19. --- a/src/cpu/x86/vm/templateTable_x86_32.cpp
  20. +++ b/src/cpu/x86/vm/templateTable_x86_32.cpp
  21. @@ -2109,6 +2109,22 @@ void TemplateTable::resolve_cache_and_index(int byte_no,
  22. // resolve first time through
  23. address entry;
  24. switch (bytecode()) {
  25. + case Bytecodes::_fast_agetfield : // fall through
  26. + case Bytecodes::_fast_bgetfield : // fall through
  27. + case Bytecodes::_fast_cgetfield : // fall through
  28. + case Bytecodes::_fast_dgetfield : // fall through
  29. + case Bytecodes::_fast_fgetfield : // fall through
  30. + case Bytecodes::_fast_igetfield : // fall through
  31. + case Bytecodes::_fast_lgetfield : // fall through
  32. + case Bytecodes::_fast_sgetfield : // fall through
  33. + case Bytecodes::_fast_aputfield : // fall through
  34. + case Bytecodes::_fast_bputfield : // fall through
  35. + case Bytecodes::_fast_cputfield : // fall through
  36. + case Bytecodes::_fast_dputfield : // fall through
  37. + case Bytecodes::_fast_fputfield : // fall through
  38. + case Bytecodes::_fast_iputfield : // fall through
  39. + case Bytecodes::_fast_lputfield : // fall through
  40. + case Bytecodes::_fast_sputfield : // fall through
  41. case Bytecodes::_getstatic : // fall through
  42. case Bytecodes::_putstatic : // fall through
  43. case Bytecodes::_getfield : // fall through
  44. @@ -2211,6 +2227,7 @@ void TemplateTable::load_invoke_cp_cache_entry(int byte_no,
  45. // Correct values of the cache and index registers are preserved.
  46. void TemplateTable::jvmti_post_field_access(Register cache,
  47. Register index,
  48. + int byte_no,
  49. bool is_static,
  50. bool has_tos) {
  51. if (JvmtiExport::can_post_field_access()) {
  52. @@ -2237,7 +2254,11 @@ void TemplateTable::jvmti_post_field_access(Register cache,
  53. // cache: cache entry pointer
  54. __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access),
  55. rax, cache);
  56. - __ get_cache_and_index_at_bcp(cache, index, 1);
  57. +
  58. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  59. + __ restore_bcp();
  60. + resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  61. +
  62. __ bind(L1);
  63. }
  64. }
  65. @@ -2258,7 +2279,7 @@ void TemplateTable::getfield_or_static(int byte_no, bool is_static) {
  66. const Register flags = rax;
  67. resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  68. - jvmti_post_field_access(cache, index, is_static, false);
  69. + jvmti_post_field_access(cache, index, byte_no, is_static, false);
  70. load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  71. if (!is_static) pop_and_check_object(obj);
  72. @@ -2393,7 +2414,7 @@ void TemplateTable::getstatic(int byte_no) {
  73. // The registers cache and index expected to be set before call.
  74. // The function may destroy various registers, just not the cache and index registers.
  75. -void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is_static) {
  76. +void TemplateTable::jvmti_post_field_mod(Register cache, Register index, int byte_no, bool is_static) {
  77. ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();
  78. @@ -2451,7 +2472,11 @@ void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is
  79. // rcx: jvalue object on the stack
  80. __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification),
  81. rbx, rax, rcx);
  82. - __ get_cache_and_index_at_bcp(cache, index, 1);
  83. +
  84. + // (tw) Redefinition might have occured => reresolve the cp entry.
  85. + __ restore_bcp();
  86. + resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  87. +
  88. __ bind(L1);
  89. }
  90. }
  91. @@ -2467,7 +2492,7 @@ void TemplateTable::putfield_or_static(int byte_no, bool is_static) {
  92. const Register flags = rax;
  93. resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  94. - jvmti_post_field_mod(cache, index, is_static);
  95. + jvmti_post_field_mod(cache, index, byte_no, is_static);
  96. load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  97. // Doug Lea believes this is not needed with current Sparcs (TSO) and Intel (PSO).
  98. @@ -2818,6 +2843,11 @@ void TemplateTable::fast_accessfield(TosState state) {
  99. // rcx: cache entry pointer
  100. __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access), rax, rcx);
  101. __ pop_ptr(rax); // restore object pointer
  102. +
  103. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  104. + __ restore_bcp();
  105. + resolve_cache_and_index(1, noreg, rax, rcx, sizeof(u2));
  106. +
  107. __ bind(L1);
  108. }
  109. @@ -3008,6 +3038,26 @@ void TemplateTable::invokevirtual_helper(Register index,
  110. __ bind(notFinal);
  111. + // DCEVM: Check if we are calling an old method (and have to go slow path)
  112. + Label notOld;
  113. + __ movl(rax, flags);
  114. + __ andl(rax, (1 << ConstantPoolCacheEntry::is_old_method_shift));
  115. + __ jcc(Assembler::zero, notOld);
  116. +
  117. + // Need a null check here!
  118. + __ null_check(recv);
  119. +
  120. + // Call out to VM to do look up based on correct vTable version (has to iterate back over the class history of the receiver class)
  121. + // DCEVM: TODO: Check if we can improve performance by inlining.
  122. + // DCEVM: TODO: Check if this additional branch affects normal execution time.
  123. + __ call_VM(method, CAST_FROM_FN_PTR(address, InterpreterRuntime::find_correct_method), recv, index);
  124. +
  125. + // profile this call
  126. + __ profile_final_call(rax);
  127. + __ jump_from_interpreted(method, rdx);
  128. +
  129. + __ bind(notOld);
  130. +
  131. // get receiver klass
  132. __ null_check(recv, oopDesc::klass_offset_in_bytes());
  133. __ load_klass(rax, recv);
  134. @@ -3093,6 +3143,31 @@ void TemplateTable::invokeinterface(int byte_no) {
  135. invokevirtual_helper(rbx, rcx, rdx);
  136. __ bind(notMethod);
  137. + // DCEVM: Check if we are calling an old method (and have to go slow path)
  138. + //__ movl(rax, rdx);
  139. + Label notOld;
  140. + __ andl(rdx, (1 << ConstantPoolCacheEntry::is_old_method_shift));
  141. + __ jcc(Assembler::zero, notOld);
  142. +
  143. + // Get receiver klass into rdx - also a null check
  144. + __ movptr(rdx, Address(rcx, oopDesc::klass_offset_in_bytes()));
  145. + __ verify_oop(rdx);
  146. +
  147. + // Call out to VM to do look up based on correct vTable version (has to iterate back over the class history of the receiver class)
  148. + // DCEVM: TODO: Check if we can improve performance by inlining.
  149. + // DCEVM: TODO: Check if this additional branch affects normal execution time.
  150. + // DCEVM: TODO: Check the exact semantic (with respect to destoying registers) of call_VM
  151. + __ call_VM(rbx, CAST_FROM_FN_PTR(address, InterpreterRuntime::find_correct_interface_method), rcx, rax, rbx);
  152. +
  153. + // DCEVM: TODO: Check if resolved method could be null.
  154. +
  155. + // profile this call
  156. + __ profile_virtual_call(rdx, rsi, rdi);
  157. +
  158. + __ jump_from_interpreted(rbx, rdx);
  159. +
  160. + __ bind(notOld);
  161. +
  162. // Get receiver klass into rdx - also a null check
  163. __ restore_locals(); // restore rdi
  164. __ null_check(rcx, oopDesc::klass_offset_in_bytes());
  165. diff --git a/src/cpu/x86/vm/templateTable_x86_64.cpp b/src/cpu/x86/vm/templateTable_x86_64.cpp
  166. index 932ee97..67bb710 100644
  167. --- a/src/cpu/x86/vm/templateTable_x86_64.cpp
  168. +++ b/src/cpu/x86/vm/templateTable_x86_64.cpp
  169. @@ -2151,6 +2151,22 @@ void TemplateTable::resolve_cache_and_index(int byte_no,
  170. // resolve first time through
  171. address entry;
  172. switch (bytecode()) {
  173. + case Bytecodes::_fast_agetfield : // fall through
  174. + case Bytecodes::_fast_bgetfield : // fall through
  175. + case Bytecodes::_fast_cgetfield : // fall through
  176. + case Bytecodes::_fast_dgetfield : // fall through
  177. + case Bytecodes::_fast_fgetfield : // fall through
  178. + case Bytecodes::_fast_igetfield : // fall through
  179. + case Bytecodes::_fast_lgetfield : // fall through
  180. + case Bytecodes::_fast_sgetfield : // fall through
  181. + case Bytecodes::_fast_aputfield : // fall through
  182. + case Bytecodes::_fast_bputfield : // fall through
  183. + case Bytecodes::_fast_cputfield : // fall through
  184. + case Bytecodes::_fast_dputfield : // fall through
  185. + case Bytecodes::_fast_fputfield : // fall through
  186. + case Bytecodes::_fast_iputfield : // fall through
  187. + case Bytecodes::_fast_lputfield : // fall through
  188. + case Bytecodes::_fast_sputfield : // fall through
  189. case Bytecodes::_getstatic:
  190. case Bytecodes::_putstatic:
  191. case Bytecodes::_getfield:
  192. @@ -2267,7 +2283,7 @@ void TemplateTable::load_invoke_cp_cache_entry(int byte_no,
  193. // The registers cache and index expected to be set before call.
  194. // Correct values of the cache and index registers are preserved.
  195. void TemplateTable::jvmti_post_field_access(Register cache, Register index,
  196. - bool is_static, bool has_tos) {
  197. + int byte_no, bool is_static, bool has_tos) {
  198. // do the JVMTI work here to avoid disturbing the register state below
  199. // We use c_rarg registers here because we want to use the register used in
  200. // the call to the VM
  201. @@ -2298,7 +2314,11 @@ void TemplateTable::jvmti_post_field_access(Register cache, Register index,
  202. __ call_VM(noreg, CAST_FROM_FN_PTR(address,
  203. InterpreterRuntime::post_field_access),
  204. c_rarg1, c_rarg2, c_rarg3);
  205. - __ get_cache_and_index_at_bcp(cache, index, 1);
  206. +
  207. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  208. + __ restore_bcp();
  209. + resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  210. +
  211. __ bind(L1);
  212. }
  213. }
  214. @@ -2320,7 +2340,7 @@ void TemplateTable::getfield_or_static(int byte_no, bool is_static) {
  215. const Register bc = c_rarg3; // uses same reg as obj, so don't mix them
  216. resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  217. - jvmti_post_field_access(cache, index, is_static, false);
  218. + jvmti_post_field_access(cache, index, byte_no, is_static, false);
  219. load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  220. if (!is_static) {
  221. @@ -2455,7 +2475,7 @@ void TemplateTable::getstatic(int byte_no) {
  222. // The registers cache and index expected to be set before call.
  223. // The function may destroy various registers, just not the cache and index registers.
  224. -void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is_static) {
  225. +void TemplateTable::jvmti_post_field_mod(Register cache, Register index, int byte_no, bool is_static) {
  226. transition(vtos, vtos);
  227. ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();
  228. @@ -2507,7 +2527,11 @@ void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is
  229. CAST_FROM_FN_PTR(address,
  230. InterpreterRuntime::post_field_modification),
  231. c_rarg1, c_rarg2, c_rarg3);
  232. - __ get_cache_and_index_at_bcp(cache, index, 1);
  233. +
  234. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  235. + __ restore_bcp();
  236. + resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  237. +
  238. __ bind(L1);
  239. }
  240. }
  241. @@ -2523,7 +2547,7 @@ void TemplateTable::putfield_or_static(int byte_no, bool is_static) {
  242. const Register bc = c_rarg3;
  243. resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  244. - jvmti_post_field_mod(cache, index, is_static);
  245. + jvmti_post_field_mod(cache, index, byte_no, is_static);
  246. load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  247. // [jk] not needed currently
  248. @@ -2837,6 +2861,11 @@ void TemplateTable::fast_accessfield(TosState state) {
  249. InterpreterRuntime::post_field_access),
  250. c_rarg1, c_rarg2);
  251. __ pop_ptr(rax); // restore object pointer
  252. +
  253. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  254. + __ restore_bcp();
  255. + resolve_cache_and_index(1, noreg, rax, rcx, sizeof(u2));
  256. +
  257. __ bind(L1);
  258. }
  259. @@ -3073,6 +3102,26 @@ void TemplateTable::invokevirtual_helper(Register index,
  260. __ bind(notFinal);
  261. + // DCEVM: Check if we are calling an old method (and have to go slow path)
  262. + Label notOld;
  263. + __ movl(rax, flags);
  264. + __ andl(rax, (1 << ConstantPoolCacheEntry::is_old_method_shift));
  265. + __ jcc(Assembler::zero, notOld);
  266. +
  267. + // Need a null check here!
  268. + __ null_check(recv);
  269. +
  270. + // Call out to VM to do look up based on correct vTable version (has to iterate back over the class history of the receiver class)
  271. + // DCEVM: TODO: Check if we can improve performance by inlining.
  272. + // DCEVM: TODO: Check if this additional branch affects normal execution time.
  273. + __ call_VM(method, CAST_FROM_FN_PTR(address, InterpreterRuntime::find_correct_method), recv, index);
  274. +
  275. + // profile this call
  276. + __ profile_final_call(rax);
  277. + __ jump_from_interpreted(method, rdx);
  278. +
  279. + __ bind(notOld);
  280. +
  281. // get receiver klass
  282. __ null_check(recv, oopDesc::klass_offset_in_bytes());
  283. __ load_klass(rax, recv);
  284. @@ -3156,6 +3205,35 @@ void TemplateTable::invokeinterface(int byte_no) {
  285. invokevirtual_helper(rbx, rcx, rdx);
  286. __ bind(notMethod);
  287. + // DCEVM: Check if we are calling an old method (and have to go slow path)
  288. + Label notOld;
  289. + __ andl(rdx, (1 << ConstantPoolCacheEntry::is_old_method_shift));
  290. + __ jcc(Assembler::zero, notOld);
  291. +
  292. + // Call out to VM to do look up based on correct vTable version (has to iterate back over the class history of the receiver class)
  293. + // DCEVM: TODO: Check if we can improve performance by inlining.
  294. + // DCEVM: TODO: Check if this additional branch affects normal execution time.
  295. + // DCEVM: TODO: Check the exact semantic (with respect to destoying registers) of call_VM
  296. + // DCEVM: FIXME: What exactly should we store here?
  297. + __ push(rcx); // destroyed by Linux arguments passing conventions
  298. + __ movptr(r14, rcx);
  299. + __ call_VM(rbx, CAST_FROM_FN_PTR(address, InterpreterRuntime::find_correct_interface_method), r14, rax, rbx);
  300. + __ pop(rcx);
  301. +
  302. + // Get receiver klass into rdx - also a null check
  303. + __ restore_locals(); // restore r14
  304. + __ load_klass(rdx, rcx);
  305. + __ verify_oop(rdx);
  306. +
  307. + // DCEVM: TODO: Check if resolved method could be null.
  308. +
  309. + // profile this call
  310. + __ profile_virtual_call(rdx, r13, r14);
  311. +
  312. + __ jump_from_interpreted(rbx, rdx);
  313. +
  314. + __ bind(notOld);
  315. +
  316. // Get receiver klass into rdx - also a null check
  317. __ restore_locals(); // restore r14
  318. __ null_check(rcx, oopDesc::klass_offset_in_bytes());
  319. diff --git a/src/share/vm/c1/c1_Compilation.hpp b/src/share/vm/c1/c1_Compilation.hpp
  320. index 9a8ca61..196ab25 100644
  321. --- a/src/share/vm/c1/c1_Compilation.hpp
  322. +++ b/src/share/vm/c1/c1_Compilation.hpp
  323. @@ -242,8 +242,8 @@ class Compilation: public StackObj {
  324. #define BAILOUT(msg) { bailout(msg); return; }
  325. #define BAILOUT_(msg, res) { bailout(msg); return res; }
  326. -#define CHECK_BAILOUT() { if (bailed_out()) return; }
  327. -#define CHECK_BAILOUT_(res) { if (bailed_out()) return res; }
  328. +#define CHECK_BAILOUT() { if (((CompilerThread *)Thread::current())->should_bailout()) bailout("Aborted externally"); if (bailed_out()) return; }
  329. +#define CHECK_BAILOUT_(res) { if (((CompilerThread *)Thread::current())->should_bailout()) bailout("Aborted externally"); if (bailed_out()) return res; }
  330. class InstructionMark: public StackObj {
  331. diff --git a/src/share/vm/ci/ciEnv.cpp b/src/share/vm/ci/ciEnv.cpp
  332. index e20db5d..57f37db 100644
  333. --- a/src/share/vm/ci/ciEnv.cpp
  334. +++ b/src/share/vm/ci/ciEnv.cpp
  335. @@ -1172,3 +1172,11 @@ void ciEnv::record_out_of_memory_failure() {
  336. // If memory is low, we stop compiling methods.
  337. record_method_not_compilable("out of memory");
  338. }
  339. +
  340. +// DCEVM: Called after class redefinition to clean up possibly invalidated state.
  341. +void ciEnv::cleanup_after_redefinition() {
  342. +
  343. + if (_factory != NULL) {
  344. + _factory->cleanup_after_redefinition();
  345. + }
  346. +}
  347. diff --git a/src/share/vm/ci/ciEnv.hpp b/src/share/vm/ci/ciEnv.hpp
  348. index 103e532..abe2e37 100644
  349. --- a/src/share/vm/ci/ciEnv.hpp
  350. +++ b/src/share/vm/ci/ciEnv.hpp
  351. @@ -417,6 +417,8 @@ public:
  352. void record_failure(const char* reason);
  353. void record_method_not_compilable(const char* reason, bool all_tiers = true);
  354. void record_out_of_memory_failure();
  355. +
  356. + void cleanup_after_redefinition();
  357. };
  358. #endif // SHARE_VM_CI_CIENV_HPP
  359. diff --git a/src/share/vm/ci/ciObjectFactory.cpp b/src/share/vm/ci/ciObjectFactory.cpp
  360. index e0ab96b..36efef4 100644
  361. --- a/src/share/vm/ci/ciObjectFactory.cpp
  362. +++ b/src/share/vm/ci/ciObjectFactory.cpp
  363. @@ -296,6 +296,11 @@ ciObject* ciObjectFactory::get(oop key) {
  364. // into the table. We need to recompute our index.
  365. index = find(keyHandle(), _ci_objects);
  366. }
  367. +
  368. + if (is_found_at(index, keyHandle(), _ci_objects)) {
  369. + // DCEVM: Check if this is an error? Can occur when redefining classes.
  370. + return _ci_objects->at(index);
  371. + }
  372. assert(!is_found_at(index, keyHandle(), _ci_objects), "no double insert");
  373. insert(index, new_object, _ci_objects);
  374. return new_object;
  375. @@ -764,3 +769,50 @@ void ciObjectFactory::print() {
  376. _unloaded_instances->length(),
  377. _unloaded_klasses->length());
  378. }
  379. +
  380. +// DCEVM: Resoring the ciObject arrays after class redefinition
  381. +void ciObjectFactory::sort_ci_objects(GrowableArray<ciObject*>* objects) {
  382. +
  383. + // Resort the _ci_objects array. The order of two class pointers can be changed during class redefinition.
  384. + oop last = NULL;
  385. + for (int j = 0; j< objects->length(); j++) {
  386. + oop o = objects->at(j)->get_oop();
  387. + if (last >= o) {
  388. + int cur_last_index = j - 1;
  389. + oop cur_last = last;
  390. + while (cur_last >= o) {
  391. +
  392. + // Swap the two objects to guarantee ordering
  393. + ciObject *tmp = objects->at(cur_last_index);
  394. + objects->at_put(cur_last_index, objects->at(cur_last_index + 1));
  395. + objects->at_put(cur_last_index + 1, tmp);
  396. +
  397. + // Decrement index to move one step to the left
  398. + cur_last_index--;
  399. + if (cur_last_index < 0) {
  400. + break;
  401. + }
  402. + cur_last = objects->at(cur_last_index)->get_oop();
  403. + }
  404. + } else {
  405. + assert(last < o, "out of order");
  406. + last = o;
  407. + }
  408. + }
  409. +
  410. +#ifdef ASSERT
  411. + if (CIObjectFactoryVerify) {
  412. + oop last = NULL;
  413. + for (int j = 0; j< objects->length(); j++) {
  414. + oop o = objects->at(j)->get_oop();
  415. + assert(last < o, "out of order");
  416. + last = o;
  417. + }
  418. + }
  419. +#endif // ASSERT
  420. +}
  421. +
  422. +// DCEVM: Called after class redefinition to clean up possibly invalidated state.
  423. +void ciObjectFactory::cleanup_after_redefinition() {
  424. + sort_ci_objects(_ci_objects);
  425. +}
  426. diff --git a/src/share/vm/ci/ciObjectFactory.hpp b/src/share/vm/ci/ciObjectFactory.hpp
  427. index 26cc2c3..855a4ac 100644
  428. --- a/src/share/vm/ci/ciObjectFactory.hpp
  429. +++ b/src/share/vm/ci/ciObjectFactory.hpp
  430. @@ -38,6 +38,7 @@
  431. class ciObjectFactory : public ResourceObj {
  432. friend class VMStructs;
  433. friend class ciEnv;
  434. + friend class CompileBroker;
  435. private:
  436. static volatile bool _initialized;
  437. @@ -137,6 +138,11 @@ public:
  438. void print_contents();
  439. void print();
  440. +
  441. +private:
  442. +
  443. + static void sort_ci_objects(GrowableArray<ciObject*>* objects);
  444. + void cleanup_after_redefinition();
  445. };
  446. #endif // SHARE_VM_CI_CIOBJECTFACTORY_HPP
  447. diff --git a/src/share/vm/classfile/classFileParser.cpp b/src/share/vm/classfile/classFileParser.cpp
  448. index 8c5e970..fc624bf 100644
  449. --- a/src/share/vm/classfile/classFileParser.cpp
  450. +++ b/src/share/vm/classfile/classFileParser.cpp
  451. @@ -795,6 +795,7 @@ objArrayHandle ClassFileParser::parse_interfaces(constantPoolHandle cp,
  452. Handle class_loader,
  453. Handle protection_domain,
  454. Symbol* class_name,
  455. + KlassHandle old_klass,
  456. TRAPS) {
  457. ClassFileStream* cfs = stream();
  458. assert(length > 0, "only called for length>0");
  459. @@ -813,6 +814,9 @@ objArrayHandle ClassFileParser::parse_interfaces(constantPoolHandle cp,
  460. interface_index, CHECK_(nullHandle));
  461. if (cp->tag_at(interface_index).is_klass()) {
  462. interf = KlassHandle(THREAD, cp->resolved_klass_at(interface_index));
  463. + if (!old_klass.is_null() && !interf->is_newest_version()) {
  464. + interf = KlassHandle(THREAD, interf->newest_version());
  465. + }
  466. } else {
  467. Symbol* unresolved_klass = cp->klass_name_at(interface_index);
  468. @@ -825,6 +829,9 @@ objArrayHandle ClassFileParser::parse_interfaces(constantPoolHandle cp,
  469. klassOop k = SystemDictionary::resolve_super_or_fail(class_name,
  470. unresolved_klass, class_loader, protection_domain,
  471. false, CHECK_(nullHandle));
  472. + if (!old_klass.is_null()) {
  473. + k = k->klass_part()->newest_version();
  474. + }
  475. interf = KlassHandle(THREAD, k);
  476. }
  477. @@ -1923,6 +1930,8 @@ methodHandle ClassFileParser::parse_method(Handle class_loader, constantPoolHand
  478. int runtime_invisible_parameter_annotations_length = 0;
  479. u1* annotation_default = NULL;
  480. int annotation_default_length = 0;
  481. + u2 code_section_table_length;
  482. + typeArrayHandle code_section_table;
  483. // Parse code and exceptions attribute
  484. u2 method_attributes_count = cfs->get_u2_fast();
  485. @@ -2092,6 +2101,24 @@ methodHandle ClassFileParser::parse_method(Handle class_loader, constantPoolHand
  486. parse_stackmap_table(code_attribute_length, CHECK_(nullHandle));
  487. stackmap_data = typeArrayHandle(THREAD, sm);
  488. parsed_stackmap_attribute = true;
  489. + } else if (UseMethodForwardPoints && cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_code_sections()) {
  490. + int length = code_attribute_length;
  491. + int value_count = length / sizeof(u2);
  492. + int line_count = length / 3;
  493. + if (TraceRedefineClasses >= 3) {
  494. + tty->print_cr("Found code section attribute when loading class with %d entries", value_count, line_count);
  495. + }
  496. + code_section_table_length = value_count;
  497. + code_section_table = oopFactory::new_permanent_shortArray(value_count, CHECK_NULL);
  498. + code_section_table->set_length(value_count);
  499. +
  500. + for (int i = 0; i < value_count; ++i) {
  501. + u2 value = cfs->get_u2(CHECK_(nullHandle));
  502. + code_section_table->short_at_put(i, value);
  503. + if (TraceRedefineClasses >= 4) {
  504. + tty->print_cr("Code section table at %d: %d", i, value);
  505. + }
  506. + }
  507. } else {
  508. // Skip unknown attributes
  509. cfs->skip_u1(code_attribute_length, CHECK_(nullHandle));
  510. @@ -2216,6 +2243,18 @@ methodHandle ClassFileParser::parse_method(Handle class_loader, constantPoolHand
  511. }
  512. #endif
  513. + // DCEVM: TODO: Get a different solution for the problem of method forward
  514. + // points and variable sized interpreter frames.
  515. + if (UseMethodForwardPoints) {
  516. + if (max_stack > MethodForwardPointsMaxStack) {
  517. + fatal(err_msg("Method has too large stack (%d), increase the value of MethodForwardPointsMaxStack (%d)", max_stack, MethodForwardPointsMaxStack));
  518. + }
  519. + if (max_locals > MethodForwardPointsMaxLocals) {
  520. + fatal(err_msg("Method has too many locals (%d), increase the value of MethodForwardPointsMaxLocals (%d)", max_stack, MethodForwardPointsMaxStack));
  521. + }
  522. + max_stack = MethodForwardPointsMaxStack;
  523. + max_locals = MethodForwardPointsMaxLocals;
  524. + }
  525. // Fill in code attribute information
  526. m->set_max_stack(max_stack);
  527. m->set_max_locals(max_locals);
  528. @@ -2229,6 +2268,8 @@ methodHandle ClassFileParser::parse_method(Handle class_loader, constantPoolHand
  529. */
  530. m->constMethod()->set_stackmap_data(stackmap_data());
  531. + m->constMethod()->set_code_section_table(code_section_table());
  532. +
  533. // Copy byte codes
  534. m->set_code(code_start);
  535. @@ -2825,6 +2866,15 @@ void ClassFileParser::parse_classfile_attributes(Handle class_loader,
  536. "Invalid Deprecated classfile attribute length %u in class file %s",
  537. attribute_length, CHECK);
  538. }
  539. + } else if (tag == vmSymbols::tag_field_redefinition_policy()) {
  540. + // DCEVM: Check for deleted field attribute
  541. + _field_redefinition_policy = cfs->get_u1_fast();
  542. + } else if (tag == vmSymbols::tag_static_field_redefinition_policy()) {
  543. + // DCEVM: Check for deleted static field attribute
  544. + _static_field_redefinition_policy = cfs->get_u1_fast();
  545. + } else if (tag == vmSymbols::tag_method_redefinition_policy()) {
  546. + // DCEVM: Check for deleted method attribute
  547. + _method_redefinition_policy = cfs->get_u1_fast();
  548. } else if (_major_version >= JAVA_1_5_VERSION) {
  549. if (tag == vmSymbols::tag_signature()) {
  550. if (attribute_length != 2) {
  551. @@ -2929,6 +2979,17 @@ void ClassFileParser::apply_parsed_class_attributes(instanceKlassHandle k) {
  552. }
  553. k->set_inner_classes(_inner_classes());
  554. k->set_class_annotations(_annotations());
  555. +
  556. +
  557. + if (_field_redefinition_policy != 0xff) {
  558. + k->set_field_redefinition_policy(_field_redefinition_policy);
  559. + }
  560. + if (_static_field_redefinition_policy != 0xff) {
  561. + k->set_static_field_redefinition_policy(_static_field_redefinition_policy);
  562. + }
  563. + if (_method_redefinition_policy != 0xff) {
  564. + k->set_method_redefinition_policy(_method_redefinition_policy);
  565. + }
  566. }
  567. typeArrayHandle ClassFileParser::assemble_annotations(u1* runtime_visible_annotations,
  568. @@ -2952,9 +3013,126 @@ typeArrayHandle ClassFileParser::assemble_annotations(u1* runtime_visible_annota
  569. }
  570. +// DCEVM: Finds the super symbols by reading the bytes of the class and returns
  571. +// them in a growable array.
  572. +void ClassFileParser::findSuperSymbols(Symbol* name,
  573. + Handle class_loader,
  574. + Handle protection_domain,
  575. + KlassHandle old_klass,
  576. + GrowableArray<Symbol*> &handles,
  577. + TRAPS) {
  578. +
  579. + _cp_patches = NULL;
  580. + // So that JVMTI can cache class file in the state before retransformable agents
  581. + // have modified it
  582. + unsigned char *cached_class_file_bytes = NULL;
  583. +
  584. + ClassFileStream* cfs = stream();
  585. +
  586. + _has_finalizer = _has_empty_finalizer = _has_vanilla_constructor = false;
  587. +
  588. + instanceKlassHandle nullHandle;
  589. +
  590. + // Save the class file name for easier error message printing.
  591. + _class_name = name != NULL ? name : vmSymbols::unknown_class_name();
  592. +
  593. + cfs->guarantee_more(8, CHECK); // magic, major, minor
  594. + // Magic value
  595. + u4 magic = cfs->get_u4_fast();
  596. + if (magic != JAVA_CLASSFILE_MAGIC) {
  597. + // Invalid class file!
  598. + return;
  599. + }
  600. +
  601. + // Version numbers
  602. + u2 minor_version = cfs->get_u2_fast();
  603. + u2 major_version = cfs->get_u2_fast();
  604. +
  605. + // Check version numbers - we check this even with verifier off
  606. + if (!is_supported_version(major_version, minor_version)) {
  607. +
  608. + // Unsupported version!
  609. + return;
  610. + }
  611. +
  612. + _major_version = major_version;
  613. + _minor_version = minor_version;
  614. +
  615. +
  616. + // Check if verification needs to be relaxed for this class file
  617. + // Do not restrict it to jdk1.0 or jdk1.1 to maintain backward compatibility (4982376)
  618. + _relax_verify = Verifier::relax_verify_for(class_loader());
  619. + _need_verify = false;
  620. +
  621. + // Constant pool
  622. + constantPoolHandle cp = parse_constant_pool(class_loader(), CHECK);
  623. + int cp_size = cp->length();
  624. +
  625. + cfs->guarantee_more(8, CHECK); // flags, this_class, super_class, infs_len
  626. +
  627. + // Access flags
  628. + AccessFlags access_flags;
  629. + jint flags = cfs->get_u2_fast() & JVM_RECOGNIZED_CLASS_MODIFIERS;
  630. +
  631. + if ((flags & JVM_ACC_INTERFACE) && _major_version < JAVA_6_VERSION) {
  632. + // Set abstract bit for old class files for backward compatibility
  633. + flags |= JVM_ACC_ABSTRACT;
  634. + }
  635. + access_flags.set_flags(flags);
  636. +
  637. + // This class and superclass
  638. + instanceKlassHandle super_klass;
  639. + u2 this_class_index = cfs->get_u2_fast();
  640. + check_property(
  641. + valid_cp_range(this_class_index, cp_size) &&
  642. + cp->tag_at(this_class_index).is_unresolved_klass(),
  643. + "Invalid this class index %u in constant pool in class file %s",
  644. + this_class_index, CHECK);
  645. +
  646. + Symbol* class_name = cp->unresolved_klass_at(this_class_index);
  647. + assert(class_name != NULL, "class_name can't be null");
  648. +
  649. + // Update _class_name which could be null previously to be class_name
  650. + _class_name = class_name;
  651. +
  652. + // DCEVM: DO NOT release all handles when parsing is done
  653. + {// HandleMark hm(THREAD);
  654. +
  655. + // Checks if name in class file matches requested name
  656. + if (name != NULL && class_name != name) {
  657. + return;
  658. + }
  659. +
  660. + u2 super_class_index = cfs->get_u2_fast();
  661. +
  662. + if (super_class_index != 0) {
  663. + Symbol* super_class = cp->klass_name_at(super_class_index);
  664. + handles.append(super_class);
  665. + } else {
  666. + // DCEVM: This redefinition must be for the Object class.
  667. + }
  668. +
  669. + // Interfaces
  670. + u2 itfs_len = cfs->get_u2_fast();
  671. + objArrayHandle local_interfaces;
  672. + if (itfs_len == 0) {
  673. + local_interfaces = objArrayHandle(THREAD, Universe::the_empty_system_obj_array());
  674. + } else {
  675. + local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, old_klass, CHECK);
  676. + }
  677. +
  678. + for (int i=0; i<local_interfaces->length(); i++) {
  679. + oop o = local_interfaces->obj_at(i);
  680. + Symbol* interface_handle = ((klassOop)o)->klass_part()->name();
  681. + handles.append(interface_handle);
  682. + }
  683. + }
  684. +}
  685. +
  686. instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  687. Handle class_loader,
  688. Handle protection_domain,
  689. + KlassHandle old_klass,
  690. KlassHandle host_klass,
  691. GrowableArray<Handle>* cp_patches,
  692. TempNewSymbol& parsed_name,
  693. @@ -3005,10 +3183,13 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  694. unsigned char* ptr = cfs->buffer();
  695. unsigned char* end_ptr = cfs->buffer() + cfs->length();
  696. + bool pretend_new_universe = Thread::current()->pretend_new_universe();
  697. + Thread::current()->set_pretend_new_universe(false);
  698. JvmtiExport::post_class_file_load_hook(name, class_loader, protection_domain,
  699. &ptr, &end_ptr,
  700. &cached_class_file_bytes,
  701. &cached_class_file_length);
  702. + Thread::current()->set_pretend_new_universe(pretend_new_universe);
  703. if (ptr != cfs->buffer()) {
  704. // JVMTI agent has modified class file data.
  705. @@ -3164,7 +3345,11 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  706. // However, make sure it is not an array type.
  707. bool is_array = false;
  708. if (cp->tag_at(super_class_index).is_klass()) {
  709. - super_klass = instanceKlassHandle(THREAD, cp->resolved_klass_at(super_class_index));
  710. + klassOop resolved_klass = cp->resolved_klass_at(super_class_index);
  711. + if (!old_klass.is_null()) {
  712. + resolved_klass = resolved_klass->klass_part()->newest_version();
  713. + }
  714. + super_klass = instanceKlassHandle(THREAD, resolved_klass);
  715. if (_need_verify)
  716. is_array = super_klass->oop_is_array();
  717. } else if (_need_verify) {
  718. @@ -3182,7 +3367,7 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  719. if (itfs_len == 0) {
  720. local_interfaces = objArrayHandle(THREAD, Universe::the_empty_system_obj_array());
  721. } else {
  722. - local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, CHECK_(nullHandle));
  723. + local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, old_klass, CHECK_(nullHandle));
  724. }
  725. u2 java_fields_count = 0;
  726. @@ -3237,7 +3422,9 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  727. protection_domain,
  728. true,
  729. CHECK_(nullHandle));
  730. -
  731. + if (!old_klass.is_null()) {
  732. + k = k->klass_part()->newest_version();
  733. + }
  734. KlassHandle kh (THREAD, k);
  735. super_klass = instanceKlassHandle(THREAD, kh());
  736. }
  737. @@ -3626,6 +3813,19 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  738. rt = REF_NONE;
  739. } else {
  740. rt = super_klass->reference_type();
  741. +
  742. + // DCEVM: With class redefinition, it can also happen that special classes are loaded.
  743. + if (name == vmSymbols::java_lang_ref_Reference()) {
  744. + rt = REF_OTHER;
  745. + } else if (name == vmSymbols::java_lang_ref_SoftReference()) {
  746. + rt = REF_SOFT;
  747. + } else if (name == vmSymbols::java_lang_ref_WeakReference()) {
  748. + rt = REF_WEAK;
  749. + } else if (name == vmSymbols::java_lang_ref_FinalReference()) {
  750. + rt = REF_FINAL;
  751. + } else if (name == vmSymbols::java_lang_ref_PhantomReference()) {
  752. + rt = REF_PHANTOM;
  753. + }
  754. }
  755. // We can now create the basic klassOop for this klass
  756. @@ -3726,7 +3926,7 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  757. fill_oop_maps(this_klass, nonstatic_oop_map_count, nonstatic_oop_offsets, nonstatic_oop_counts);
  758. // Fill in has_finalizer, has_vanilla_constructor, and layout_helper
  759. - set_precomputed_flags(this_klass);
  760. + set_precomputed_flags(this_klass, old_klass);
  761. // reinitialize modifiers, using the InnerClasses attribute
  762. int computed_modifiers = this_klass->compute_modifier_flags(CHECK_(nullHandle));
  763. @@ -3749,6 +3949,10 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  764. // Allocate mirror and initialize static fields
  765. java_lang_Class::create_mirror(this_klass, CHECK_(nullHandle));
  766. + if (rt == REF_OTHER) {
  767. + instanceRefKlass::update_nonstatic_oop_maps(ik);
  768. + }
  769. +
  770. ClassLoadingService::notify_class_loaded(instanceKlass::cast(this_klass()),
  771. false /* not shared class */);
  772. @@ -3891,7 +4095,7 @@ void ClassFileParser::fill_oop_maps(instanceKlassHandle k,
  773. }
  774. -void ClassFileParser::set_precomputed_flags(instanceKlassHandle k) {
  775. +void ClassFileParser::set_precomputed_flags(instanceKlassHandle k, KlassHandle old_klass) {
  776. klassOop super = k->super();
  777. // Check if this klass has an empty finalize method (i.e. one with return bytecode only),
  778. @@ -3899,7 +4103,9 @@ void ClassFileParser::set_precomputed_flags(instanceKlassHandle k) {
  779. if (!_has_empty_finalizer) {
  780. if (_has_finalizer ||
  781. (super != NULL && super->klass_part()->has_finalizer())) {
  782. - k->set_has_finalizer();
  783. + if (old_klass.is_null() || old_klass->has_finalizer()) {
  784. + k->set_has_finalizer();
  785. + }
  786. }
  787. }
  788. @@ -3915,7 +4121,7 @@ void ClassFileParser::set_precomputed_flags(instanceKlassHandle k) {
  789. // Check if this klass supports the java.lang.Cloneable interface
  790. if (SystemDictionary::Cloneable_klass_loaded()) {
  791. - if (k->is_subtype_of(SystemDictionary::Cloneable_klass())) {
  792. + if (k->is_subtype_of(SystemDictionary::Cloneable_klass()) || k->is_subtype_of(SystemDictionary::Cloneable_klass()->klass_part()->newest_version())) {
  793. k->set_is_cloneable();
  794. }
  795. }
  796. diff --git a/src/share/vm/classfile/classFileParser.hpp b/src/share/vm/classfile/classFileParser.hpp
  797. index a95a784..ac217fc 100644
  798. --- a/src/share/vm/classfile/classFileParser.hpp
  799. +++ b/src/share/vm/classfile/classFileParser.hpp
  800. @@ -64,6 +64,9 @@ class ClassFileParser VALUE_OBJ_CLASS_SPEC {
  801. int _sde_length;
  802. typeArrayHandle _inner_classes;
  803. typeArrayHandle _annotations;
  804. + u1 _field_redefinition_policy;
  805. + u1 _static_field_redefinition_policy;
  806. + u1 _method_redefinition_policy;
  807. void set_class_synthetic_flag(bool x) { _synthetic_flag = x; }
  808. void set_class_sourcefile(Symbol* x) { _sourcefile = x; }
  809. @@ -151,6 +154,7 @@ class ClassFileParser VALUE_OBJ_CLASS_SPEC {
  810. Handle class_loader,
  811. Handle protection_domain,
  812. Symbol* class_name,
  813. + KlassHandle old_klass,
  814. TRAPS);
  815. // Field parsing
  816. @@ -239,7 +243,7 @@ class ClassFileParser VALUE_OBJ_CLASS_SPEC {
  817. unsigned int nonstatic_oop_map_count,
  818. int* nonstatic_oop_offsets,
  819. unsigned int* nonstatic_oop_counts);
  820. - void set_precomputed_flags(instanceKlassHandle k);
  821. + void set_precomputed_flags(instanceKlassHandle k, KlassHandle old_klass);
  822. objArrayHandle compute_transitive_interfaces(instanceKlassHandle super,
  823. objArrayHandle local_ifs, TRAPS);
  824. @@ -345,7 +349,12 @@ class ClassFileParser VALUE_OBJ_CLASS_SPEC {
  825. public:
  826. // Constructor
  827. - ClassFileParser(ClassFileStream* st) { set_stream(st); }
  828. + ClassFileParser(ClassFileStream* st) {
  829. + set_stream(st);
  830. + _field_redefinition_policy = 0xff;
  831. + _static_field_redefinition_policy = 0xff;
  832. + _method_redefinition_policy = 0xff;
  833. + }
  834. // Parse .class file and return new klassOop. The klassOop is not hooked up
  835. // to the system dictionary or any other structures, so a .class file can
  836. @@ -357,21 +366,33 @@ class ClassFileParser VALUE_OBJ_CLASS_SPEC {
  837. instanceKlassHandle parseClassFile(Symbol* name,
  838. Handle class_loader,
  839. Handle protection_domain,
  840. + KlassHandle old_klass,
  841. TempNewSymbol& parsed_name,
  842. bool verify,
  843. TRAPS) {
  844. KlassHandle no_host_klass;
  845. - return parseClassFile(name, class_loader, protection_domain, no_host_klass, NULL, parsed_name, verify, THREAD);
  846. + return parseClassFile(name, class_loader, protection_domain, old_klass, no_host_klass, NULL, parsed_name, verify, THREAD);
  847. }
  848. instanceKlassHandle parseClassFile(Symbol* name,
  849. Handle class_loader,
  850. Handle protection_domain,
  851. + KlassHandle old_klass,
  852. KlassHandle host_klass,
  853. GrowableArray<Handle>* cp_patches,
  854. TempNewSymbol& parsed_name,
  855. bool verify,
  856. TRAPS);
  857. + static void initialize_static_field(fieldDescriptor* fd, TRAPS);
  858. +
  859. + // DCEVM: Creates symbol handles for the super class and the interfaces
  860. + void findSuperSymbols(Symbol* name,
  861. + Handle class_loader,
  862. + Handle protection_domain,
  863. + KlassHandle old_klass,
  864. + GrowableArray<Symbol*> &handles,
  865. + TRAPS);
  866. +
  867. // Verifier checks
  868. static void check_super_class_access(instanceKlassHandle this_klass, TRAPS);
  869. static void check_super_interface_access(instanceKlassHandle this_klass, TRAPS);
  870. diff --git a/src/share/vm/classfile/classLoader.cpp b/src/share/vm/classfile/classLoader.cpp
  871. index a2e61a4..450e19f 100644
  872. --- a/src/share/vm/classfile/classLoader.cpp
  873. +++ b/src/share/vm/classfile/classLoader.cpp
  874. @@ -915,6 +915,7 @@ instanceKlassHandle ClassLoader::load_classfile(Symbol* h_name, TRAPS) {
  875. instanceKlassHandle result = parser.parseClassFile(h_name,
  876. class_loader,
  877. protection_domain,
  878. + KlassHandle(),
  879. parsed_name,
  880. false,
  881. CHECK_(h));
  882. diff --git a/src/share/vm/classfile/dictionary.cpp b/src/share/vm/classfile/dictionary.cpp
  883. index 78e76cc..ee21f3a 100644
  884. --- a/src/share/vm/classfile/dictionary.cpp
  885. +++ b/src/share/vm/classfile/dictionary.cpp
  886. @@ -326,6 +326,21 @@ void Dictionary::classes_do(void f(klassOop)) {
  887. }
  888. }
  889. +
  890. +// DCEVM: Just the classes from defining class loaders
  891. +void Dictionary::classes_do(ObjectClosure *closure) {
  892. + for (int index = 0; index < table_size(); index++) {
  893. + for (DictionaryEntry* probe = bucket(index);
  894. + probe != NULL;
  895. + probe = probe->next()) {
  896. + klassOop k = probe->klass();
  897. + if (probe->loader() == instanceKlass::cast(k)->class_loader()) {
  898. + closure->do_object(k);
  899. + }
  900. + }
  901. + }
  902. +}
  903. +
  904. // Added for initialize_itable_for_klass to handle exceptions
  905. // Just the classes from defining class loaders
  906. void Dictionary::classes_do(void f(klassOop, TRAPS), TRAPS) {
  907. @@ -433,6 +448,33 @@ void Dictionary::add_klass(Symbol* class_name, Handle class_loader,
  908. add_entry(index, entry);
  909. }
  910. +// DCEVM: Updates the klass entry to point to the new klassOop. Necessary only for class redefinition.
  911. +bool Dictionary::update_klass(int index, unsigned int hash, Symbol* name, Handle loader, KlassHandle k, KlassHandle old_class) {
  912. +
  913. + // There are several entries for the same class in the dictionary: One extra entry for each parent classloader of the classloader of the class.
  914. + bool found = false;
  915. + for (int index = 0; index < table_size(); index++) {
  916. + for (DictionaryEntry* entry = bucket(index); entry != NULL; entry = entry->next()) {
  917. + if (entry->klass() == old_class()) {
  918. + entry->set_literal(k());
  919. + found = true;
  920. + }
  921. + }
  922. + }
  923. +
  924. + return found;
  925. +}
  926. +
  927. +// DCEVM: Undo previous updates to the system dictionary
  928. +void Dictionary::rollback_redefinition() {
  929. + for (int index = 0; index < table_size(); index++) {
  930. + for (DictionaryEntry* entry = bucket(index); entry != NULL; entry = entry->next()) {
  931. + if (entry->klass()->klass_part()->is_redefining()) {
  932. + entry->set_literal(entry->klass()->klass_part()->old_version());
  933. + }
  934. + }
  935. + }
  936. +}
  937. // This routine does not lock the system dictionary.
  938. //
  939. @@ -459,12 +501,22 @@ DictionaryEntry* Dictionary::get_entry(int index, unsigned int hash,
  940. return NULL;
  941. }
  942. +// DCEVM: return old version if we are not in the new universe?
  943. +klassOop Dictionary::intercept_for_version(klassOop k) {
  944. + if (k == NULL) return k;
  945. +
  946. + if (k->klass_part()->is_redefining() && !Thread::current()->pretend_new_universe()) {
  947. + return k->klass_part()->old_version();
  948. + }
  949. +
  950. + return k;
  951. +}
  952. klassOop Dictionary::find(int index, unsigned int hash, Symbol* name,
  953. Handle loader, Handle protection_domain, TRAPS) {
  954. DictionaryEntry* entry = get_entry(index, hash, name, loader);
  955. if (entry != NULL && entry->is_valid_protection_domain(protection_domain)) {
  956. - return entry->klass();
  957. + return intercept_for_version(entry->klass());
  958. } else {
  959. return NULL;
  960. }
  961. @@ -477,7 +529,7 @@ klassOop Dictionary::find_class(int index, unsigned int hash,
  962. assert (index == index_for(name, loader), "incorrect index?");
  963. DictionaryEntry* entry = get_entry(index, hash, name, loader);
  964. - return (entry != NULL) ? entry->klass() : (klassOop)NULL;
  965. + return intercept_for_version((entry != NULL) ? entry->klass() : (klassOop)NULL);
  966. }
  967. @@ -489,7 +541,7 @@ klassOop Dictionary::find_shared_class(int index, unsigned int hash,
  968. assert (index == index_for(name, Handle()), "incorrect index?");
  969. DictionaryEntry* entry = get_entry(index, hash, name, Handle());
  970. - return (entry != NULL) ? entry->klass() : (klassOop)NULL;
  971. + return intercept_for_version((entry != NULL) ? entry->klass() : (klassOop)NULL);
  972. }
  973. diff --git a/src/share/vm/classfile/dictionary.hpp b/src/share/vm/classfile/dictionary.hpp
  974. index bd33760..186d0eb 100644
  975. --- a/src/share/vm/classfile/dictionary.hpp
  976. +++ b/src/share/vm/classfile/dictionary.hpp
  977. @@ -73,6 +73,10 @@ public:
  978. void add_klass(Symbol* class_name, Handle class_loader,KlassHandle obj);
  979. + bool update_klass(int index, unsigned int hash, Symbol* name, Handle loader, KlassHandle k, KlassHandle old_class);
  980. +
  981. + void rollback_redefinition();
  982. +
  983. klassOop find_class(int index, unsigned int hash,
  984. Symbol* name, Handle loader);
  985. @@ -89,6 +93,7 @@ public:
  986. void classes_do(void f(klassOop, TRAPS), TRAPS);
  987. void classes_do(void f(klassOop, oop));
  988. void classes_do(void f(klassOop, oop, TRAPS), TRAPS);
  989. + void classes_do(ObjectClosure *closure);
  990. void methods_do(void f(methodOop));
  991. @@ -105,6 +110,7 @@ public:
  992. bool do_unloading(BoolObjectClosure* is_alive);
  993. // Protection domains
  994. + static klassOop intercept_for_version(klassOop k);
  995. klassOop find(int index, unsigned int hash, Symbol* name,
  996. Handle loader, Handle protection_domain, TRAPS);
  997. bool is_valid_protection_domain(int index, unsigned int hash,
  998. diff --git a/src/share/vm/classfile/javaClasses.cpp b/src/share/vm/classfile/javaClasses.cpp
  999. index 7dd5f1b..9c7d8eb 100644
  1000. --- a/src/share/vm/classfile/javaClasses.cpp
  1001. +++ b/src/share/vm/classfile/javaClasses.cpp
  1002. @@ -1798,7 +1798,7 @@ Handle java_lang_reflect_Method::create(TRAPS) {
  1003. klassOop klass = SystemDictionary::reflect_Method_klass();
  1004. // This class is eagerly initialized during VM initialization, since we keep a refence
  1005. // to one of the methods
  1006. - assert(instanceKlass::cast(klass)->is_initialized(), "must be initialized");
  1007. + assert(instanceKlass::cast(klass)->is_initialized() || klass->klass_part()->old_version() != NULL, "must be initialized");
  1008. return instanceKlass::cast(klass)->allocate_instance_handle(CHECK_NH);
  1009. }
  1010. diff --git a/src/share/vm/classfile/javaClasses.hpp b/src/share/vm/classfile/javaClasses.hpp
  1011. index 36d1cec..a6de98e 100644
  1012. --- a/src/share/vm/classfile/javaClasses.hpp
  1013. +++ b/src/share/vm/classfile/javaClasses.hpp
  1014. @@ -213,7 +213,6 @@ class java_lang_String : AllStatic {
  1015. class java_lang_Class : AllStatic {
  1016. friend class VMStructs;
  1017. -
  1018. private:
  1019. // The fake offsets are added by the class loader when java.lang.Class is loaded
  1020. diff --git a/src/share/vm/classfile/loaderConstraints.cpp b/src/share/vm/classfile/loaderConstraints.cpp
  1021. index 8650cd9..965cce2 100644
  1022. --- a/src/share/vm/classfile/loaderConstraints.cpp
  1023. +++ b/src/share/vm/classfile/loaderConstraints.cpp
  1024. @@ -449,7 +449,7 @@ void LoaderConstraintTable::verify(Dictionary* dictionary,
  1025. if (k != NULL) {
  1026. // We found the class in the system dictionary, so we should
  1027. // make sure that the klassOop matches what we already have.
  1028. - guarantee(k == probe->klass(), "klass should be in dictionary");
  1029. + guarantee(k == probe->klass()->klass_part()->newest_version(), "klass should be in dictionary");
  1030. } else {
  1031. // If we don't find the class in the system dictionary, it
  1032. // has to be in the placeholders table.
  1033. diff --git a/src/share/vm/classfile/loaderConstraints.hpp b/src/share/vm/classfile/loaderConstraints.hpp
  1034. index d01b2c4..1ad80f7 100644
  1035. --- a/src/share/vm/classfile/loaderConstraints.hpp
  1036. +++ b/src/share/vm/classfile/loaderConstraints.hpp
  1037. @@ -106,7 +106,7 @@ public:
  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 --git a/src/share/vm/classfile/systemDictionary.cpp b/src/share/vm/classfile/systemDictionary.cpp
  1045. index 4899d32..365aeda 100644
  1046. --- a/src/share/vm/classfile/systemDictionary.cpp
  1047. +++ b/src/share/vm/classfile/systemDictionary.cpp
  1048. @@ -157,6 +157,7 @@ klassOop SystemDictionary::resolve_or_fail(Symbol* class_name, Handle class_load
  1049. // can return a null klass
  1050. klass = handle_resolution_exception(class_name, class_loader, protection_domain, throw_error, k_h, THREAD);
  1051. }
  1052. + assert(klass == NULL || klass->klass_part()->is_newest_version() || klass->klass_part()->newest_version()->klass_part()->is_redefining(), "must be");
  1053. return klass;
  1054. }
  1055. @@ -199,7 +200,8 @@ klassOop SystemDictionary::resolve_or_fail(Symbol* class_name,
  1056. // Forwards to resolve_instance_class_or_null
  1057. klassOop SystemDictionary::resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS) {
  1058. - assert(!THREAD->is_Compiler_thread(),
  1059. + // DCEVM: Check if this relaxing of the condition is correct? Test case hs203t004 failing otherwise.
  1060. + assert(!THREAD->is_Compiler_thread() || JvmtiThreadState::state_for(JavaThread::current())->get_class_being_redefined() != NULL,
  1061. err_msg("can not load classes with compiler thread: class=%s, classloader=%s",
  1062. class_name->as_C_string(),
  1063. class_loader.is_null() ? "null" : class_loader->klass()->klass_part()->name()->as_C_string()));
  1064. @@ -961,6 +963,7 @@ klassOop SystemDictionary::parse_stream(Symbol* class_name,
  1065. instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
  1066. class_loader,
  1067. protection_domain,
  1068. + KlassHandle(),
  1069. host_klass,
  1070. cp_patches,
  1071. parsed_name,
  1072. @@ -1022,7 +1025,14 @@ klassOop SystemDictionary::resolve_from_stream(Symbol* class_name,
  1073. Handle protection_domain,
  1074. ClassFileStream* st,
  1075. bool verify,
  1076. + KlassHandle old_class,
  1077. TRAPS) {
  1078. + bool redefine_classes_locked = false;
  1079. + if (!Thread::current()->redefine_classes_mutex()->owned_by_self()) {
  1080. + Thread::current()->redefine_classes_mutex()->lock();
  1081. + redefine_classes_locked = true;
  1082. + }
  1083. +
  1084. // Classloaders that support parallelism, e.g. bootstrap classloader,
  1085. // or all classloaders with UnsyncloadClass do not acquire lock here
  1086. bool DoObjectLock = true;
  1087. @@ -1050,9 +1060,14 @@ klassOop SystemDictionary::resolve_from_stream(Symbol* class_name,
  1088. instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
  1089. class_loader,
  1090. protection_domain,
  1091. + old_class,
  1092. parsed_name,
  1093. verify,
  1094. THREAD);
  1095. + if (!old_class.is_null() && !k.is_null()) {
  1096. + k->set_redefining(true);
  1097. + k->set_old_version(old_class());
  1098. + }
  1099. const char* pkg = "java/";
  1100. if (!HAS_PENDING_EXCEPTION &&
  1101. @@ -1087,13 +1102,18 @@ klassOop SystemDictionary::resolve_from_stream(Symbol* class_name,
  1102. // Add class just loaded
  1103. // If a class loader supports parallel classloading handle parallel define requests
  1104. // find_or_define_instance_class may return a different instanceKlass
  1105. - if (is_parallelCapable(class_loader)) {
  1106. + // (tw) TODO: for class redefinition the parallel version does not work, check if this is a problem?
  1107. + if (is_parallelCapable(class_loader) && old_class.is_null()) {
  1108. k = find_or_define_instance_class(class_name, class_loader, k, THREAD);
  1109. } else {
  1110. - define_instance_class(k, THREAD);
  1111. + define_instance_class(k, old_class, THREAD);
  1112. }
  1113. }
  1114. + if (redefine_classes_locked) {
  1115. + Thread::current()->redefine_classes_mutex()->unlock();
  1116. + }
  1117. +
  1118. // If parsing the class file or define_instance_class failed, we
  1119. // need to remove the placeholder added on our behalf. But we
  1120. // must make sure parsed_name is valid first (it won't be if we had
  1121. @@ -1122,7 +1142,7 @@ klassOop SystemDictionary::resolve_from_stream(Symbol* class_name,
  1122. MutexLocker mu(SystemDictionary_lock, THREAD);
  1123. klassOop check = find_class(parsed_name, class_loader);
  1124. - assert(check == k(), "should be present in the dictionary");
  1125. + assert((check == k() && !k->is_redefining()) || (k->is_redefining() && check == k->old_version()), "should be present in the dictionary");
  1126. klassOop check2 = find_class(h_name, h_loader);
  1127. assert(check == check2, "name inconsistancy in SystemDictionary");
  1128. @@ -1349,7 +1369,11 @@ instanceKlassHandle SystemDictionary::load_instance_class(Symbol* class_name, Ha
  1129. }
  1130. }
  1131. -void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) {
  1132. +void SystemDictionary::rollback_redefinition() {
  1133. + dictionary()->rollback_redefinition();
  1134. +}
  1135. +
  1136. +void SystemDictionary::define_instance_class(instanceKlassHandle k, KlassHandle old_class, TRAPS) {
  1137. Handle class_loader_h(THREAD, k->class_loader());
  1138. @@ -1376,13 +1400,23 @@ void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) {
  1139. Symbol* name_h = k->name();
  1140. unsigned int d_hash = dictionary()->compute_hash(name_h, class_loader_h);
  1141. int d_index = dictionary()->hash_to_index(d_hash);
  1142. - check_constraints(d_index, d_hash, k, class_loader_h, true, CHECK);
  1143. +
  1144. + // DCEVM: Update version of the klassOop in the system dictionary
  1145. + // TODO: Check for thread safety!
  1146. + if (!old_class.is_null()) {
  1147. + bool ok = dictionary()->update_klass(d_index, d_hash, name_h, class_loader_h, k, old_class);
  1148. + assert (ok, "must have found old class and updated!");
  1149. + }
  1150. + check_constraints(d_index, d_hash, k, class_loader_h, old_class.is_null(), CHECK);
  1151. +
  1152. + if(!old_class.is_null() && TraceRedefineClasses >= 3){ tty->print_cr("Class has been updated!"); }
  1153. // Register class just loaded with class loader (placed in Vector)
  1154. // Note we do this before updating the dictionary, as this can
  1155. // fail with an OutOfMemoryError (if it does, we will *not* put this
  1156. // class in the dictionary and will not update the class hierarchy).
  1157. - if (k->class_loader() != NULL) {
  1158. + // (tw) Only register if not redefining a class.
  1159. + if (k->class_loader() != NULL && old_class.is_null()) {
  1160. methodHandle m(THREAD, Universe::loader_addClass_method());
  1161. JavaValue result(T_VOID);
  1162. JavaCallArguments args(class_loader_h);
  1163. @@ -1408,8 +1442,9 @@ void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) {
  1164. }
  1165. k->eager_initialize(THREAD);
  1166. + // (tw) Only notify jvmti if not redefining a class.
  1167. // notify jvmti
  1168. - if (JvmtiExport::should_post_class_load()) {
  1169. + if (JvmtiExport::should_post_class_load() && old_class.is_null()) {
  1170. assert(THREAD->is_Java_thread(), "thread->is_Java_thread()");
  1171. JvmtiExport::post_class_load((JavaThread *) THREAD, k());
  1172. @@ -1482,7 +1517,7 @@ instanceKlassHandle SystemDictionary::find_or_define_instance_class(Symbol* clas
  1173. }
  1174. }
  1175. - define_instance_class(k, THREAD);
  1176. + define_instance_class(k, KlassHandle(), THREAD);
  1177. Handle linkage_exception = Handle(); // null handle
  1178. @@ -1613,6 +1648,14 @@ void SystemDictionary::add_to_hierarchy(instanceKlassHandle k, TRAPS) {
  1179. Universe::flush_dependents_on(k);
  1180. }
  1181. +// (tw) Remove from hierarchy - Undo add_to_hierarchy.
  1182. +void SystemDictionary::remove_from_hierarchy(instanceKlassHandle k) {
  1183. + assert(k.not_null(), "just checking");
  1184. +
  1185. + k->remove_from_sibling_list();
  1186. +
  1187. + // TODO: Remove from interfaces.
  1188. +}
  1189. // ----------------------------------------------------------------------------
  1190. // GC support
  1191. @@ -1702,6 +1745,24 @@ void SystemDictionary::oops_do(OopClosure* f) {
  1192. }
  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. +
  1199. + {
  1200. + for (int i = 0; i < T_VOID+1; i++) {
  1201. + if (_box_klasses[i] != NULL) {
  1202. + assert(i >= T_BOOLEAN, "checking");
  1203. + f->do_oop((oop*) &_box_klasses[i]);
  1204. + }
  1205. + }
  1206. + }
  1207. +
  1208. + // TODO: Check if we need to call FilterFieldsMap
  1209. +}
  1210. +
  1211. void SystemDictionary::preloaded_oops_do(OopClosure* f) {
  1212. for (int k = (int)FIRST_WKID; k < (int)WKID_LIMIT; k++) {
  1213. f->do_oop((oop*) &_well_known_klasses[k]);
  1214. @@ -1734,6 +1795,11 @@ void SystemDictionary::classes_do(void f(klassOop)) {
  1215. dictionary()->classes_do(f);
  1216. }
  1217. +// (tw) Iterate over all classes in the dictionary.
  1218. +void SystemDictionary::classes_do(ObjectClosure *closure) {
  1219. + dictionary()->classes_do(closure);
  1220. +}
  1221. +
  1222. // Added for initialize_itable_for_klass
  1223. // Just the classes from defining class loaders
  1224. // Don't iterate over placeholders
  1225. @@ -1870,7 +1936,9 @@ void SystemDictionary::initialize_preloaded_classes(TRAPS) {
  1226. // Preload ref klasses and set reference types
  1227. instanceKlass::cast(WK_KLASS(Reference_klass))->set_reference_type(REF_OTHER);
  1228. - instanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));
  1229. +
  1230. + // (tw) This is now done in parseClassFile in order to support class redefinition
  1231. + // instanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));
  1232. initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(PhantomReference_klass), scan, CHECK);
  1233. instanceKlass::cast(WK_KLASS(SoftReference_klass))->set_reference_type(REF_SOFT);
  1234. @@ -1956,7 +2024,11 @@ void SystemDictionary::check_constraints(int d_index, unsigned int d_hash,
  1235. // also holds array classes
  1236. assert(check->klass_part()->oop_is_instance(), "noninstance in systemdictionary");
  1237. - if ((defining == true) || (k() != check)) {
  1238. + if ((defining == true) && ((k() != check) && k->old_version() != check)) {
  1239. + ResourceMark rm(Thread::current());
  1240. + 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());
  1241. + k()->print();
  1242. + check->print();
  1243. linkage_error = "loader (instance of %s): attempted duplicate class "
  1244. "definition for name: \"%s\"";
  1245. } else {
  1246. diff --git a/src/share/vm/classfile/systemDictionary.hpp b/src/share/vm/classfile/systemDictionary.hpp
  1247. index 324d53d..0c600ae 100644
  1248. --- a/src/share/vm/classfile/systemDictionary.hpp
  1249. +++ b/src/share/vm/classfile/systemDictionary.hpp
  1250. @@ -269,7 +269,7 @@ public:
  1251. // Resolve from stream (called by jni_DefineClass and JVM_DefineClass)
  1252. static klassOop resolve_from_stream(Symbol* class_name, Handle class_loader,
  1253. Handle protection_domain,
  1254. - ClassFileStream* st, bool verify, TRAPS);
  1255. + ClassFileStream* st, bool verify, KlassHandle old_class, TRAPS);
  1256. // Lookup an already loaded class. If not found NULL is returned.
  1257. static klassOop find(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS);
  1258. @@ -310,6 +310,8 @@ public:
  1259. // Iterate over all klasses in dictionary
  1260. // Just the classes from defining class loaders
  1261. static void classes_do(void f(klassOop));
  1262. + static void classes_do(ObjectClosure *closure);
  1263. + static void preloaded_classes_do(OopClosure *closure);
  1264. // Added for initialize_itable_for_klass to handle exceptions
  1265. static void classes_do(void f(klassOop, TRAPS), TRAPS);
  1266. // All classes, and their class loaders
  1267. @@ -416,6 +418,8 @@ public:
  1268. initialize_wk_klasses_until((WKID) limit, start_id, THREAD);
  1269. }
  1270. + static void rollback_redefinition();
  1271. +
  1272. public:
  1273. #define WK_KLASS_DECLARE(name, symbol, option) \
  1274. static klassOop name() { return check_klass_##option(_well_known_klasses[WK_KLASS_ENUM_NAME(name)]); }
  1275. @@ -597,11 +601,11 @@ private:
  1276. // after waiting, but before reentering SystemDictionary_lock
  1277. // to preserve lock order semantics.
  1278. static void double_lock_wait(Handle lockObject, TRAPS);
  1279. - static void define_instance_class(instanceKlassHandle k, TRAPS);
  1280. + static void define_instance_class(instanceKlassHandle k, KlassHandle old_class, TRAPS);
  1281. static instanceKlassHandle find_or_define_instance_class(Symbol* class_name,
  1282. Handle class_loader,
  1283. instanceKlassHandle k, TRAPS);
  1284. - static instanceKlassHandle load_shared_class(Symbol* class_name,
  1285. + static instanceKlassHandle load_shared_class(Symbol* class_name, // after waiting, but before reentering SystemDictionary_lock,
  1286. Handle class_loader, TRAPS);
  1287. static instanceKlassHandle load_shared_class(instanceKlassHandle ik,
  1288. Handle class_loader, TRAPS);
  1289. @@ -616,12 +620,16 @@ private:
  1290. // Setup link to hierarchy
  1291. static void add_to_hierarchy(instanceKlassHandle k, TRAPS);
  1292. +public:
  1293. + // Remove link to hierarchy
  1294. + static void remove_from_hierarchy(instanceKlassHandle k);
  1295. +
  1296. +private:
  1297. // event based tracing
  1298. static void post_class_load_event(const Ticks& start_time, instanceKlassHandle k,
  1299. Handle initiating_loader);
  1300. static void post_class_unload_events(BoolObjectClosure* is_alive);
  1301. -private:
  1302. // We pass in the hashtable index so we can calculate it outside of
  1303. // the SystemDictionary_lock.
  1304. diff --git a/src/share/vm/classfile/verifier.cpp b/src/share/vm/classfile/verifier.cpp
  1305. index 0dbe9dd..f4b22cc 100644
  1306. --- a/src/share/vm/classfile/verifier.cpp
  1307. +++ b/src/share/vm/classfile/verifier.cpp
  1308. @@ -106,7 +106,7 @@ bool Verifier::relax_verify_for(oop loader) {
  1309. return !need_verify;
  1310. }
  1311. -bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, TRAPS) {
  1312. +bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, bool may_use_old_verifier, TRAPS) {
  1313. HandleMark hm;
  1314. ResourceMark rm(THREAD);
  1315. @@ -117,7 +117,8 @@ bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool shoul
  1316. const char* klassName = klass->external_name();
  1317. bool can_failover = FailOverToOldVerifier &&
  1318. - klass->major_version() < NOFAILOVER_MAJOR_VERSION;
  1319. + klass->major_version() < NOFAILOVER_MAJOR_VERSION &&
  1320. + may_use_old_verifier;
  1321. // If the class should be verified, first see if we can use the split
  1322. // verifier. If not, or if verification fails and FailOverToOldVerifier
  1323. @@ -138,6 +139,7 @@ bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool shoul
  1324. tty->print_cr(
  1325. "Fail over class verification to old verifier for: %s", klassName);
  1326. }
  1327. + assert(may_use_old_verifier, "");
  1328. exception_name = inference_verify(
  1329. klass, message_buffer, message_buffer_len, THREAD);
  1330. }
  1331. @@ -145,6 +147,7 @@ bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool shoul
  1332. exception_message = split_verifier.exception_message();
  1333. }
  1334. } else {
  1335. + assert(may_use_old_verifier, "");
  1336. exception_name = inference_verify(
  1337. klass, message_buffer, message_buffer_len, THREAD);
  1338. }
  1339. @@ -159,6 +162,9 @@ bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool shoul
  1340. }
  1341. tty->print_cr("End class verification for: %s", klassName);
  1342. }
  1343. + } else if (TraceClassInitialization) {
  1344. + // (tw) Output not verified classes
  1345. + tty->print_cr("Class %s was not verified", klassName);
  1346. }
  1347. if (HAS_PENDING_EXCEPTION) {
  1348. @@ -210,7 +216,7 @@ bool Verifier::is_eligible_for_verification(instanceKlassHandle klass, bool shou
  1349. // NOTE: this is called too early in the bootstrapping process to be
  1350. // guarded by Universe::is_gte_jdk14x_version()/UseNewReflection.
  1351. (refl_magic_klass == NULL ||
  1352. - !klass->is_subtype_of(refl_magic_klass) ||
  1353. + !(klass->is_subtype_of(refl_magic_klass) || klass->is_subtype_of(refl_magic_klass->klass_part()->newest_version())) ||
  1354. VerifyReflectionBytecodes)
  1355. );
  1356. }
  1357. @@ -517,7 +523,7 @@ void ErrorContext::stackmap_details(outputStream* ss, methodOop method) const {
  1358. ClassVerifier::ClassVerifier(
  1359. instanceKlassHandle klass, TRAPS)
  1360. - : _thread(THREAD), _exception_type(NULL), _message(NULL), _klass(klass) {
  1361. + : _thread(THREAD), _exception_type(NULL), _message(NULL), _klass(klass->newest_version()), _klass_to_verify(klass) {
  1362. _this_type = VerificationType::reference_type(klass->name());
  1363. // Create list to hold symbols in reference area.
  1364. _symbols = new GrowableArray<Symbol*>(100, 0, NULL);
  1365. @@ -547,7 +553,7 @@ void ClassVerifier::verify_class(TRAPS) {
  1366. _klass->external_name());
  1367. }
  1368. - objArrayHandle methods(THREAD, _klass->methods());
  1369. + objArrayHandle methods(THREAD, _klass_to_verify->methods());
  1370. int num_methods = methods->length();
  1371. for (int index = 0; index < num_methods; index++) {
  1372. @@ -2475,7 +2481,10 @@ void ClassVerifier::verify_invoke_instructions(
  1373. VerificationType stack_object_type =
  1374. current_frame->pop_stack(ref_class_type, CHECK_VERIFY(this));
  1375. if (current_type() != stack_object_type) {
  1376. - assert(cp->cache() == NULL, "not rewritten yet");
  1377. +
  1378. + // (tw) TODO: Check if relaxing the following assertion is correct. For class redefinition we might call the verifier twice.
  1379. + //assert(cp->cache() == NULL, "not rewritten yet");
  1380. +
  1381. Symbol* ref_class_name =
  1382. cp->klass_name_at(cp->klass_ref_index_at(index));
  1383. // See the comments in verify_field_instructions() for
  1384. diff --git a/src/share/vm/classfile/verifier.hpp b/src/share/vm/classfile/verifier.hpp
  1385. index 022c9b7..c495af4 100644
  1386. --- a/src/share/vm/classfile/verifier.hpp
  1387. +++ b/src/share/vm/classfile/verifier.hpp
  1388. @@ -47,7 +47,7 @@ class Verifier : AllStatic {
  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. @@ -259,7 +259,10 @@ class ClassVerifier : public StackObj {
  1397. // Used to detect illegal jumps over calls to super() and this() in ctors.
  1398. int32_t _furthest_jump;
  1399. +public:
  1400. void verify_method(methodHandle method, TRAPS);
  1401. +
  1402. +private:
  1403. char* generate_code_data(methodHandle m, u4 code_length, TRAPS);
  1404. void verify_exception_handler_table(u4 code_length, char* code_data,
  1405. int& min, int& max, TRAPS);
  1406. @@ -332,6 +335,7 @@ class ClassVerifier : public StackObj {
  1407. VerificationType object_type() const;
  1408. + instanceKlassHandle _klass_to_verify;
  1409. instanceKlassHandle _klass; // the class being verified
  1410. methodHandle _method; // current method being verified
  1411. VerificationType _this_type; // the verification type of the current class
  1412. diff --git a/src/share/vm/classfile/vmSymbols.hpp b/src/share/vm/classfile/vmSymbols.hpp
  1413. index 5b773da..b20086b 100644
  1414. --- a/src/share/vm/classfile/vmSymbols.hpp
  1415. +++ b/src/share/vm/classfile/vmSymbols.hpp
  1416. @@ -138,6 +138,10 @@
  1417. template(tag_annotation_default, "AnnotationDefault") \
  1418. template(tag_enclosing_method, "EnclosingMethod") \
  1419. template(tag_bootstrap_methods, "BootstrapMethods") \
  1420. + template(tag_static_field_redefinition_policy, "StaticFieldRedefinitionPolicy") \
  1421. + template(tag_field_redefinition_policy, "FieldRedefinitionPolicy") \
  1422. + template(tag_method_redefinition_policy, "MethodRedefinitionPolicy") \
  1423. + template(tag_code_sections, "CodeSections") \
  1424. \
  1425. /* exception klasses: at least all exceptions thrown by the VM have entries here */ \
  1426. template(java_lang_ArithmeticException, "java/lang/ArithmeticException") \
  1427. @@ -379,6 +383,10 @@
  1428. template(oop_size_name, "oop_size") \
  1429. template(static_oop_field_count_name, "static_oop_field_count") \
  1430. \
  1431. + /* mutator in case of class redefinition */ \
  1432. + template(static_transformer_name, "$staticTransformer") \
  1433. + template(transformer_name, "$transformer") \
  1434. + \
  1435. /* non-intrinsic name/signature pairs: */ \
  1436. template(register_method_name, "register") \
  1437. do_alias(register_method_signature, object_void_signature) \
  1438. diff --git a/src/share/vm/compiler/compileBroker.cpp b/src/share/vm/compiler/compileBroker.cpp
  1439. index 3e8a65a..fe96a94 100644
  1440. --- a/src/share/vm/compiler/compileBroker.cpp
  1441. +++ b/src/share/vm/compiler/compileBroker.cpp
  1442. @@ -1181,6 +1181,14 @@ nmethod* CompileBroker::compile_method(methodHandle method, int osr_bci,
  1443. int comp_level,
  1444. methodHandle hot_method, int hot_count,
  1445. const char* comment, Thread* THREAD) {
  1446. + JavaThread* thread = JavaThread::current();
  1447. + if (thread->is_Compiler_thread() && thread->as_CompilerThread()->should_bailout()) {
  1448. + return NULL; // FIXME: DCEVM: should we do something else?
  1449. + }
  1450. + if (instanceKlass::cast(method->method_holder())->is_not_initialized()) {
  1451. + return NULL; // FIXME: DCEVM: how should we avoid this?
  1452. + }
  1453. +
  1454. // make sure arguments make sense
  1455. assert(method->method_holder()->klass_part()->oop_is_instance(), "not an instance method");
  1456. assert(osr_bci == InvocationEntryBci || (0 <= osr_bci && osr_bci < method->code_size()), "bci out of range");
  1457. @@ -1260,6 +1268,7 @@ nmethod* CompileBroker::compile_method(methodHandle method, int osr_bci,
  1458. }
  1459. // RedefineClasses() has replaced this method; just return
  1460. + // (tw) This is important for the new version of hotswapping: Old code will only execute properly in the interpreter!
  1461. if (method->is_old()) {
  1462. return NULL;
  1463. }
  1464. @@ -1592,6 +1601,8 @@ void CompileBroker::compiler_thread_loop() {
  1465. // Never compile a method if breakpoints are present in it
  1466. if (method()->number_of_breakpoints() == 0) {
  1467. + thread->compilation_mutex()->lock();
  1468. + thread->set_should_bailout(false);
  1469. // Compile the method.
  1470. if ((UseCompiler || AlwaysCompileLoopMethods) && CompileBroker::should_compile_new_jobs()) {
  1471. #ifdef COMPILER1
  1472. @@ -1615,6 +1626,7 @@ void CompileBroker::compiler_thread_loop() {
  1473. // After compilation is disabled, remove remaining methods from queue
  1474. method->clear_queued_for_compilation();
  1475. }
  1476. + thread->compilation_mutex()->unlock();
  1477. }
  1478. }
  1479. }
  1480. @@ -2165,3 +2177,15 @@ void CompileBroker::print_compiler_threads_on(outputStream* st) {
  1481. st->cr();
  1482. #endif
  1483. }
  1484. +
  1485. +// (tw) Clean up compiler interface after a class redefinition step
  1486. +void CompileBroker::cleanup_after_redefinition() {
  1487. + int num_threads = _method_threads->length();
  1488. +
  1489. + ciObjectFactory::sort_ci_objects(ciObjectFactory::_shared_ci_objects);
  1490. + for (int i=0; i<num_threads; i++) {
  1491. + if (_method_threads->at(i)->env() != NULL && _method_threads->at(i)->env() != (ciEnv *)badAddress) {
  1492. + _method_threads->at(i)->env()->cleanup_after_redefinition();
  1493. + }
  1494. + }
  1495. +}
  1496. diff --git a/src/share/vm/compiler/compileBroker.hpp b/src/share/vm/compiler/compileBroker.hpp
  1497. index 29f2b22..37989d1 100644
  1498. --- a/src/share/vm/compiler/compileBroker.hpp
  1499. +++ b/src/share/vm/compiler/compileBroker.hpp
  1500. @@ -408,6 +408,7 @@ class CompileBroker: AllStatic {
  1501. static void print_compiler_threads_on(outputStream* st);
  1502. + static void cleanup_after_redefinition();
  1503. static int get_total_compile_count() { return _total_compile_count; }
  1504. static int get_total_bailout_count() { return _total_bailout_count; }
  1505. static int get_total_invalidated_count() { return _total_invalidated_count; }
  1506. diff --git a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
  1507. index b0c9ec8..b3298e0 100644
  1508. --- a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
  1509. +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
  1510. @@ -162,6 +162,13 @@ CompactibleFreeListSpace::CompactibleFreeListSpace(BlockOffsetSharedArray* bs,
  1511. }
  1512. }
  1513. +
  1514. +HeapWord* CompactibleFreeListSpace::forward_compact_top(size_t size,
  1515. + CompactPoint* cp, HeapWord* compact_top) {
  1516. + ShouldNotReachHere();
  1517. + return NULL;
  1518. +}
  1519. +
  1520. // Like CompactibleSpace forward() but always calls cross_threshold() to
  1521. // update the block offset table. Removed initialize_threshold call because
  1522. // CFLS does not use a block offset array for contiguous spaces.
  1523. diff --git a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
  1524. index 3b7bb9a..de7e54b 100644
  1525. --- a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
  1526. +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
  1527. @@ -149,6 +149,7 @@ class CompactibleFreeListSpace: public CompactibleSpace {
  1528. // Support for compacting cms
  1529. HeapWord* cross_threshold(HeapWord* start, HeapWord* end);
  1530. + HeapWord* forward_compact_top(size_t size, CompactPoint* cp, HeapWord* compact_top);
  1531. HeapWord* forward(oop q, size_t size, CompactPoint* cp, HeapWord* compact_top);
  1532. // Initialization helpers.
  1533. diff --git a/src/share/vm/gc_implementation/shared/markSweep.cpp b/src/share/vm/gc_implementation/shared/markSweep.cpp
  1534. index 29841d8..a13a35d 100644
  1535. --- a/src/share/vm/gc_implementation/shared/markSweep.cpp
  1536. +++ b/src/share/vm/gc_implementation/shared/markSweep.cpp
  1537. @@ -32,6 +32,8 @@
  1538. #include "oops/objArrayKlass.inline.hpp"
  1539. #include "oops/oop.inline.hpp"
  1540. +GrowableArray<oop>* MarkSweep::_rescued_oops = NULL;
  1541. +
  1542. Stack<oop, mtGC> MarkSweep::_marking_stack;
  1543. Stack<DataLayout*, mtGC> MarkSweep::_revisit_mdo_stack;
  1544. Stack<Klass*, mtGC> MarkSweep::_revisit_klass_stack;
  1545. @@ -357,3 +359,86 @@ void MarkSweep::trace(const char* msg) {
  1546. }
  1547. #endif
  1548. +
  1549. +// (tw) Copy the rescued objects to their destination address after compaction.
  1550. +void MarkSweep::copy_rescued_objects_back() {
  1551. +
  1552. + if (_rescued_oops != NULL) {
  1553. +
  1554. + for (int i=0; i<_rescued_oops->length(); i++) {
  1555. + oop rescued_obj = _rescued_oops->at(i);
  1556. +
  1557. + int size = rescued_obj->size();
  1558. + oop new_obj = rescued_obj->forwardee();
  1559. +
  1560. + if (rescued_obj->blueprint()->new_version() != NULL) {
  1561. + MarkSweep::update_fields(rescued_obj, new_obj);
  1562. + } else {
  1563. + Copy::aligned_disjoint_words((HeapWord*)rescued_obj, (HeapWord*)new_obj, size);
  1564. + }
  1565. +
  1566. + FREE_RESOURCE_ARRAY(HeapWord, rescued_obj, size);
  1567. +
  1568. + new_obj->init_mark();
  1569. + assert(new_obj->is_oop(), "must be a valid oop");
  1570. + }
  1571. + _rescued_oops->clear();
  1572. + _rescued_oops = NULL;
  1573. + }
  1574. +}
  1575. +
  1576. +// (tw) Update instances of a class whose fields changed.
  1577. +void MarkSweep::update_fields(oop q, oop new_location) {
  1578. +
  1579. + assert(q->blueprint()->new_version() != NULL, "class of old object must have new version");
  1580. +
  1581. + klassOop old_klass_oop = q->klass();
  1582. + klassOop new_klass_oop = q->blueprint()->new_version();
  1583. +
  1584. + instanceKlass *old_klass = instanceKlass::cast(old_klass_oop);
  1585. + instanceKlass *new_klass = instanceKlass::cast(new_klass_oop);
  1586. +
  1587. + int size = q->size_given_klass(old_klass);
  1588. + int new_size = q->size_given_klass(new_klass);
  1589. +
  1590. + oop tmp_obj = q;
  1591. +
  1592. + if (new_klass_oop->klass_part()->is_copying_backwards()) {
  1593. + if (((HeapWord *)q >= (HeapWord *)new_location && (HeapWord *)q < (HeapWord *)new_location + new_size) ||
  1594. + ((HeapWord *)new_location >= (HeapWord *)q && (HeapWord *)new_location < (HeapWord *)q + size)) {
  1595. + tmp_obj = (oop)resource_allocate_bytes(size * HeapWordSize);
  1596. + Copy::aligned_disjoint_words((HeapWord*)q, (HeapWord*)tmp_obj, size);
  1597. + }
  1598. + }
  1599. +
  1600. + int *cur = new_klass_oop->klass_part()->update_information();
  1601. +
  1602. + tmp_obj->set_klass_no_check(new_klass_oop);
  1603. +
  1604. + if (cur == NULL) {
  1605. + assert(size == new_size, "just checking");
  1606. + Copy::conjoint_words(((HeapWord *)tmp_obj), ((HeapWord *)new_location), size);
  1607. + } else {
  1608. + int destOffset = 0;
  1609. + while (*cur != 0) {
  1610. + if (*cur > 0) {
  1611. + int size = *cur;
  1612. + cur++;
  1613. + int offset = *cur;
  1614. + Copy::conjoint_jbytes(((char *)tmp_obj) + offset, ((char *)new_location) + destOffset, size);
  1615. + destOffset += size;
  1616. + cur++;
  1617. + } else {
  1618. + assert(*cur < 0, "");
  1619. + int skip = -*cur;
  1620. + Copy::fill_to_bytes(((char*)new_location) + destOffset, skip, 0);
  1621. + destOffset += skip;
  1622. + cur++;
  1623. + }
  1624. + }
  1625. + }
  1626. +
  1627. + if (tmp_obj != q) {
  1628. + FREE_RESOURCE_ARRAY(HeapWord, tmp_obj, size);
  1629. + }
  1630. +}
  1631. diff --git a/src/share/vm/gc_implementation/shared/markSweep.hpp b/src/share/vm/gc_implementation/shared/markSweep.hpp
  1632. index eb8252c..b96a677 100644
  1633. --- a/src/share/vm/gc_implementation/shared/markSweep.hpp
  1634. +++ b/src/share/vm/gc_implementation/shared/markSweep.hpp
  1635. @@ -117,8 +117,12 @@ class MarkSweep : AllStatic {
  1636. friend class AdjustPointerClosure;
  1637. friend class KeepAliveClosure;
  1638. friend class VM_MarkSweep;
  1639. + friend class GenMarkSweep;
  1640. friend void marksweep_init();
  1641. +public:
  1642. + static GrowableArray<oop>* _rescued_oops;
  1643. +
  1644. //
  1645. // Vars
  1646. //
  1647. @@ -208,6 +212,8 @@ class MarkSweep : AllStatic {
  1648. template <class T> static inline void mark_and_push(T* p);
  1649. static inline void push_objarray(oop obj, size_t index);
  1650. + static void copy_rescued_objects_back();
  1651. + static void update_fields(oop q, oop new_location);
  1652. static void follow_stack(); // Empty marking stack.
  1653. static void preserve_mark(oop p, markOop mark);
  1654. diff --git a/src/share/vm/interpreter/interpreterRuntime.cpp b/src/share/vm/interpreter/interpreterRuntime.cpp
  1655. index 1a1af1b..94972f0 100644
  1656. --- a/src/share/vm/interpreter/interpreterRuntime.cpp
  1657. +++ b/src/share/vm/interpreter/interpreterRuntime.cpp
  1658. @@ -402,7 +402,7 @@ IRT_ENTRY(address, InterpreterRuntime::exception_handler_for_exception(JavaThrea
  1659. assert(h_exception.not_null(), "NULL exceptions should be handled by athrow");
  1660. assert(h_exception->is_oop(), "just checking");
  1661. // Check that exception is a subclass of Throwable, otherwise we have a VerifyError
  1662. - if (!(h_exception->is_a(SystemDictionary::Throwable_klass()))) {
  1663. + if (!(h_exception->is_a(SystemDictionary::Throwable_klass()->klass_part()->newest_version())) && !(h_exception->is_a(SystemDictionary::Throwable_klass()))) {
  1664. if (ExitVMOnVerifyError) vm_exit(-1);
  1665. ShouldNotReachHere();
  1666. }
  1667. @@ -656,6 +656,82 @@ IRT_ENTRY(void, InterpreterRuntime::_breakpoint(JavaThread* thread, methodOopDes
  1668. JvmtiExport::post_raw_breakpoint(thread, method, bcp);
  1669. IRT_END
  1670. +// (tw) Correctly resolve method when running old code.
  1671. +IRT_ENTRY(void, InterpreterRuntime::forward_method(JavaThread *thread))
  1672. + {
  1673. + MonitorLockerEx ml(RedefinitionSync_lock);
  1674. + while (Threads::wait_at_instrumentation_entry()) {
  1675. + ml.wait();
  1676. + }
  1677. + }
  1678. + frame f = last_frame(thread);
  1679. + methodOop m = f.interpreter_frame_method();
  1680. + methodOop forward_method = m->forward_method();
  1681. + if (forward_method != NULL) {
  1682. + int bci = f.interpreter_frame_bci();
  1683. +
  1684. + if (TraceRedefineClasses >= 3) {
  1685. + 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));
  1686. + }
  1687. +
  1688. + int next_bci = bci - 1;
  1689. + // First try bci before NOP.
  1690. + if (!m->is_in_code_section(next_bci)) {
  1691. + // Try bci after NOP.
  1692. + next_bci = bci + 1;
  1693. + if (!m->is_in_code_section(next_bci)) return;
  1694. + }
  1695. +
  1696. + int new_bci = m->calculate_forward_bci(next_bci, forward_method);
  1697. + if (TraceRedefineClasses >= 2) {
  1698. + 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);
  1699. + }
  1700. + RegisterMap reg_map(thread);
  1701. + vframe* vf = vframe::new_vframe(&f, &reg_map, thread);
  1702. + interpretedVFrame *iframe = (interpretedVFrame *)vf;
  1703. + iframe->set_method(forward_method, new_bci - 1);
  1704. + }
  1705. +IRT_END
  1706. +
  1707. +// (tw) Correctly resolve method when running old code.
  1708. +IRT_ENTRY(void, InterpreterRuntime::find_correct_method(JavaThread *thread, oopDesc* receiverOop, int vTableIndex))
  1709. + // extract receiver from the outgoing argument list if necessary
  1710. + Handle receiver(thread, receiverOop);
  1711. +
  1712. + // TODO: Check for invokeinterface!
  1713. + Bytecodes::Code bytecode = Bytecodes::_invokevirtual;
  1714. +
  1715. + int method_holder_revision_number = method(thread)->method_holder()->klass_part()->revision_number();
  1716. + klassOop klass = receiverOop->klass();
  1717. + while (klass->klass_part()->revision_number() > method_holder_revision_number) {
  1718. + klass = klass->klass_part()->old_version();
  1719. + }
  1720. +
  1721. + // TODO: Check for correctness if different vtable indices in different versions?
  1722. +
  1723. + methodOop method = ((instanceKlass *)klass->klass_part())->method_at_vtable(vTableIndex);
  1724. + thread->set_vm_result(method);
  1725. +IRT_END
  1726. +
  1727. +// Correctly resolve interface method when running old code.
  1728. +IRT_ENTRY(void, InterpreterRuntime::find_correct_interface_method(JavaThread *thread, oopDesc* receiverOop, oopDesc* interface_klass, int vTableIndex))
  1729. +
  1730. + // extract receiver from the outgoing argument list if necessary
  1731. + Handle receiver(thread, receiverOop);
  1732. +
  1733. + // TODO: Check for invokeinterface!
  1734. + Bytecodes::Code bytecode = Bytecodes::_invokevirtual;
  1735. +
  1736. + int method_holder_revision_number = method(thread)->method_holder()->klass_part()->revision_number();
  1737. + klassOop klass = receiverOop->klass();
  1738. + while (klass->klass_part()->revision_number() > method_holder_revision_number) {
  1739. + klass = klass->klass_part()->old_version();
  1740. + }
  1741. +
  1742. + methodOop method = ((instanceKlass *)klass->klass_part())->method_at_itable((klassOop)interface_klass, vTableIndex, THREAD);
  1743. + thread->set_vm_result(method);
  1744. +IRT_END
  1745. +
  1746. IRT_ENTRY(void, InterpreterRuntime::resolve_invoke(JavaThread* thread, Bytecodes::Code bytecode)) {
  1747. // extract receiver from the outgoing argument list if necessary
  1748. Handle receiver(thread, NULL);
  1749. @@ -684,6 +760,10 @@ IRT_ENTRY(void, InterpreterRuntime::resolve_invoke(JavaThread* thread, Bytecodes
  1750. if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
  1751. int retry_count = 0;
  1752. while (info.resolved_method()->is_old()) {
  1753. + // (tw) If we are executing an old method, this is OK!
  1754. + if (method(thread)->is_old()) {
  1755. + break;
  1756. + }
  1757. // It is very unlikely that method is redefined more than 100 times
  1758. // in the middle of resolve. If it is looping here more than 100 times
  1759. // means then there could be a bug here.
  1760. diff --git a/src/share/vm/interpreter/interpreterRuntime.hpp b/src/share/vm/interpreter/interpreterRuntime.hpp
  1761. index 6d5f13a..50fa219 100644
  1762. --- a/src/share/vm/interpreter/interpreterRuntime.hpp
  1763. +++ b/src/share/vm/interpreter/interpreterRuntime.hpp
  1764. @@ -141,6 +141,9 @@ class InterpreterRuntime: AllStatic {
  1765. static void post_method_entry(JavaThread *thread);
  1766. static void post_method_exit (JavaThread *thread);
  1767. static int interpreter_contains(address pc);
  1768. + static void forward_method(JavaThread *thread);
  1769. + static void find_correct_method(JavaThread *thread, oopDesc* receiver, int vTableIndex);
  1770. + static void find_correct_interface_method(JavaThread *thread, oopDesc* receiver, oopDesc* interface_klass, int vTableIndex);
  1771. // Native signature handlers
  1772. static void prepare_native_call(JavaThread* thread, methodOopDesc* method);
  1773. diff --git a/src/share/vm/interpreter/linkResolver.cpp b/src/share/vm/interpreter/linkResolver.cpp
  1774. index 1676add..ccd5241 100644
  1775. --- a/src/share/vm/interpreter/linkResolver.cpp
  1776. +++ b/src/share/vm/interpreter/linkResolver.cpp
  1777. @@ -153,8 +153,8 @@ void CallInfo::set_common(KlassHandle resolved_klass, KlassHandle selected_klass
  1778. // Klass resolution
  1779. void LinkResolver::check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS) {
  1780. - if (!Reflection::verify_class_access(ref_klass->as_klassOop(),
  1781. - sel_klass->as_klassOop(),
  1782. + if (!Reflection::verify_class_access(ref_klass->as_klassOop()->klass_part()->newest_version(),
  1783. + sel_klass->as_klassOop()->klass_part()->newest_version(),
  1784. true)) {
  1785. ResourceMark rm(THREAD);
  1786. Exceptions::fthrow(
  1787. @@ -346,7 +346,7 @@ void LinkResolver::check_method_accessability(KlassHandle ref_klass,
  1788. // We'll check for the method name first, as that's most likely
  1789. // to be false (so we'll short-circuit out of these tests).
  1790. if (sel_method->name() == vmSymbols::clone_name() &&
  1791. - sel_klass() == SystemDictionary::Object_klass() &&
  1792. + sel_klass()->klass_part()->newest_version() == SystemDictionary::Object_klass()->klass_part()->newest_version() &&
  1793. resolved_klass->oop_is_array()) {
  1794. // We need to change "protected" to "public".
  1795. assert(flags.is_protected(), "clone not protected?");
  1796. @@ -412,48 +412,169 @@ void LinkResolver::resolve_method_statically(methodHandle& resolved_method, Klas
  1797. }
  1798. }
  1799. -void LinkResolver::resolve_method(methodHandle& resolved_method, KlassHandle resolved_klass,
  1800. - Symbol* method_name, Symbol* method_signature,
  1801. - KlassHandle current_klass, bool check_access, TRAPS) {
  1802. - // 1. check if klass is not interface
  1803. - if (resolved_klass->is_interface()) {
  1804. - ResourceMark rm(THREAD);
  1805. - char buf[200];
  1806. - jio_snprintf(buf, sizeof(buf), "Found interface %s, but class was expected", Klass::cast(resolved_klass())->external_name());
  1807. - THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
  1808. +void LinkResolver::lookup_method(methodHandle& resolved_method, KlassHandle resolved_klass,
  1809. + Symbol* method_name, Symbol* method_signature, bool is_interface, KlassHandle current_klass, TRAPS) {
  1810. +
  1811. + // Interface method lookup?
  1812. + if (is_interface) {
  1813. +
  1814. + // lookup method in this interface or its super, java.lang.Object
  1815. + lookup_instance_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1816. +
  1817. + if (resolved_method.is_null() && !resolved_klass->oop_is_array()) {
  1818. + // lookup method in all the super-interfaces
  1819. + lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1820. + }
  1821. +
  1822. + // Other methods
  1823. + } else {
  1824. + Handle nested_exception;
  1825. +
  1826. + // 2. lookup method in resolved klass and its super klasses
  1827. + lookup_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1828. +
  1829. + if (resolved_method.is_null() && !resolved_klass->oop_is_array()) { // not found in the class hierarchy
  1830. + // 3. lookup method in all the interfaces implemented by the resolved klass
  1831. + lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1832. +
  1833. + if (resolved_method.is_null()) {
  1834. + // JSR 292: see if this is an implicitly generated method MethodHandle.linkToVirtual(*...), etc
  1835. + lookup_polymorphic_method(resolved_method, resolved_klass, method_name, method_signature,
  1836. + current_klass, (Handle*)NULL, (Handle*)NULL, THREAD);
  1837. + if (HAS_PENDING_EXCEPTION) {
  1838. + nested_exception = Handle(THREAD, PENDING_EXCEPTION);
  1839. + CLEAR_PENDING_EXCEPTION;
  1840. + }
  1841. + }
  1842. + }
  1843. }
  1844. +}
  1845. - Handle nested_exception;
  1846. +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) {
  1847. - // 2. lookup method in resolved klass and its super klasses
  1848. - lookup_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1849. + // First attempt unversioned
  1850. + sel_klass = KlassHandle(Thread::current(), resolved_klass->find_field(field_name, field_sig, &fd));
  1851. - if (resolved_method.is_null() && !resolved_klass->oop_is_array()) { // not found in the class hierarchy
  1852. - // 3. lookup method in all the interfaces implemented by the resolved klass
  1853. - lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1854. + if (!current_klass.is_null() && !current_klass->is_newest_version()) {
  1855. +
  1856. + // 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).
  1857. + int redefinition_policy = current_klass->new_version()->klass_part()->field_redefinition_policy();
  1858. + if (is_static) {
  1859. + redefinition_policy = current_klass->new_version()->klass_part()->static_field_redefinition_policy();
  1860. + }
  1861. +
  1862. + assert(redefinition_policy != Klass::StaticCheck, "if the policy is static check, then we can never reach here");
  1863. +
  1864. + if (redefinition_policy != Klass::DynamicCheck) {
  1865. +
  1866. + if (redefinition_policy == Klass::AccessOldMembers) {
  1867. + // Forget looked up fields
  1868. + sel_klass = KlassHandle(Thread::current(), (oop)NULL);
  1869. + }
  1870. +
  1871. + assert(redefinition_policy == Klass::AccessOldMembers || redefinition_policy == Klass::AccessDeletedMembers, "");
  1872. +
  1873. + if (sel_klass.is_null() || fd.is_static() != is_static /* access old static field field is changed from static to non-static */) {
  1874. +
  1875. + // Select correct version for resolved klass.
  1876. + find_correct_resolved_klass(resolved_klass, current_klass);
  1877. +
  1878. + sel_klass = KlassHandle(Thread::current(), instanceKlass::cast(resolved_klass())->find_field(field_name, field_sig, &fd));
  1879. - if (resolved_method.is_null()) {
  1880. - // JSR 292: see if this is an implicitly generated method MethodHandle.linkToVirtual(*...), etc
  1881. - lookup_polymorphic_method(resolved_method, resolved_klass, method_name, method_signature,
  1882. - current_klass, (Handle*)NULL, (Handle*)NULL, THREAD);
  1883. - if (HAS_PENDING_EXCEPTION) {
  1884. - nested_exception = Handle(THREAD, PENDING_EXCEPTION);
  1885. - CLEAR_PENDING_EXCEPTION;
  1886. + // FIXME: idubrov
  1887. + //if (sel_klass.is_null()) {
  1888. + // TRACE_RC2("Trying to resolve field (%s) in old universe failed => exception is the correct behaviour", field_name->as_C_string());
  1889. + //} else {
  1890. + // assert(sel_klass->new_version() != NULL, "must be old class!");
  1891. + // TRACE_RC2("Resolved a field in the old universe (%s)!", field_name->as_C_string());
  1892. + //}
  1893. }
  1894. }
  1895. }
  1896. +}
  1897. - if (resolved_method.is_null()) {
  1898. - // 4. method lookup failed
  1899. +void LinkResolver::lookup_correct_method(methodHandle& resolved_method, KlassHandle resolved_klass, KlassHandle current_klass,
  1900. + Symbol* method_name, Symbol* method_signature, bool is_interface, TRAPS) {
  1901. +
  1902. + // First attempt unversioned
  1903. + lookup_method(resolved_method, resolved_klass, method_name, method_signature, is_interface, current_klass, CHECK);
  1904. +
  1905. + // (tw) Are we in an old method that wants to see a different view on the world?
  1906. + if (!current_klass.is_null() && !current_klass->is_newest_version()) {
  1907. +
  1908. + // 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).
  1909. + int method_redefinition_policy = current_klass->new_version()->klass_part()->method_redefinition_policy();
  1910. + assert(method_redefinition_policy != Klass::StaticCheck, "if the policy is static check, then we can never reach here");
  1911. +
  1912. + if (method_redefinition_policy != Klass::DynamicCheck) {
  1913. +
  1914. + // We do not throw the exception
  1915. + if (method_redefinition_policy == Klass::AccessOldMembers) {
  1916. + // Forget any new member lookup
  1917. + resolved_method = methodHandle(THREAD, NULL);
  1918. + }
  1919. +
  1920. + assert(method_redefinition_policy == Klass::AccessOldMembers || method_redefinition_policy == Klass::AccessDeletedMembers, "");
  1921. +
  1922. + if (resolved_method.is_null()) {
  1923. +
  1924. + // Select correct version for resolved klass.
  1925. + find_correct_resolved_klass(resolved_klass, current_klass);
  1926. +
  1927. + // Now do the lookup in a second attempt with a different resolved klass.
  1928. + lookup_method(resolved_method, resolved_klass, method_name, method_signature, is_interface, current_klass, CHECK);
  1929. +
  1930. + // FIXME: idubrov
  1931. + //IF_TRACE_RC2 {
  1932. + // ResourceMark rm(THREAD);
  1933. + // if (resolved_method.is_null()) {
  1934. + // TRACE_RC2("Trying to resolve method (%s) in old universe failed => exception is the correct behaviour", method_name->as_C_string());
  1935. + // } else {
  1936. + // assert(resolved_method->is_old(), "must be old method!");
  1937. + // TRACE_RC2("Resolved a method in the old universe (%s)!", resolved_method->name()->as_C_string());
  1938. + // }
  1939. + //}
  1940. + }
  1941. + }
  1942. + }
  1943. +
  1944. + if (resolved_method.is_null()) {
  1945. + // no method found
  1946. + ResourceMark rm(THREAD);
  1947. + THROW_MSG(vmSymbols::java_lang_NoSuchMethodError(),
  1948. + methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()),
  1949. + method_name,
  1950. + method_signature));
  1951. + }
  1952. +}
  1953. +
  1954. +void LinkResolver::find_correct_resolved_klass(KlassHandle &resolved_klass, KlassHandle &current_klass) {
  1955. + int current_klass_revision = current_klass->revision_number();
  1956. + int resolved_klass_revision = resolved_klass->revision_number();
  1957. + // FIXME: idubrov
  1958. + //TRACE_RC2("The two different revision numbers for interfaces: current=%d / resolved_callee=%d", current_klass_revision, resolved_klass_revision);
  1959. +
  1960. + while (resolved_klass->revision_number() > current_klass_revision) {
  1961. + assert(resolved_klass->old_version(), "must have old version");
  1962. + resolved_klass = KlassHandle(Thread::current(), resolved_klass->old_version());
  1963. + }
  1964. +}
  1965. +void LinkResolver::resolve_method(methodHandle& resolved_method, KlassHandle resolved_klass,
  1966. + Symbol* method_name, Symbol* method_signature,
  1967. + KlassHandle current_klass, bool check_access, TRAPS) {
  1968. +
  1969. + // 1. check if klass is not interface
  1970. + if (resolved_klass->is_interface()) {
  1971. ResourceMark rm(THREAD);
  1972. - THROW_MSG_CAUSE(vmSymbols::java_lang_NoSuchMethodError(),
  1973. - methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()),
  1974. - method_name,
  1975. - method_signature),
  1976. - nested_exception);
  1977. + char buf[200];
  1978. + jio_snprintf(buf, sizeof(buf), "Found interface %s, but class was expected", Klass::cast(resolved_klass())->external_name());
  1979. + THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
  1980. }
  1981. + // 2. and 3. and 4. lookup method in resolved klass and its super klasses
  1982. + lookup_correct_method(resolved_method, resolved_klass, current_klass, method_name, method_signature, false, CHECK);
  1983. +
  1984. // 5. check if method is concrete
  1985. if (resolved_method->is_abstract() && !resolved_klass->is_abstract()) {
  1986. ResourceMark rm(THREAD);
  1987. @@ -520,7 +641,10 @@ void LinkResolver::resolve_interface_method(methodHandle& resolved_method,
  1988. }
  1989. // lookup method in this interface or its super, java.lang.Object
  1990. - lookup_instance_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1991. + lookup_correct_method(resolved_method, resolved_klass, current_klass, method_name, method_signature, true, CHECK);
  1992. +
  1993. +
  1994. +
  1995. if (resolved_method.is_null() && !resolved_klass->oop_is_array()) {
  1996. // lookup method in all the super-interfaces
  1997. @@ -621,9 +745,14 @@ void LinkResolver::resolve_field(FieldAccessInfo& result, constantPoolHandle poo
  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, 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. @@ -631,7 +760,6 @@ void LinkResolver::resolve_field(FieldAccessInfo& result, constantPoolHandle poo
  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. @@ -643,7 +771,7 @@ void LinkResolver::resolve_field(FieldAccessInfo& result, constantPoolHandle poo
  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. @@ -848,7 +976,7 @@ void LinkResolver::resolve_virtual_call(CallInfo& result, Handle recv, KlassHand
  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. @@ -878,6 +1006,7 @@ void LinkResolver::runtime_resolve_virtual_method(CallInfo& result,
  2034. KlassHandle resolved_klass,
  2035. Handle recv,
  2036. KlassHandle recv_klass,
  2037. + KlassHandle current_klass,
  2038. bool check_null_and_abstract,
  2039. TRAPS) {
  2040. @@ -926,10 +1055,44 @@ void LinkResolver::runtime_resolve_virtual_method(CallInfo& result,
  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. - selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index));
  2045. +
  2046. + // (tw) The type of the virtual method call and the type of the receiver do not need to
  2047. + // have anything in common, as the receiver type could've been hotswapped.
  2048. + // Does not always work (method could be resolved with correct dynamic type and later
  2049. + // be called at the same place with a wrong dynamic type).
  2050. + // (tw) TODO: Need to handle the static type vs dynamic type issue more generally.
  2051. +
  2052. + // The vTable must be based on the view of the world of the resolved method
  2053. + klassOop method_holder = resolved_method->method_holder();
  2054. +
  2055. + if (method_holder->klass_part()->new_version() != NULL) {
  2056. + // We are executing in old code
  2057. + // FIXME: idubrov
  2058. + //TRACE_RC2("Calling a method in old code");
  2059. + while (method_holder->klass_part()->revision_number() < inst->revision_number()) {
  2060. + inst = (instanceKlass *)(inst->old_version()->klass_part());
  2061. + }
  2062. + }
  2063. +
  2064. + if (inst->is_subtype_of(method_holder)) {
  2065. + selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index));
  2066. + } else {
  2067. +
  2068. + tty->print_cr("Failure:");
  2069. + inst->as_klassOop()->print();
  2070. + inst->super()->print();
  2071. + juint off = inst->super_check_offset();
  2072. + klassOop sup = *(klassOop*)( (address)inst->as_klassOop() + off );
  2073. + sup->print();
  2074. + method_holder->print();
  2075. +
  2076. + bool b = inst->is_subtype_of(method_holder);
  2077. + 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!");
  2078. + }
  2079. }
  2080. }
  2081. +
  2082. // check if method exists
  2083. if (selected_method.is_null()) {
  2084. ResourceMark rm(THREAD);
  2085. diff --git a/src/share/vm/interpreter/linkResolver.hpp b/src/share/vm/interpreter/linkResolver.hpp
  2086. index dfd74f9..cf6e44a 100644
  2087. --- a/src/share/vm/interpreter/linkResolver.hpp
  2088. +++ b/src/share/vm/interpreter/linkResolver.hpp
  2089. @@ -110,7 +110,11 @@ class CallInfo: public LinkInfo {
  2090. // It does all necessary link-time checks & throws exceptions if necessary.
  2091. class LinkResolver: AllStatic {
  2092. - private:
  2093. +private:
  2094. + static void lookup_method (methodHandle& result, KlassHandle resolved_klass, Symbol* name, Symbol* signature, bool is_interface, KlassHandle current_klass, TRAPS);
  2095. + 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);
  2096. + static void lookup_correct_method (methodHandle& result, KlassHandle resolved_klass, KlassHandle current_klass, Symbol* name, Symbol* signature, bool is_interface, TRAPS);
  2097. + static void find_correct_resolved_klass (KlassHandle &resolved_klass, KlassHandle &current_klass);
  2098. static void lookup_method_in_klasses (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
  2099. static void lookup_instance_method_in_klasses (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
  2100. static void lookup_method_in_interfaces (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
  2101. @@ -133,7 +137,7 @@ class LinkResolver: AllStatic {
  2102. 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);
  2103. static void runtime_resolve_special_method (CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, KlassHandle current_klass, bool check_access, TRAPS);
  2104. - 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);
  2105. + 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);
  2106. 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);
  2107. static void check_field_accessability (KlassHandle ref_klass, KlassHandle resolved_klass, KlassHandle sel_klass, fieldDescriptor& fd, TRAPS);
  2108. diff --git a/src/share/vm/interpreter/templateTable.hpp b/src/share/vm/interpreter/templateTable.hpp
  2109. index 17e9f26..e77500f 100644
  2110. --- a/src/share/vm/interpreter/templateTable.hpp
  2111. +++ b/src/share/vm/interpreter/templateTable.hpp
  2112. @@ -329,8 +329,8 @@ class TemplateTable: AllStatic {
  2113. static void shouldnotreachhere();
  2114. // jvmti support
  2115. - static void jvmti_post_field_access(Register cache, Register index, bool is_static, bool has_tos);
  2116. - static void jvmti_post_field_mod(Register cache, Register index, bool is_static);
  2117. + static void jvmti_post_field_access(Register cache, Register index, int byte_no, bool is_static, bool has_tos);
  2118. + static void jvmti_post_field_mod(Register cache, Register index, int byte_no, bool is_static);
  2119. static void jvmti_post_fast_field_mod();
  2120. // debugging of TemplateGenerator
  2121. diff --git a/src/share/vm/memory/genMarkSweep.cpp b/src/share/vm/memory/genMarkSweep.cpp
  2122. index 76e18d8..6af7c14 100644
  2123. --- a/src/share/vm/memory/genMarkSweep.cpp
  2124. +++ b/src/share/vm/memory/genMarkSweep.cpp
  2125. @@ -421,6 +421,7 @@ void GenMarkSweep::mark_sweep_phase4() {
  2126. // in the same order in phase2, phase3 and phase4. We don't quite do that
  2127. // here (perm_gen first rather than last), so we tell the validate code
  2128. // to use a higher index (saved from phase2) when verifying perm_gen.
  2129. + assert(_rescued_oops == NULL, "must be empty before processing");
  2130. GenCollectedHeap* gch = GenCollectedHeap::heap();
  2131. Generation* pg = gch->perm_gen();
  2132. @@ -433,10 +434,14 @@ void GenMarkSweep::mark_sweep_phase4() {
  2133. VALIDATE_MARK_SWEEP_ONLY(reset_live_oop_tracking(false));
  2134. + MarkSweep::copy_rescued_objects_back();
  2135. +
  2136. GenCompactClosure blk;
  2137. gch->generation_iterate(&blk, true);
  2138. VALIDATE_MARK_SWEEP_ONLY(compaction_complete());
  2139. + MarkSweep::copy_rescued_objects_back();
  2140. +
  2141. pg->post_compact(); // Shared spaces verification.
  2142. }
  2143. diff --git a/src/share/vm/memory/permGen.cpp b/src/share/vm/memory/permGen.cpp
  2144. index 350f583..59faad1 100644
  2145. --- a/src/share/vm/memory/permGen.cpp
  2146. +++ b/src/share/vm/memory/permGen.cpp
  2147. @@ -57,7 +57,12 @@ HeapWord* PermGen::mem_allocate_in_gen(size_t size, Generation* gen) {
  2148. for (;;) {
  2149. {
  2150. - MutexLocker ml(Heap_lock);
  2151. + // (tw) Only lock when not at a safepoint (necessary to use the split verifier from the VmThread)
  2152. + Monitor *lock = Heap_lock;
  2153. + if (SafepointSynchronize::is_at_safepoint()) {
  2154. + lock = NULL;
  2155. + }
  2156. + MutexLockerEx ml(lock);
  2157. if ((obj = gen->allocate(size, false)) != NULL) {
  2158. return obj;
  2159. }
  2160. diff --git a/src/share/vm/memory/space.cpp b/src/share/vm/memory/space.cpp
  2161. index f97bc34..9b20d08 100644
  2162. --- a/src/share/vm/memory/space.cpp
  2163. +++ b/src/share/vm/memory/space.cpp
  2164. @@ -378,6 +378,31 @@ void CompactibleSpace::clear(bool mangle_space) {
  2165. _compaction_top = bottom();
  2166. }
  2167. +// (tw) Calculates the compact_top that will be used for placing the next object with the giving size on the heap.
  2168. +HeapWord* CompactibleSpace::forward_compact_top(size_t size,
  2169. +CompactPoint* cp, HeapWord* compact_top) {
  2170. + // First check if we should switch compaction space
  2171. + assert(this == cp->space, "'this' should be current compaction space.");
  2172. + size_t compaction_max_size = pointer_delta(end(), compact_top);
  2173. + while (size > compaction_max_size) {
  2174. + // switch to next compaction space
  2175. + cp->space->set_compaction_top(compact_top);
  2176. + cp->space = cp->space->next_compaction_space();
  2177. + if (cp->space == NULL) {
  2178. + cp->gen = GenCollectedHeap::heap()->prev_gen(cp->gen);
  2179. + assert(cp->gen != NULL, "compaction must succeed");
  2180. + cp->space = cp->gen->first_compaction_space();
  2181. + assert(cp->space != NULL, "generation must have a first compaction space");
  2182. + }
  2183. + compact_top = cp->space->bottom();
  2184. + cp->space->set_compaction_top(compact_top);
  2185. + cp->threshold = cp->space->initialize_threshold();
  2186. + compaction_max_size = pointer_delta(cp->space->end(), compact_top);
  2187. + }
  2188. +
  2189. + return compact_top;
  2190. +}
  2191. +
  2192. HeapWord* CompactibleSpace::forward(oop q, size_t size,
  2193. CompactPoint* cp, HeapWord* compact_top) {
  2194. // q is alive
  2195. @@ -401,7 +426,7 @@ HeapWord* CompactibleSpace::forward(oop q, size_t size,
  2196. }
  2197. // store the forwarding pointer into the mark word
  2198. - if ((HeapWord*)q != compact_top) {
  2199. + if ((HeapWord*)q != compact_top || (size_t)q->size() != size) {
  2200. q->forward_to(oop(compact_top));
  2201. assert(q->is_gc_marked(), "encoding the pointer should preserve the mark");
  2202. } else {
  2203. @@ -449,7 +474,208 @@ void CompactibleSpace::prepare_for_compaction(CompactPoint* cp) {
  2204. // Faster object search.
  2205. void ContiguousSpace::prepare_for_compaction(CompactPoint* cp) {
  2206. - SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size);
  2207. + if (!Universe::is_redefining_gc_run()) {
  2208. + SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size);
  2209. + return;
  2210. + }
  2211. +
  2212. + /* Compute the new addresses for the live objects and store it in the mark
  2213. + * Used by universe::mark_sweep_phase2()
  2214. + */
  2215. + HeapWord* compact_top; /* This is where we are currently compacting to. */
  2216. +
  2217. + /* We're sure to be here before any objects are compacted into this
  2218. + * space, so this is a good time to initialize this:
  2219. + */
  2220. + set_compaction_top(bottom());
  2221. +
  2222. + if (cp->space == NULL) {
  2223. + assert(cp->gen != NULL, "need a generation");
  2224. + assert(cp->threshold == NULL, "just checking");
  2225. + assert(cp->gen->first_compaction_space() == this, "just checking");
  2226. + cp->space = cp->gen->first_compaction_space();
  2227. + compact_top = cp->space->bottom();
  2228. + cp->space->set_compaction_top(compact_top);
  2229. + cp->threshold = cp->space->initialize_threshold();
  2230. + } else {
  2231. + compact_top = cp->space->compaction_top();
  2232. + }
  2233. +
  2234. + /* We allow some amount of garbage towards the bottom of the space, so
  2235. + * we don't start compacting before there is a significant gain to be made.
  2236. + * Occasionally, we want to ensure a full compaction, which is determined
  2237. + * by the MarkSweepAlwaysCompactCount parameter.
  2238. + */
  2239. + int invocations = SharedHeap::heap()->perm_gen()->stat_record()->invocations;
  2240. + bool skip_dead = (MarkSweepAlwaysCompactCount < 1)
  2241. + ||((invocations % MarkSweepAlwaysCompactCount) != 0);
  2242. +
  2243. + size_t allowed_deadspace = 0;
  2244. + if (skip_dead) {
  2245. + int ratio = (int)allowed_dead_ratio();
  2246. + allowed_deadspace = (capacity() * ratio / 100) / HeapWordSize;
  2247. + }
  2248. +
  2249. + HeapWord* q = bottom();
  2250. + HeapWord* t = end();
  2251. +
  2252. + HeapWord* end_of_live= q; /* One byte beyond the last byte of the last
  2253. + live object. */
  2254. + HeapWord* first_dead = end();/* The first dead object. */
  2255. + LiveRange* liveRange = NULL; /* The current live range, recorded in the
  2256. + first header of preceding free area. */
  2257. + _first_dead = first_dead;
  2258. +
  2259. + const intx interval = PrefetchScanIntervalInBytes;
  2260. +
  2261. + while (q < t) {
  2262. + assert(!block_is_obj(q) ||
  2263. + oop(q)->mark()->is_marked() || oop(q)->mark()->is_unlocked() ||
  2264. + oop(q)->mark()->has_bias_pattern(),
  2265. + "these are the only valid states during a mark sweep");
  2266. + if (block_is_obj(q) && oop(q)->is_gc_marked()) {
  2267. + /* prefetch beyond q */
  2268. + Prefetch::write(q, interval);
  2269. + /* size_t size = oop(q)->size(); changing this for cms for perm gen */
  2270. + size_t size = block_size(q);
  2271. +
  2272. + // DCEVM: begin
  2273. + //////////////////////////////////////////////////////////////////////////
  2274. + size_t forward_size = size;
  2275. +
  2276. + // Compute the forward sizes and leave out objects whose position could
  2277. + // possibly overlap other objects.
  2278. +
  2279. + // DCEVM: There is a new version of the class of q => different size
  2280. + if (oop(q)->blueprint()->new_version() != NULL && oop(q)->blueprint()->new_version()->klass_part()->update_information() != NULL) {
  2281. +
  2282. + size_t new_size = oop(q)->size_given_klass(oop(q)->blueprint()->new_version()->klass_part());
  2283. + assert(size != new_size || oop(q)->is_perm(), "instances without changed size have to be updated prior to GC run");
  2284. + forward_size = new_size;
  2285. + }
  2286. +
  2287. + compact_top = cp->space->forward_compact_top(forward_size, cp, compact_top);
  2288. +
  2289. + bool rescueing = false;
  2290. + if (rescueing = must_rescue(oop(q), oop(compact_top))) {
  2291. + if (MarkSweep::_rescued_oops == NULL) {
  2292. + MarkSweep::_rescued_oops = new GrowableArray<oop>(128);
  2293. + }
  2294. + // FIXME: idubrov
  2295. + //TRACE_RC5("rescue obj %d klass=%s", MarkSweep::_rescued_oops->length(), oop(q)->klass()->klass_part()->name()->as_C_string());
  2296. + MarkSweep::_rescued_oops->append(oop(q));
  2297. + } else {
  2298. + compact_top = cp->space->forward(oop(q), forward_size, cp, compact_top);
  2299. + }
  2300. +
  2301. + if ((size != forward_size || rescueing) && q < first_dead) {
  2302. + // (tw) This object moves => first_dead must be set to here!
  2303. + first_dead = q;
  2304. + }
  2305. + //////////////////////////////////////////////////////////////////////////
  2306. + q += size;
  2307. + end_of_live = q;
  2308. + } else {
  2309. + /* run over all the contiguous dead objects */
  2310. + HeapWord* end = q;
  2311. + do {
  2312. + /* prefetch beyond end */
  2313. + Prefetch::write(end, interval);
  2314. + end += block_size(end);
  2315. + } while (end < t && (!block_is_obj(end) || !oop(end)->is_gc_marked()));
  2316. +
  2317. + /* see if we might want to pretend this object is alive so that
  2318. + * we don't have to compact quite as often.
  2319. + */
  2320. + if (allowed_deadspace > 0 && q == compact_top) {
  2321. + size_t sz = pointer_delta(end, q);
  2322. + if (insert_deadspace(allowed_deadspace, q, sz)) {
  2323. + compact_top = cp->space->forward(oop(q), sz, cp, compact_top);
  2324. + q = end;
  2325. + end_of_live = end;
  2326. + continue;
  2327. + }
  2328. + }
  2329. +
  2330. + /* otherwise, it really is a free region. */
  2331. +
  2332. + /* for the previous LiveRange, record the end of the live objects. */
  2333. + if (liveRange) {
  2334. + liveRange->set_end(q);
  2335. + }
  2336. +
  2337. + /* record the current LiveRange object.
  2338. + * liveRange->start() is overlaid on the mark word.
  2339. + */
  2340. + liveRange = (LiveRange*)q;
  2341. + liveRange->set_start(end);
  2342. + liveRange->set_end(end);
  2343. +
  2344. + /* see if this is the first dead region. */
  2345. + if (q < first_dead) {
  2346. + first_dead = q;
  2347. + }
  2348. +
  2349. + /* move on to the next object */
  2350. + q = end;
  2351. + }
  2352. + }
  2353. +
  2354. + //////////////////////////////////////////////////////////////////////////
  2355. + // Compute the forwarding addresses for the objects that need to be
  2356. + // rescued.
  2357. + // TODO: empty the _rescued_oops after ALL spaces are compacted!
  2358. + if (MarkSweep::_rescued_oops != NULL) {
  2359. + // FIXME: idubrov
  2360. + //TRACE_RC2("Calculating new forward sizes for %d objects!", MarkSweep::_rescued_oops->length());
  2361. +
  2362. + for (int i=0; i<MarkSweep::_rescued_oops->length(); i++) {
  2363. + oop q = MarkSweep::_rescued_oops->at(i);
  2364. +
  2365. + /* size_t size = oop(q)->size(); changing this for cms for perm gen */
  2366. + size_t size = block_size((HeapWord*)q);
  2367. +
  2368. + size_t forward_size = size;
  2369. +
  2370. + // (tw) There is a new version of the class of q => different size
  2371. + if (oop(q)->blueprint()->new_version() != NULL) {
  2372. +
  2373. + size_t new_size = oop(q)->size_given_klass(oop(q)->blueprint()->new_version()->klass_part());
  2374. + assert(size != new_size || oop(q)->is_perm(), "instances without changed size have to be updated prior to GC run");
  2375. + forward_size = new_size;
  2376. + }
  2377. +
  2378. + compact_top = cp->space->forward(oop(q), forward_size, cp, compact_top);
  2379. + assert(compact_top <= t, "must not write over end of space!");
  2380. + }
  2381. + MarkSweep::_rescued_oops->clear();
  2382. + MarkSweep::_rescued_oops = NULL;
  2383. + }
  2384. + //////////////////////////////////////////////////////////////////////////
  2385. +
  2386. + assert(q == t, "just checking");
  2387. + if (liveRange != NULL) {
  2388. + liveRange->set_end(q);
  2389. + }
  2390. + _end_of_live = end_of_live;
  2391. + if (end_of_live < first_dead) {
  2392. + first_dead = end_of_live;
  2393. + }
  2394. + _first_dead = first_dead;
  2395. +
  2396. +// FIXME: idubrov
  2397. +// if (_first_dead > top()) {
  2398. +// _first_dead = top();
  2399. +// }
  2400. +//
  2401. +// if (_end_of_live > top()) {
  2402. +// _end_of_live = top();
  2403. +// }
  2404. + assert(_first_dead <= top(), "Must be smaller equal");
  2405. + assert(_end_of_live <= top(), "Must be smaller equal");
  2406. +
  2407. + /* save the compaction_top of the compaction space. */
  2408. + cp->space->set_compaction_top(compact_top);
  2409. }
  2410. void Space::adjust_pointers() {
  2411. @@ -490,17 +716,313 @@ void Space::adjust_pointers() {
  2412. assert(q == t, "just checking");
  2413. }
  2414. +
  2415. +#ifdef ASSERT
  2416. +
  2417. +int CompactibleSpace::space_index(oop obj) {
  2418. + GenCollectedHeap* heap = GenCollectedHeap::heap();
  2419. +
  2420. + if (heap->is_in_permanent(obj)) {
  2421. + return -1;
  2422. + }
  2423. +
  2424. + int index = 0;
  2425. + for (int i = heap->n_gens() - 1; i >= 0; i--) {
  2426. + Generation* gen = heap->get_gen(i);
  2427. + CompactibleSpace* space = gen->first_compaction_space();
  2428. + while (space != NULL) {
  2429. + if (space->is_in_reserved(obj)) {
  2430. + return index;
  2431. + }
  2432. + space = space->next_compaction_space();
  2433. + index++;
  2434. + }
  2435. + }
  2436. +
  2437. + tty->print_cr("could not compute space_index for %08xh", obj);
  2438. + index = 0;
  2439. + for (int i = heap->n_gens() - 1; i >= 0; i--) {
  2440. + Generation* gen = heap->get_gen(i);
  2441. + tty->print_cr(" generation %s: %08xh - %08xh", gen->name(), gen->reserved().start(), gen->reserved().end());
  2442. +
  2443. + CompactibleSpace* space = gen->first_compaction_space();
  2444. + while (space != NULL) {
  2445. + tty->print_cr(" %2d space %08xh - %08xh", index, space->bottom(), space->end());
  2446. + space = space->next_compaction_space();
  2447. + index++;
  2448. + }
  2449. + }
  2450. +
  2451. + ShouldNotReachHere();
  2452. + return 0;
  2453. +}
  2454. +#endif
  2455. +
  2456. +bool CompactibleSpace::must_rescue(oop old_obj, oop new_obj) {
  2457. +
  2458. + assert(is_in_reserved(old_obj), "old_obj must be in this space");
  2459. +
  2460. + if (old_obj->is_perm()) {
  2461. + // This object is in perm gen; check for invariant obj->klass() <= obj
  2462. + if (oop(old_obj)->blueprint()->new_version() != NULL) {
  2463. + return true;
  2464. + }
  2465. + }
  2466. +
  2467. + int size = old_obj->size();
  2468. + int original_size = size;
  2469. + if (oop(old_obj)->blueprint()->is_redefining()) {
  2470. + assert(oop(old_obj)->blueprint()->old_version() != NULL, "must not be null");
  2471. + original_size = oop(old_obj)->size_given_klass(oop(old_obj)->blueprint()->old_version()->klass_part());
  2472. + } else if (oop(old_obj)->blueprint()->new_version() != NULL) {
  2473. + size = oop(old_obj)->size_given_klass(oop(old_obj)->blueprint()->new_version()->klass_part());
  2474. + }
  2475. +
  2476. + bool normalComparison = (old_obj + original_size < new_obj + size);
  2477. +
  2478. + if (is_in_reserved(new_obj)) {
  2479. + // Old and new address are in same space, so just compare the address.
  2480. + // Must rescue if object moves towards the top of the space.
  2481. + assert(space_index(old_obj) == space_index(new_obj), "old_obj and new_obj must be in same space");
  2482. + return normalComparison;
  2483. +
  2484. + } else {
  2485. +
  2486. + assert(space_index(old_obj) != space_index(new_obj), "old_obj and new_obj must be in different spaces");
  2487. +
  2488. + Generation* tenured_gen = GenCollectedHeap::heap()->get_gen(1);
  2489. + if (tenured_gen->is_in_reserved(new_obj)) {
  2490. + // Must never rescue when moving from the new into the old generation.
  2491. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(old_obj), "old_obj must be in DefNewGeneration");
  2492. + assert(space_index(old_obj) > space_index(new_obj), "must be");
  2493. + return false;
  2494. +
  2495. + } else if (tenured_gen->is_in_reserved(old_obj)) {
  2496. + // Must always rescue when moving from the old into the new generation.
  2497. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(new_obj), "new_obj must be in DefNewGeneration");
  2498. + assert(space_index(old_obj) < space_index(new_obj), "must be");
  2499. + return true;
  2500. +
  2501. + } else {
  2502. + // In the new generation, eden is located before the from space, so a
  2503. + // simple pointer comparison is sufficient.
  2504. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(old_obj), "old_obj must be in DefNewGeneration");
  2505. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(new_obj), "new_obj must be in DefNewGeneration");
  2506. + assert((normalComparison) == (space_index(old_obj) < space_index(new_obj)), "slow and fast computation must yield same result");
  2507. + return normalComparison;
  2508. + }
  2509. + }
  2510. +}
  2511. +
  2512. +oop CompactibleSpace::rescue(oop old_obj) {
  2513. + assert(must_rescue(old_obj, old_obj->forwardee()), "do not call otherwise");
  2514. +
  2515. + int size = old_obj->size();
  2516. + oop rescued_obj = (oop)resource_allocate_bytes(size * HeapWordSize);
  2517. + Copy::aligned_disjoint_words((HeapWord*)old_obj, (HeapWord*)rescued_obj, size);
  2518. +
  2519. + if (MarkSweep::_rescued_oops == NULL) {
  2520. + MarkSweep::_rescued_oops = new GrowableArray<oop>(128);
  2521. + }
  2522. +
  2523. + MarkSweep::_rescued_oops->append(rescued_obj);
  2524. + return rescued_obj;
  2525. +}
  2526. +
  2527. void CompactibleSpace::adjust_pointers() {
  2528. // Check first is there is any work to do.
  2529. if (used() == 0) {
  2530. return; // Nothing to do.
  2531. }
  2532. -
  2533. - SCAN_AND_ADJUST_POINTERS(adjust_obj_size);
  2534. + /* adjust all the interior pointers to point at the new locations of objects
  2535. + * Used by MarkSweep::mark_sweep_phase3() */
  2536. +
  2537. + HeapWord* q = bottom();
  2538. + HeapWord* t = _end_of_live; /* Established by "prepare_for_compaction". */
  2539. +
  2540. + assert(_first_dead <= _end_of_live, "Stands to reason, no?");
  2541. +
  2542. + debug_only(HeapWord* prev_q = NULL);
  2543. + debug_only(HeapWord* prev_prev_q = NULL);
  2544. + debug_only(HeapWord* prev_prev_prev_q = NULL);
  2545. + if (q < t && _first_dead > q &&
  2546. + !oop(q)->is_gc_marked()) {
  2547. + /* we have a chunk of the space which hasn't moved and we've
  2548. + * reinitialized the mark word during the previous pass, so we can't
  2549. + * use is_gc_marked for the traversal. */
  2550. + HeapWord* end = _first_dead;
  2551. +
  2552. + while (q < end) {
  2553. + /* I originally tried to conjoin "block_start(q) == q" to the
  2554. + * assertion below, but that doesn't work, because you can't
  2555. + * accurately traverse previous objects to get to the current one
  2556. + * after their pointers (including pointers into permGen) have been
  2557. + * updated, until the actual compaction is done. dld, 4/00 */
  2558. + assert(block_is_obj(q),
  2559. + "should be at block boundaries, and should be looking at objs");
  2560. +
  2561. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::track_interior_pointers(oop(q)));
  2562. +
  2563. + /* point all the oops to the new location */
  2564. + size_t size = oop(q)->adjust_pointers();
  2565. + size = adjust_obj_size(size);
  2566. +
  2567. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::check_interior_pointers());
  2568. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::validate_live_oop(oop(q), size));
  2569. +
  2570. + debug_only(prev_prev_prev_q = prev_prev_q);
  2571. + debug_only(prev_prev_q = prev_q);
  2572. + debug_only(prev_q = q);
  2573. + q += size;
  2574. + }
  2575. +
  2576. + // (tw) first_dead can be live object!
  2577. + q = _first_dead;
  2578. +
  2579. +// if (_first_dead == t) {
  2580. +// q = t;
  2581. +// } else {
  2582. +// /* $$$ This is funky. Using this to read the previously written
  2583. +// * LiveRange. See also use below. */
  2584. +// q = (HeapWord*)oop(_first_dead)->mark()->decode_pointer();
  2585. +// }
  2586. + }
  2587. +
  2588. + const intx interval = PrefetchScanIntervalInBytes;
  2589. +
  2590. + debug_only(prev_q = NULL);
  2591. + debug_only(prev_prev_q = NULL);
  2592. + debug_only(prev_prev_prev_q = NULL);
  2593. + while (q < t) {
  2594. + /* prefetch beyond q */
  2595. + Prefetch::write(q, interval);
  2596. + if (oop(q)->is_gc_marked()) {
  2597. + /* q is alive */
  2598. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::track_interior_pointers(oop(q)));
  2599. + /* point all the oops to the new location */
  2600. + size_t size = oop(q)->adjust_pointers();
  2601. + size = adjust_obj_size(size);
  2602. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::check_interior_pointers());
  2603. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::validate_live_oop(oop(q), size));
  2604. + debug_only(prev_prev_prev_q = prev_prev_q);
  2605. + debug_only(prev_prev_q = prev_q);
  2606. + debug_only(prev_q = q);
  2607. + q += size;
  2608. + } else {
  2609. + /* q is not a live object, so its mark should point at the next
  2610. + * live object */
  2611. + debug_only(prev_prev_prev_q = prev_prev_q);
  2612. + debug_only(prev_prev_q = prev_q);
  2613. + debug_only(prev_q = q);
  2614. + q = (HeapWord*) oop(q)->mark()->decode_pointer();
  2615. + assert(q > prev_q, "we should be moving forward through memory");
  2616. + }
  2617. + }
  2618. +
  2619. + assert(q == t, "just checking");
  2620. }
  2621. void CompactibleSpace::compact() {
  2622. - SCAN_AND_COMPACT(obj_size);
  2623. +
  2624. + if(!Universe::is_redefining_gc_run()) {
  2625. + SCAN_AND_COMPACT(obj_size);
  2626. + return;
  2627. + }
  2628. +
  2629. + /* Copy all live objects to their new location
  2630. + * Used by MarkSweep::mark_sweep_phase4() */
  2631. +
  2632. + HeapWord* q = bottom();
  2633. + HeapWord* const t = _end_of_live;
  2634. + debug_only(HeapWord* prev_q = NULL);
  2635. +
  2636. + if (q < t && _first_dead > q &&
  2637. + !oop(q)->is_gc_marked()) {
  2638. + debug_only(
  2639. + /* we have a chunk of the space which hasn't moved and we've reinitialized
  2640. + * the mark word during the previous pass, so we can't use is_gc_marked for
  2641. + * the traversal. */
  2642. + HeapWord* const end = _first_dead;
  2643. +
  2644. + while (q < end) {
  2645. + size_t size = obj_size(q); // FIXME: idubrov oop(q)->size();
  2646. + assert(!oop(q)->is_gc_marked(),
  2647. + "should be unmarked (special dense prefix handling)");
  2648. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::live_oop_moved_to(q, size, q));
  2649. + debug_only(prev_q = q);
  2650. + q += size;
  2651. + }
  2652. + ) /* debug_only */
  2653. + // (tw) first_dead can be live object!
  2654. + q = _first_dead;
  2655. +
  2656. + //if (_first_dead == t) {
  2657. + // q = t;
  2658. + //} else {
  2659. + ///* $$$ Funky */
  2660. + //q = (HeapWord*) oop(_first_dead)->mark()->decode_pointer();
  2661. + //}
  2662. + }
  2663. +
  2664. + const intx scan_interval = PrefetchScanIntervalInBytes;
  2665. + const intx copy_interval = PrefetchCopyIntervalInBytes;
  2666. + while (q < t) {
  2667. + if (!oop(q)->is_gc_marked()) {
  2668. + /* mark is pointer to next marked oop */
  2669. + debug_only(prev_q = q);
  2670. + q = (HeapWord*) oop(q)->mark()->decode_pointer();
  2671. + assert(q > prev_q, "we should be moving forward through memory");
  2672. + } else {
  2673. + /* prefetch beyond q */
  2674. + Prefetch::read(q, scan_interval);
  2675. +
  2676. + /* size and destination */
  2677. + size_t size = obj_size(q);
  2678. + HeapWord* compaction_top = (HeapWord*)oop(q)->forwardee();
  2679. +
  2680. + if (must_rescue(oop(q), oop(q)->forwardee())) {
  2681. + oop dest_obj = rescue(oop(q));
  2682. + debug_only(Copy::fill_to_words(q, size, 0));
  2683. + } else {
  2684. +
  2685. + /* prefetch beyond compaction_top */
  2686. + Prefetch::write(compaction_top, copy_interval);
  2687. +
  2688. + /* copy object and reinit its mark */
  2689. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::live_oop_moved_to(q, size,
  2690. + compaction_top));
  2691. + assert(q != compaction_top || oop(q)->blueprint()->new_version() != NULL, "everything in this pass should be moving");
  2692. +
  2693. + if (oop(q)->blueprint()->new_version() != NULL) {
  2694. + MarkSweep::update_fields(oop(q), oop(compaction_top));
  2695. + } else {
  2696. + Copy::aligned_conjoint_words(q, compaction_top, size);
  2697. + }
  2698. + oop(compaction_top)->init_mark();
  2699. + assert(oop(compaction_top)->klass() != NULL, "should have a class");
  2700. + }
  2701. +
  2702. + debug_only(prev_q = q);
  2703. + q += size;
  2704. + }
  2705. + }
  2706. +
  2707. + /* Let's remember if we were empty before we did the compaction. */
  2708. + bool was_empty = used_region().is_empty();
  2709. + /* Reset space after compaction is complete */
  2710. + reset_after_compaction();
  2711. + /* We do this clear, below, since it has overloaded meanings for some */
  2712. + /* space subtypes. For example, OffsetTableContigSpace's that were */
  2713. + /* compacted into will have had their offset table thresholds updated */
  2714. + /* continuously, but those that weren't need to have their thresholds */
  2715. + /* re-initialized. Also mangles unused area for debugging. */
  2716. + if (used_region().is_empty()) {
  2717. + if (!was_empty) clear(SpaceDecorator::Mangle);
  2718. + } else {
  2719. + if (ZapUnusedHeapArea) mangle_unused_area();
  2720. + }
  2721. +
  2722. + //SCAN_AND_COMPACT(obj_size);
  2723. }
  2724. void Space::print_short() const { print_short_on(tty); }
  2725. diff --git a/src/share/vm/memory/space.hpp b/src/share/vm/memory/space.hpp
  2726. index ef2f2c6..b54d470 100644
  2727. --- a/src/share/vm/memory/space.hpp
  2728. +++ b/src/share/vm/memory/space.hpp
  2729. @@ -445,6 +445,9 @@ public:
  2730. // indicates when the next such action should be taken.
  2731. virtual void prepare_for_compaction(CompactPoint* cp);
  2732. // MarkSweep support phase3
  2733. + DEBUG_ONLY(int space_index(oop obj));
  2734. + bool must_rescue(oop old_obj, oop new_obj);
  2735. + oop rescue(oop old_obj);
  2736. virtual void adjust_pointers();
  2737. // MarkSweep support phase4
  2738. virtual void compact();
  2739. @@ -475,6 +478,10 @@ public:
  2740. virtual HeapWord* forward(oop q, size_t size, CompactPoint* cp,
  2741. HeapWord* compact_top);
  2742. + // (tw)
  2743. + virtual HeapWord* forward_compact_top(size_t size, CompactPoint* cp,
  2744. + HeapWord* compact_top);
  2745. +
  2746. // Return a size with adjusments as required of the space.
  2747. virtual size_t adjust_object_size_v(size_t size) const { return size; }
  2748. diff --git a/src/share/vm/memory/universe.cpp b/src/share/vm/memory/universe.cpp
  2749. index 4030d9d..da9a186 100644
  2750. --- a/src/share/vm/memory/universe.cpp
  2751. +++ b/src/share/vm/memory/universe.cpp
  2752. @@ -100,6 +100,8 @@
  2753. #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
  2754. #endif
  2755. +bool Universe::_is_redefining_gc_run = false;
  2756. +
  2757. // Known objects
  2758. klassOop Universe::_boolArrayKlassObj = NULL;
  2759. klassOop Universe::_byteArrayKlassObj = NULL;
  2760. @@ -204,6 +206,38 @@ void Universe::system_classes_do(void f(klassOop)) {
  2761. f(systemObjArrayKlassObj());
  2762. }
  2763. +// DCEVM: This method should iterate all pointers that are not within heap objects.
  2764. +void Universe::root_oops_do(OopClosure *oopClosure) {
  2765. +
  2766. + class AlwaysTrueClosure: public BoolObjectClosure {
  2767. + public:
  2768. + void do_object(oop p) { ShouldNotReachHere(); }
  2769. + bool do_object_b(oop p) { return true; }
  2770. + };
  2771. + AlwaysTrueClosure always_true;
  2772. +
  2773. + // General strong roots
  2774. + Universe::oops_do(oopClosure);
  2775. + JNIHandles::oops_do(oopClosure);
  2776. + Threads::oops_do(oopClosure, NULL);
  2777. + ObjectSynchronizer::oops_do(oopClosure);
  2778. + FlatProfiler::oops_do(oopClosure);
  2779. + //Management::oops_do(oopClosure); // DCEVM: TODO: Check if this is correct?
  2780. + JvmtiExport::oops_do(oopClosure);
  2781. + // SO_AllClasses
  2782. + SystemDictionary::oops_do(oopClosure);
  2783. +
  2784. + // Now adjust pointers in remaining weak roots. (All of which should
  2785. + // have been cleared if they pointed to non-surviving objects.)
  2786. + // Global (weak) JNI handles
  2787. + JNIHandles::weak_oops_do(&always_true, oopClosure);
  2788. +
  2789. + CodeCache::oops_do(oopClosure);
  2790. + StringTable::oops_do(oopClosure);
  2791. + //ref_processor()->weak_oops_do(&oopClosure); // DCEVM: TODO: Check if this is correct?
  2792. + //PSScavenge::reference_processor()->weak_oops_do(&oopClosure); // DCEVM: TODO: Check if this is correct?
  2793. +}
  2794. +
  2795. void Universe::oops_do(OopClosure* f, bool do_all) {
  2796. f->do_oop((oop*) &_int_mirror);
  2797. diff --git a/src/share/vm/memory/universe.hpp b/src/share/vm/memory/universe.hpp
  2798. index 50fcb62..afb6b33 100644
  2799. --- a/src/share/vm/memory/universe.hpp
  2800. +++ b/src/share/vm/memory/universe.hpp
  2801. @@ -127,6 +127,8 @@ class Universe: AllStatic {
  2802. friend class SystemDictionary;
  2803. friend class VMStructs;
  2804. friend class CompactingPermGenGen;
  2805. + friend class Space;
  2806. + friend class ContiguousSpace;
  2807. friend class VM_PopulateDumpSharedSpace;
  2808. friend jint universe_init();
  2809. @@ -258,7 +260,18 @@ class Universe: AllStatic {
  2810. static void compute_verify_oop_data();
  2811. + static bool _is_redefining_gc_run;
  2812. +
  2813. public:
  2814. +
  2815. + static bool is_redefining_gc_run() {
  2816. + return _is_redefining_gc_run;
  2817. + }
  2818. +
  2819. + static void set_redefining_gc_run(bool b) {
  2820. + _is_redefining_gc_run = b;
  2821. + }
  2822. +
  2823. // Known classes in the VM
  2824. static klassOop boolArrayKlassObj() { return _boolArrayKlassObj; }
  2825. static klassOop byteArrayKlassObj() { return _byteArrayKlassObj; }
  2826. @@ -403,6 +416,8 @@ class Universe: AllStatic {
  2827. // Iteration
  2828. + static void root_oops_do(OopClosure *f);
  2829. +
  2830. // Apply "f" to the addresses of all the direct heap pointers maintained
  2831. // as static fields of "Universe".
  2832. static void oops_do(OopClosure* f, bool do_all = false);
  2833. @@ -419,6 +434,7 @@ class Universe: AllStatic {
  2834. // Debugging
  2835. static bool verify_in_progress() { return _verify_in_progress; }
  2836. + static void set_verify_in_progress(bool b) { _verify_in_progress = b; }
  2837. static void verify(VerifyOption option, const char* prefix, bool silent = VerifySilently);
  2838. static void verify(const char* prefix, bool silent = VerifySilently) {
  2839. verify(VerifyOption_Default, prefix, silent);
  2840. diff --git a/src/share/vm/oops/arrayKlass.cpp b/src/share/vm/oops/arrayKlass.cpp
  2841. index 16142b8..921e546 100644
  2842. --- a/src/share/vm/oops/arrayKlass.cpp
  2843. +++ b/src/share/vm/oops/arrayKlass.cpp
  2844. @@ -136,9 +136,9 @@ objArrayOop arrayKlass::compute_secondary_supers(int num_extra_slots, TRAPS) {
  2845. bool arrayKlass::compute_is_subtype_of(klassOop k) {
  2846. // An array is a subtype of Serializable, Clonable, and Object
  2847. - return k == SystemDictionary::Object_klass()
  2848. - || k == SystemDictionary::Cloneable_klass()
  2849. - || k == SystemDictionary::Serializable_klass();
  2850. + return k->klass_part()->newest_version() == SystemDictionary::Object_klass()->klass_part()->newest_version()
  2851. + || k->klass_part()->newest_version() == SystemDictionary::Cloneable_klass()->klass_part()->newest_version()
  2852. + || k->klass_part()->newest_version() == SystemDictionary::Serializable_klass()->klass_part()->newest_version();
  2853. }
  2854. diff --git a/src/share/vm/oops/constMethodKlass.cpp b/src/share/vm/oops/constMethodKlass.cpp
  2855. index e74811f..be3fe7d 100644
  2856. --- a/src/share/vm/oops/constMethodKlass.cpp
  2857. +++ b/src/share/vm/oops/constMethodKlass.cpp
  2858. @@ -102,6 +102,7 @@ void constMethodKlass::oop_follow_contents(oop obj) {
  2859. constMethodOop cm = constMethodOop(obj);
  2860. MarkSweep::mark_and_push(cm->adr_constants());
  2861. MarkSweep::mark_and_push(cm->adr_stackmap_data());
  2862. + MarkSweep::mark_and_push(cm->adr_code_section_table());
  2863. // Performance tweak: We skip iterating over the klass pointer since we
  2864. // know that Universe::constMethodKlassObj never moves.
  2865. }
  2866. @@ -113,6 +114,7 @@ void constMethodKlass::oop_follow_contents(ParCompactionManager* cm,
  2867. constMethodOop cm_oop = constMethodOop(obj);
  2868. PSParallelCompact::mark_and_push(cm, cm_oop->adr_constants());
  2869. PSParallelCompact::mark_and_push(cm, cm_oop->adr_stackmap_data());
  2870. + PSParallelCompact::mark_and_push(cm, cm_oop->adr_code_section_table());
  2871. // Performance tweak: We skip iterating over the klass pointer since we
  2872. // know that Universe::constMethodKlassObj never moves.
  2873. }
  2874. @@ -123,6 +125,7 @@ int constMethodKlass::oop_oop_iterate(oop obj, OopClosure* blk) {
  2875. constMethodOop cm = constMethodOop(obj);
  2876. blk->do_oop(cm->adr_constants());
  2877. blk->do_oop(cm->adr_stackmap_data());
  2878. + blk->do_oop(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. @@ -138,6 +141,8 @@ int constMethodKlass::oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr)
  2883. if (mr.contains(adr)) blk->do_oop(adr);
  2884. adr = cm->adr_stackmap_data();
  2885. if (mr.contains(adr)) blk->do_oop(adr);
  2886. + adr = cm->adr_code_section_table();
  2887. + if (mr.contains(adr)) blk->do_oop(adr);
  2888. // Get size before changing pointers.
  2889. // Don't call size() or oop_size() since that is a virtual call.
  2890. int size = cm->object_size();
  2891. @@ -152,6 +157,7 @@ int constMethodKlass::oop_adjust_pointers(oop obj) {
  2892. constMethodOop cm = constMethodOop(obj);
  2893. MarkSweep::adjust_pointer(cm->adr_constants());
  2894. MarkSweep::adjust_pointer(cm->adr_stackmap_data());
  2895. + MarkSweep::adjust_pointer(cm->adr_code_section_table());
  2896. // Get size before changing pointers.
  2897. // Don't call size() or oop_size() since that is a virtual call.
  2898. int size = cm->object_size();
  2899. diff --git a/src/share/vm/oops/constMethodOop.hpp b/src/share/vm/oops/constMethodOop.hpp
  2900. index 549192b..5cea5c4 100644
  2901. --- a/src/share/vm/oops/constMethodOop.hpp
  2902. +++ b/src/share/vm/oops/constMethodOop.hpp
  2903. @@ -129,7 +129,7 @@ private:
  2904. public:
  2905. oop* oop_block_beg() const { return adr_constants(); }
  2906. - oop* oop_block_end() const { return adr_stackmap_data() + 1; }
  2907. + oop* oop_block_end() const { return adr_code_section_table() + 1; }
  2908. private:
  2909. //
  2910. @@ -141,6 +141,9 @@ private:
  2911. // Raw stackmap data for the method
  2912. typeArrayOop _stackmap_data;
  2913. + // (tw) Table mapping code sections for method forward points.
  2914. + typeArrayOop _code_section_table;
  2915. +
  2916. //
  2917. // End of the oop block.
  2918. //
  2919. @@ -195,6 +198,28 @@ public:
  2920. }
  2921. bool has_stackmap_table() const { return _stackmap_data != NULL; }
  2922. + // code section table
  2923. + typeArrayOop code_section_table() const { return _code_section_table; }
  2924. + void set_code_section_table(typeArrayOop e) { oop_store_without_check((oop*) &_code_section_table, (oop) e); }
  2925. + bool has_code_section_table() const { return code_section_table() != NULL && code_section_table()->length() > 0; }
  2926. + static const int ValuesPerCodeSectionEntry = 3;
  2927. + int code_section_entries() const {
  2928. + if (!has_code_section_table()) return 0;
  2929. + return _code_section_table->length() / ValuesPerCodeSectionEntry;
  2930. + }
  2931. +
  2932. + int code_section_new_index_at(int index) const {
  2933. + return _code_section_table->short_at(index * ValuesPerCodeSectionEntry);
  2934. + }
  2935. +
  2936. + int code_section_original_index_at(int index) const {
  2937. + return _code_section_table->short_at(index * ValuesPerCodeSectionEntry + 1);
  2938. + }
  2939. +
  2940. + int code_section_length_at(int index) const {
  2941. + return _code_section_table->short_at(index * ValuesPerCodeSectionEntry + 2);
  2942. + }
  2943. +
  2944. void init_fingerprint() {
  2945. const uint64_t initval = CONST64(0x8000000000000000);
  2946. _fingerprint = initval;
  2947. @@ -301,6 +326,7 @@ public:
  2948. // Garbage collection support
  2949. oop* adr_constants() const { return (oop*)&_constants; }
  2950. oop* adr_stackmap_data() const { return (oop*)&_stackmap_data; }
  2951. + oop* adr_code_section_table() const { return (oop*)&_code_section_table; }
  2952. bool is_conc_safe() { return _is_conc_safe; }
  2953. void set_is_conc_safe(bool v) { _is_conc_safe = v; }
  2954. diff --git a/src/share/vm/oops/cpCacheOop.cpp b/src/share/vm/oops/cpCacheOop.cpp
  2955. index ad62921..f39f202 100644
  2956. --- a/src/share/vm/oops/cpCacheOop.cpp
  2957. +++ b/src/share/vm/oops/cpCacheOop.cpp
  2958. @@ -37,9 +37,15 @@
  2959. // Implememtation of ConstantPoolCacheEntry
  2960. +void ConstantPoolCacheEntry::copy_from(ConstantPoolCacheEntry *other) {
  2961. + _flags = other->_flags; // flags
  2962. +}
  2963. +
  2964. void ConstantPoolCacheEntry::initialize_entry(int index) {
  2965. assert(0 < index && index < 0x10000, "sanity check");
  2966. _indices = index;
  2967. + _f1 = NULL;
  2968. + _f2 = 0;
  2969. assert(constant_pool_index() == index, "");
  2970. }
  2971. @@ -162,7 +168,8 @@ void ConstantPoolCacheEntry::set_method(Bytecodes::Code invoke_code,
  2972. int vtable_index) {
  2973. assert(!is_secondary_entry(), "");
  2974. assert(method->interpreter_entry() != NULL, "should have been set at this point");
  2975. - assert(!method->is_obsolete(), "attempt to write obsolete method to cpCache");
  2976. + // (tw) No longer valid assert
  2977. + //assert(!method->is_obsolete(), "attempt to write obsolete method to cpCache");
  2978. int byte_no = -1;
  2979. bool change_to_virtual = false;
  2980. @@ -183,6 +190,7 @@ void ConstantPoolCacheEntry::set_method(Bytecodes::Code invoke_code,
  2981. set_method_flags(as_TosState(method->result_type()),
  2982. ( 1 << is_vfinal_shift) |
  2983. ((method->is_final_method() ? 1 : 0) << is_final_shift) |
  2984. + ((method->is_old() ? 1 : 0) << is_old_method_shift) |
  2985. ((change_to_virtual ? 1 : 0) << is_forced_virtual_shift),
  2986. method()->size_of_parameters());
  2987. set_f2_as_vfinal_method(method());
  2988. @@ -190,9 +198,13 @@ void ConstantPoolCacheEntry::set_method(Bytecodes::Code invoke_code,
  2989. assert(vtable_index >= 0, "valid index");
  2990. assert(!method->is_final_method(), "sanity");
  2991. set_method_flags(as_TosState(method->result_type()),
  2992. + ((method->is_old() ? 1 : 0) << is_old_method_shift) |
  2993. ((change_to_virtual ? 1 : 0) << is_forced_virtual_shift),
  2994. method()->size_of_parameters());
  2995. set_f2(vtable_index);
  2996. +
  2997. + // (tw) save method holder in f1 for virtual calls
  2998. + set_f1(method());
  2999. }
  3000. byte_no = 2;
  3001. break;
  3002. @@ -206,7 +218,8 @@ void ConstantPoolCacheEntry::set_method(Bytecodes::Code invoke_code,
  3003. // Once is_vfinal is set, it must stay that way, lest we get a dangling oop.
  3004. set_method_flags(as_TosState(method->result_type()),
  3005. ((is_vfinal() ? 1 : 0) << is_vfinal_shift) |
  3006. - ((method->is_final_method() ? 1 : 0) << is_final_shift),
  3007. + ((method->is_final_method() ? 1 : 0) << is_final_shift) |
  3008. + ((method->is_old() ? 1 : 0) << is_old_method_shift),
  3009. method()->size_of_parameters());
  3010. set_f1(method());
  3011. byte_no = 1;
  3012. @@ -259,7 +272,7 @@ void ConstantPoolCacheEntry::set_interface_call(methodHandle method, int index)
  3013. set_f1(interf);
  3014. set_f2(index);
  3015. set_method_flags(as_TosState(method->result_type()),
  3016. - 0, // no option bits
  3017. + ((method->is_old() ? 1 : 0) << is_old_method_shift),
  3018. method()->size_of_parameters());
  3019. set_bytecode_1(Bytecodes::_invokeinterface);
  3020. }
  3021. @@ -520,27 +533,12 @@ void ConstantPoolCacheEntry::update_pointers() {
  3022. // If this constantPoolCacheEntry refers to old_method then update it
  3023. // to refer to new_method.
  3024. bool ConstantPoolCacheEntry::adjust_method_entry(methodOop old_method,
  3025. - methodOop new_method, bool * trace_name_printed) {
  3026. + methodOop new_method) {
  3027. if (is_vfinal()) {
  3028. - // virtual and final so _f2 contains method ptr instead of vtable index
  3029. - if (f2_as_vfinal_method() == old_method) {
  3030. - // match old_method so need an update
  3031. - // NOTE: can't use set_f2_as_vfinal_method as it asserts on different values
  3032. - _f2 = (intptr_t)new_method;
  3033. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  3034. - if (!(*trace_name_printed)) {
  3035. - // RC_TRACE_MESG macro has an embedded ResourceMark
  3036. - RC_TRACE_MESG(("adjust: name=%s",
  3037. - Klass::cast(old_method->method_holder())->external_name()));
  3038. - *trace_name_printed = true;
  3039. - }
  3040. - // RC_TRACE macro has an embedded ResourceMark
  3041. - RC_TRACE(0x00400000, ("cpc vf-entry update: %s(%s)",
  3042. - new_method->name()->as_C_string(),
  3043. - new_method->signature()->as_C_string()));
  3044. - }
  3045. -
  3046. + // virtual and final so f2() contains method ptr instead of vtable index
  3047. + if (f2_as_vfinal_method() != NULL && f2_as_vfinal_method()->method_holder()->klass_part()->new_version()) {
  3048. + initialize_entry(constant_pool_index());
  3049. return true;
  3050. }
  3051. @@ -548,84 +546,27 @@ bool ConstantPoolCacheEntry::adjust_method_entry(methodOop old_method,
  3052. return false;
  3053. }
  3054. - if ((oop)_f1 == NULL) {
  3055. - // NULL f1() means this is a virtual entry so bail out
  3056. - // We are assuming that the vtable index does not need change.
  3057. + // (tw) check how to update interface methods!
  3058. + if (bytecode_1() == Bytecodes::_invokevirtual || bytecode_2() == Bytecodes::_invokevirtual) {
  3059. +
  3060. + if(f1_as_method()->method_holder()->klass_part()->new_version()) {
  3061. + initialize_entry(constant_pool_index());
  3062. + return true;
  3063. + }
  3064. +
  3065. return false;
  3066. }
  3067. if ((oop)_f1 == old_method) {
  3068. _f1 = new_method;
  3069. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  3070. - if (!(*trace_name_printed)) {
  3071. - // RC_TRACE_MESG macro has an embedded ResourceMark
  3072. - RC_TRACE_MESG(("adjust: name=%s",
  3073. - Klass::cast(old_method->method_holder())->external_name()));
  3074. - *trace_name_printed = true;
  3075. - }
  3076. - // RC_TRACE macro has an embedded ResourceMark
  3077. - RC_TRACE(0x00400000, ("cpc entry update: %s(%s)",
  3078. - new_method->name()->as_C_string(),
  3079. - new_method->signature()->as_C_string()));
  3080. - }
  3081. -
  3082. return true;
  3083. + } else if(_f1 != NULL && (bytecode_1() != Bytecodes::_invokeinterface && f1_as_method()->method_holder()->klass_part()->new_version())) {
  3084. + initialize_entry(constant_pool_index());
  3085. }
  3086. return false;
  3087. }
  3088. -// a constant pool cache entry should never contain old or obsolete methods
  3089. -bool ConstantPoolCacheEntry::check_no_old_or_obsolete_entries() {
  3090. - if (is_vfinal()) {
  3091. - // virtual and final so _f2 contains method ptr instead of vtable index
  3092. - methodOop m = (methodOop)_f2;
  3093. - // Return false if _f2 refers to an old or an obsolete method.
  3094. - // _f2 == NULL || !m->is_method() are just as unexpected here.
  3095. - return (m != NULL && m->is_method() && !m->is_old() && !m->is_obsolete());
  3096. - } else if ((oop)_f1 == NULL || !((oop)_f1)->is_method()) {
  3097. - // _f1 == NULL || !_f1->is_method() are OK here
  3098. - return true;
  3099. - }
  3100. -
  3101. - methodOop m = (methodOop)_f1;
  3102. - // return false if _f1 refers to an old or an obsolete method
  3103. - return (!m->is_old() && !m->is_obsolete());
  3104. -}
  3105. -
  3106. -bool ConstantPoolCacheEntry::is_interesting_method_entry(klassOop k) {
  3107. - if (!is_method_entry()) {
  3108. - // not a method entry so not interesting by default
  3109. - return false;
  3110. - }
  3111. -
  3112. - methodOop m = NULL;
  3113. - if (is_vfinal()) {
  3114. - // virtual and final so _f2 contains method ptr instead of vtable index
  3115. - m = f2_as_vfinal_method();
  3116. - } else if (is_f1_null()) {
  3117. - // NULL _f1 means this is a virtual entry so also not interesting
  3118. - return false;
  3119. - } else {
  3120. - oop f1 = _f1; // _f1 is volatile
  3121. - if (!f1->is_method()) {
  3122. - // _f1 can also contain a klassOop for an interface
  3123. - return false;
  3124. - }
  3125. - m = f1_as_method();
  3126. - }
  3127. -
  3128. - assert(m != NULL && m->is_method(), "sanity check");
  3129. - if (m == NULL || !m->is_method() || (k != NULL && m->method_holder() != k)) {
  3130. - // robustness for above sanity checks or method is not in
  3131. - // the interesting class
  3132. - return false;
  3133. - }
  3134. -
  3135. - // the method is in the interesting class so the entry is interesting
  3136. - return true;
  3137. -}
  3138. -
  3139. void ConstantPoolCacheEntry::print(outputStream* st, int index) const {
  3140. // print separator
  3141. if (index == 0) st->print_cr(" -------------");
  3142. @@ -663,60 +604,18 @@ void constantPoolCacheOopDesc::initialize(intArray& inverse_index_map) {
  3143. }
  3144. }
  3145. -// RedefineClasses() API support:
  3146. -// If any entry of this constantPoolCache points to any of
  3147. -// old_methods, replace it with the corresponding new_method.
  3148. -void constantPoolCacheOopDesc::adjust_method_entries(methodOop* old_methods, methodOop* new_methods,
  3149. - int methods_length, bool * trace_name_printed) {
  3150. -
  3151. - if (methods_length == 0) {
  3152. - // nothing to do if there are no methods
  3153. - return;
  3154. - }
  3155. -
  3156. - // get shorthand for the interesting class
  3157. - klassOop old_holder = old_methods[0]->method_holder();
  3158. +void constantPoolCacheOopDesc::adjust_entries(methodOop* old_methods, methodOop* new_methods,
  3159. + int methods_length) {
  3160. for (int i = 0; i < length(); i++) {
  3161. - if (!entry_at(i)->is_interesting_method_entry(old_holder)) {
  3162. - // skip uninteresting methods
  3163. - continue;
  3164. - }
  3165. -
  3166. - // The constantPoolCache contains entries for several different
  3167. - // things, but we only care about methods. In fact, we only care
  3168. - // about methods in the same class as the one that contains the
  3169. - // old_methods. At this point, we have an interesting entry.
  3170. -
  3171. - for (int j = 0; j < methods_length; j++) {
  3172. - methodOop old_method = old_methods[j];
  3173. - methodOop new_method = new_methods[j];
  3174. -
  3175. - if (entry_at(i)->adjust_method_entry(old_method, new_method,
  3176. - trace_name_printed)) {
  3177. - // current old_method matched this entry and we updated it so
  3178. - // break out and get to the next interesting entry if there one
  3179. - break;
  3180. - }
  3181. + if (entry_at(i)->is_field_entry()) {
  3182. + // (tw) TODO: Update only field offsets and modify only constant pool entries that
  3183. + // point to changed fields
  3184. + entry_at(i)->initialize_entry(entry_at(i)->constant_pool_index());
  3185. + } else if(entry_at(i)->is_method_entry()) {
  3186. + entry_at(i)->adjust_method_entry(NULL, NULL);
  3187. }
  3188. }
  3189. }
  3190. -// the constant pool cache should never contain old or obsolete methods
  3191. -bool constantPoolCacheOopDesc::check_no_old_or_obsolete_entries() {
  3192. - for (int i = 1; i < length(); i++) {
  3193. - if (entry_at(i)->is_interesting_method_entry(NULL) &&
  3194. - !entry_at(i)->check_no_old_or_obsolete_entries()) {
  3195. - return false;
  3196. - }
  3197. - }
  3198. - return true;
  3199. -}
  3200. -void constantPoolCacheOopDesc::dump_cache() {
  3201. - for (int i = 1; i < length(); i++) {
  3202. - if (entry_at(i)->is_interesting_method_entry(NULL)) {
  3203. - entry_at(i)->print(tty, i);
  3204. - }
  3205. - }
  3206. -}
  3207. diff --git a/src/share/vm/oops/cpCacheOop.hpp b/src/share/vm/oops/cpCacheOop.hpp
  3208. index ef26775..6f37d81 100644
  3209. --- a/src/share/vm/oops/cpCacheOop.hpp
  3210. +++ b/src/share/vm/oops/cpCacheOop.hpp
  3211. @@ -136,7 +136,8 @@ class ConstantPoolCacheEntry VALUE_OBJ_CLASS_SPEC {
  3212. void set_bytecode_2(Bytecodes::Code code);
  3213. void set_f1(oop f1) {
  3214. oop existing_f1 = _f1; // read once
  3215. - assert(existing_f1 == NULL || existing_f1 == f1, "illegal field change");
  3216. + // (tw) need to relax assertion for redefinition
  3217. + // assert(existing_f1 == NULL || existing_f1 == f1, "illegal field change");
  3218. oop_store(&_f1, f1);
  3219. }
  3220. void release_set_f1(oop f1);
  3221. @@ -167,6 +168,7 @@ class ConstantPoolCacheEntry VALUE_OBJ_CLASS_SPEC {
  3222. tos_state_mask = right_n_bits(tos_state_bits),
  3223. tos_state_shift = BitsPerInt - tos_state_bits, // see verify_tos_state_shift below
  3224. // misc. option bits; can be any bit position in [16..27]
  3225. + is_old_method_shift = 19,
  3226. is_vfinal_shift = 20,
  3227. is_volatile_shift = 21,
  3228. is_final_shift = 22,
  3229. @@ -200,6 +202,8 @@ class ConstantPoolCacheEntry VALUE_OBJ_CLASS_SPEC {
  3230. void initialize_entry(int original_index); // initialize primary entry
  3231. void initialize_secondary_entry(int main_index); // initialize secondary entry
  3232. + void copy_from(ConstantPoolCacheEntry *other);
  3233. +
  3234. void set_field( // sets entry to resolved field state
  3235. Bytecodes::Code get_code, // the bytecode used for reading the field
  3236. Bytecodes::Code put_code, // the bytecode used for writing the field
  3237. @@ -361,10 +365,7 @@ class ConstantPoolCacheEntry VALUE_OBJ_CLASS_SPEC {
  3238. // trace_name_printed is set to true if the current call has
  3239. // printed the klass name so that other routines in the adjust_*
  3240. // group don't print the klass name.
  3241. - bool adjust_method_entry(methodOop old_method, methodOop new_method,
  3242. - bool * trace_name_printed);
  3243. - bool check_no_old_or_obsolete_entries();
  3244. - bool is_interesting_method_entry(klassOop k);
  3245. + bool adjust_method_entry(methodOop old_method, methodOop new_method);
  3246. // Debugging & Printing
  3247. void print (outputStream* st, int index) const;
  3248. @@ -485,16 +486,9 @@ class constantPoolCacheOopDesc: public oopDesc {
  3249. return (base_offset() + ConstantPoolCacheEntry::size_in_bytes() * index);
  3250. }
  3251. - // RedefineClasses() API support:
  3252. - // If any entry of this constantPoolCache points to any of
  3253. - // old_methods, replace it with the corresponding new_method.
  3254. - // trace_name_printed is set to true if the current call has
  3255. - // printed the klass name so that other routines in the adjust_*
  3256. - // group don't print the klass name.
  3257. - void adjust_method_entries(methodOop* old_methods, methodOop* new_methods,
  3258. - int methods_length, bool * trace_name_printed);
  3259. - bool check_no_old_or_obsolete_entries();
  3260. - void dump_cache();
  3261. + // (tw) Update method and field references
  3262. + void adjust_entries(methodOop* old_methods, methodOop* new_methods,
  3263. + int methods_length);
  3264. };
  3265. #endif // SHARE_VM_OOPS_CPCACHEOOP_HPP
  3266. diff --git a/src/share/vm/oops/instanceKlass.cpp b/src/share/vm/oops/instanceKlass.cpp
  3267. index a775b02..749458f 100644
  3268. --- a/src/share/vm/oops/instanceKlass.cpp
  3269. +++ b/src/share/vm/oops/instanceKlass.cpp
  3270. @@ -250,12 +250,118 @@ void instanceKlass::initialize(TRAPS) {
  3271. }
  3272. +void instanceKlass::initialize_redefined_class() {
  3273. + RC_TRACE(0x00000400, ("initializing redefined class %s",
  3274. + name()->as_C_string()));
  3275. +
  3276. + assert(!is_initialized(), "");
  3277. + assert(this->old_version() != NULL, "");
  3278. + assert(is_linked(), "must be linked before");
  3279. +
  3280. +
  3281. + instanceKlassHandle this_oop(Thread::current(), this->as_klassOop());
  3282. + class UpdateStaticFieldClosure : public FieldClosure {
  3283. +
  3284. + private:
  3285. + instanceKlassHandle this_oop;
  3286. +
  3287. + public:
  3288. + UpdateStaticFieldClosure(instanceKlassHandle this_oop) {
  3289. + this->this_oop = this_oop;
  3290. + }
  3291. +
  3292. + virtual void do_field(fieldDescriptor* fd) {
  3293. + fieldDescriptor result;
  3294. + bool found = ((instanceKlass *)(this_oop->old_version()->klass_part()))->find_local_field(fd->name(), fd->signature(), &result);
  3295. +
  3296. + if (found && result.is_static()) {
  3297. + int old_offset = result.offset();
  3298. + assert(result.field_type() == fd->field_type(), "Old and new field type does not match");
  3299. +
  3300. + oop new_location = this_oop()->java_mirror();
  3301. + oop old_location = this_oop->old_version()->java_mirror();
  3302. + int offset = fd->offset();
  3303. + RC_TRACE(0x00000400, ("Copying static field value for field '%s' old_offset=%d new_offset=%d",
  3304. + fd->name()->as_C_string(), old_offset, offset));
  3305. +
  3306. + oop cur_oop;
  3307. +
  3308. + switch(result.field_type()) {
  3309. +
  3310. + // Found static field with same name and type in the old klass => copy value from old to new klass
  3311. +
  3312. + case T_BOOLEAN:
  3313. + new_location->bool_field_put(offset, old_location->bool_field(old_offset));
  3314. + DEBUG_ONLY(old_location->byte_field_put(old_offset, 0));
  3315. + break;
  3316. +
  3317. + case T_CHAR:
  3318. + new_location->char_field_put(offset, old_location->char_field(old_offset));
  3319. + DEBUG_ONLY(old_location->char_field_put(old_offset, 0));
  3320. + break;
  3321. +
  3322. + case T_FLOAT:
  3323. + new_location->float_field_put(offset, old_location->float_field(old_offset));
  3324. + DEBUG_ONLY(old_location->float_field_put(old_offset, 0));
  3325. + break;
  3326. +
  3327. + case T_DOUBLE:
  3328. + new_location->double_field_put(offset, old_location->double_field(old_offset));
  3329. + DEBUG_ONLY(old_location->double_field_put(old_offset, 0));
  3330. + break;
  3331. +
  3332. + case T_BYTE:
  3333. + new_location->byte_field_put(offset, old_location->byte_field(old_offset));
  3334. + DEBUG_ONLY(old_location->byte_field_put(old_offset, 0));
  3335. + break;
  3336. +
  3337. + case T_SHORT:
  3338. + new_location->short_field_put(offset, old_location->short_field(old_offset));
  3339. + DEBUG_ONLY(old_location->short_field_put(old_offset, 0));
  3340. + break;
  3341. +
  3342. + case T_INT:
  3343. + new_location->int_field_put(offset, old_location->int_field(old_offset));
  3344. + DEBUG_ONLY(old_location->int_field_put(old_offset, 0));
  3345. + break;
  3346. +
  3347. + case T_LONG:
  3348. + new_location->long_field_put(offset, old_location->long_field(old_offset));
  3349. + DEBUG_ONLY(old_location->long_field_put(old_offset, 0));
  3350. + break;
  3351. +
  3352. + case T_OBJECT:
  3353. + case T_ARRAY:
  3354. + cur_oop = old_location->obj_field(old_offset);
  3355. + new_location->obj_field_put_raw(offset, cur_oop);
  3356. + old_location->obj_field_put_raw(old_offset, NULL);
  3357. + break;
  3358. +
  3359. + default:
  3360. + ShouldNotReachHere();
  3361. + }
  3362. + } else {
  3363. + RC_TRACE(0x00000200, ("New static field %s has_initial_value=%d",
  3364. + fd->name()->as_C_string(), (int)(fd->has_initial_value())));
  3365. + // field not found
  3366. + // (tw) TODO: Probably this call is not necessary here!
  3367. + // FIXME: idubrov
  3368. + //ClassFileParser::initialize_static_field(fd, Thread::current());
  3369. + }
  3370. + }
  3371. + };
  3372. +
  3373. + UpdateStaticFieldClosure cl(this_oop);
  3374. + this->do_local_static_fields(&cl);
  3375. +}
  3376. +
  3377. +
  3378. bool instanceKlass::verify_code(
  3379. instanceKlassHandle this_oop, bool throw_verifyerror, TRAPS) {
  3380. // 1) Verify the bytecodes
  3381. Verifier::Mode mode =
  3382. throw_verifyerror ? Verifier::ThrowException : Verifier::NoException;
  3383. - return Verifier::verify(this_oop, mode, this_oop->should_verify_class(), CHECK_false);
  3384. + return Verifier::verify(this_oop, mode, this_oop->should_verify_class(), true, CHECK_false);
  3385. }
  3386. @@ -362,7 +468,13 @@ bool instanceKlass::link_class_impl(
  3387. jt->get_thread_stat()->perf_recursion_counts_addr(),
  3388. jt->get_thread_stat()->perf_timers_addr(),
  3389. PerfClassTraceTime::CLASS_VERIFY);
  3390. - bool verify_ok = verify_code(this_oop, throw_verifyerror, THREAD);
  3391. + if (this_oop->is_redefining()) {
  3392. + Thread::current()->set_pretend_new_universe(true);
  3393. + }
  3394. + bool verify_ok = verify_code(this_oop, throw_verifyerror, THREAD);
  3395. + if (this_oop->is_redefining()) {
  3396. + Thread::current()->set_pretend_new_universe(false);
  3397. + }
  3398. if (!verify_ok) {
  3399. return false;
  3400. }
  3401. @@ -400,7 +512,8 @@ bool instanceKlass::link_class_impl(
  3402. }
  3403. #endif
  3404. this_oop->set_init_state(linked);
  3405. - if (JvmtiExport::should_post_class_prepare()) {
  3406. + // (tw) Must check for old version in order to prevent infinite loops.
  3407. + if (JvmtiExport::should_post_class_prepare() && this_oop->old_version() == NULL /* JVMTI deadlock otherwise */) {
  3408. Thread *thread = THREAD;
  3409. assert(thread->is_Java_thread(), "thread->is_Java_thread()");
  3410. JvmtiExport::post_class_prepare((JavaThread *) thread, this_oop());
  3411. @@ -673,6 +786,18 @@ bool instanceKlass::implements_interface(klassOop k) const {
  3412. return false;
  3413. }
  3414. +bool instanceKlass::implements_interface_any_version(klassOop k) const {
  3415. + k = k->klass_part()->newest_version();
  3416. + if (this->newest_version() == k) return true;
  3417. + assert(Klass::cast(k)->is_interface(), "should be an interface class");
  3418. + for (int i = 0; i < transitive_interfaces()->length(); i++) {
  3419. + if (((klassOop)transitive_interfaces()->obj_at(i))->klass_part()->newest_version() == k) {
  3420. + return true;
  3421. + }
  3422. + }
  3423. + return false;
  3424. +}
  3425. +
  3426. objArrayOop instanceKlass::allocate_objArray(int n, int length, TRAPS) {
  3427. if (length < 0) THROW_0(vmSymbols::java_lang_NegativeArraySizeException());
  3428. if (length > arrayOopDesc::max_array_length(T_OBJECT)) {
  3429. @@ -801,7 +926,25 @@ methodOop instanceKlass::class_initializer() {
  3430. }
  3431. void instanceKlass::call_class_initializer_impl(instanceKlassHandle this_oop, TRAPS) {
  3432. +
  3433. + ResourceMark rm(THREAD);
  3434. methodHandle h_method(THREAD, this_oop->class_initializer());
  3435. +
  3436. + if (this_oop->revision_number() != -1){
  3437. + methodOop m = NULL;
  3438. + if (AllowAdvancedClassRedefinition) {
  3439. + m = this_oop->find_method(vmSymbols::static_transformer_name(), vmSymbols::void_method_signature());
  3440. + }
  3441. + methodHandle method(m);
  3442. + if (method() != NULL && method()->is_static()) {
  3443. + RC_TRACE(0x00000200, ("Calling static transformer instead of static initializer"));
  3444. + h_method = method;
  3445. + } else if (!((instanceKlass*)this_oop->old_version()->klass_part())->is_not_initialized()) {
  3446. + // Only execute the static initializer, if it was not yet executed for the old version of the class.
  3447. + return;
  3448. + }
  3449. + }
  3450. +
  3451. assert(!this_oop->is_initialized(), "we cannot initialize twice");
  3452. if (TraceClassInitialization) {
  3453. tty->print("%d Initializing ", call_class_initializer_impl_counter++);
  3454. @@ -949,6 +1092,137 @@ void instanceKlass::methods_do(void f(methodOop method)) {
  3455. }
  3456. }
  3457. +void instanceKlass::store_update_information(GrowableArray<int> &values) {
  3458. + int *arr = NEW_C_HEAP_ARRAY(int, values.length(), mtClass);
  3459. + for (int i=0; i<values.length(); i++) {
  3460. + arr[i] = values.at(i);
  3461. + }
  3462. + set_update_information(arr);
  3463. +}
  3464. +
  3465. +void instanceKlass::clear_update_information() {
  3466. + FREE_C_HEAP_ARRAY(int, update_information(), mtClass);
  3467. + set_update_information(NULL);
  3468. +}
  3469. +
  3470. +typedef Pair<int, klassOop> typeInfoPair;
  3471. +
  3472. +void instanceKlass::store_type_check_information(GrowableArray< Pair<int, klassOop> > &values) {
  3473. + Pair<int, klassOop> *arr = NEW_C_HEAP_ARRAY(typeInfoPair, values.length(), mtClass);
  3474. + for (int i=0; i<values.length(); i++) {
  3475. + arr[i] = values.at(i);
  3476. + }
  3477. + set_type_check_information(arr);
  3478. +}
  3479. +
  3480. +void instanceKlass::clear_type_check_information() {
  3481. + FREE_C_HEAP_ARRAY(typeInfoPair, type_check_information(), mtClass);
  3482. + set_type_check_information(NULL);
  3483. +}
  3484. +
  3485. +void instanceKlass::do_fields_evolution(FieldEvolutionClosure* cl) {
  3486. +
  3487. + assert (old_version() != NULL, "must have old version!");
  3488. +
  3489. + klassOop old_klass_oop = old_version();
  3490. + instanceKlass *old_klass = instanceKlass::cast(old_klass_oop);
  3491. + instanceKlass *new_klass = this;
  3492. +
  3493. + fieldDescriptor fd;
  3494. + fieldDescriptor old_fd;
  3495. +
  3496. + instanceKlass *cur_new_klass = new_klass;
  3497. + klassOop cur_new_klass_oop = this->as_klassOop();
  3498. +
  3499. + if (_fields_not_changed) {
  3500. +
  3501. + class MyFieldClosure : public FieldClosure {
  3502. +
  3503. + FieldEvolutionClosure *_cl;
  3504. + public:
  3505. + MyFieldClosure(FieldEvolutionClosure *cl) {_cl = cl; }
  3506. + virtual void do_field(fieldDescriptor* fd) {
  3507. + _cl->do_changed_field(fd, fd);
  3508. + }
  3509. + };
  3510. +
  3511. + MyFieldClosure mfc(cl);
  3512. + do_nonstatic_fields(&mfc);
  3513. + } else {
  3514. +
  3515. + _fields_not_changed = true;
  3516. + GrowableArray<fieldDescriptor> fds;
  3517. + while (true) {
  3518. + for (JavaFieldStream fs(cur_new_klass); !fs.done(); fs.next()) {
  3519. + fd.initialize(cur_new_klass_oop, fs.index());
  3520. + if (fd.is_static()) {
  3521. + continue;
  3522. + }
  3523. + fds.append(fd);
  3524. + }
  3525. +
  3526. + if (cur_new_klass->super() != NULL) {
  3527. + cur_new_klass_oop = cur_new_klass->super();
  3528. + cur_new_klass = instanceKlass::cast(cur_new_klass_oop);
  3529. + } else {
  3530. + break;
  3531. + }
  3532. + }
  3533. +
  3534. + GrowableArray<fieldDescriptor> sortedFds;
  3535. + while (fds.length() > 0) {
  3536. + int minOffset = 0x7fffffff;
  3537. + int minIndex = -1;
  3538. + for (int i=0; i<fds.length(); i++) {
  3539. + int curOffset = fds.adr_at(i)->offset();
  3540. + if (curOffset < minOffset) {
  3541. + minOffset = curOffset;
  3542. + minIndex = i;
  3543. + }
  3544. + }
  3545. +
  3546. + sortedFds.append(fds.at(minIndex));
  3547. + fds.remove_at(minIndex);
  3548. + }
  3549. +
  3550. +
  3551. + for (int i=0; i<sortedFds.length(); i++) {
  3552. + fieldDescriptor &fd = *sortedFds.adr_at(i);
  3553. +
  3554. + char found = 0;
  3555. + instanceKlass *cur_old_klass = old_klass;
  3556. + klassOop cur_old_klass_oop = old_klass_oop;
  3557. + while (true) {
  3558. + for (JavaFieldStream fs(cur_old_klass); !fs.done(); fs.next()) {
  3559. + old_fd.initialize(cur_old_klass_oop, fs.index());
  3560. + if (old_fd.is_static()) {
  3561. + continue;
  3562. + }
  3563. + if (old_fd.name() == fd.name() && old_fd.signature() == fd.signature()) {
  3564. + found = 1;
  3565. + break;
  3566. + }
  3567. + }
  3568. + if (!found && cur_old_klass->super()) {
  3569. + cur_old_klass_oop = cur_old_klass->super();
  3570. + cur_old_klass = instanceKlass::cast(cur_old_klass_oop);
  3571. + } else {
  3572. + break;
  3573. + }
  3574. + }
  3575. +
  3576. + if (found) {
  3577. + if (old_fd.offset() != fd.offset()) {
  3578. + _fields_not_changed = false;
  3579. + }
  3580. + cl->do_changed_field(&old_fd, &fd);
  3581. + } else {
  3582. + _fields_not_changed = false;
  3583. + cl->do_new_field(&fd);
  3584. + }
  3585. + }
  3586. + }
  3587. +}
  3588. void instanceKlass::do_local_static_fields(FieldClosure* cl) {
  3589. for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
  3590. @@ -1368,6 +1642,20 @@ jmethodID instanceKlass::jmethod_id_or_null(methodOop method) {
  3591. return id;
  3592. }
  3593. +bool instanceKlass::update_jmethod_id(methodOop method, jmethodID newMethodID) {
  3594. + size_t idnum = (size_t)method->method_idnum();
  3595. + jmethodID* jmeths = methods_jmethod_ids_acquire();
  3596. + size_t length; // length assigned as debugging crumb
  3597. + jmethodID id = NULL;
  3598. + if (jmeths != NULL && // If there is a cache
  3599. + (length = (size_t)jmeths[0]) > idnum) { // and if it is long enough,
  3600. + jmeths[idnum+1] = newMethodID; // Set the id (may be NULL)
  3601. + return true;
  3602. + }
  3603. +
  3604. + return false;
  3605. +}
  3606. +
  3607. // Cache an itable index
  3608. void instanceKlass::set_cached_itable_index(size_t idnum, int index) {
  3609. @@ -1527,6 +1815,13 @@ void instanceKlass::remove_dependent_nmethod(nmethod* nm) {
  3610. last = b;
  3611. b = b->next();
  3612. }
  3613. +
  3614. + // (tw) Hack as dependencies get wrong version of klassOop
  3615. + if(this->old_version() != NULL) {
  3616. + ((instanceKlass *)this->old_version()->klass_part())->remove_dependent_nmethod(nm);
  3617. + return;
  3618. + }
  3619. +
  3620. #ifdef ASSERT
  3621. tty->print_cr("### %s can't find dependent nmethod:", this->external_name());
  3622. nm->print();
  3623. @@ -2417,6 +2712,9 @@ void instanceKlass::oop_print_on(oop obj, outputStream* st) {
  3624. klassOop mirrored_klass = java_lang_Class::as_klassOop(obj);
  3625. st->print(BULLET"fake entry for mirror: ");
  3626. mirrored_klass->print_value_on(st);
  3627. + if (mirrored_klass != NULL) {
  3628. + 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());
  3629. + }
  3630. st->cr();
  3631. st->print(BULLET"fake entry resolved_constructor: ");
  3632. methodOop ctor = java_lang_Class::resolved_constructor(obj);
  3633. diff --git a/src/share/vm/oops/instanceKlass.hpp b/src/share/vm/oops/instanceKlass.hpp
  3634. index bb613b0..71f0083 100644
  3635. --- a/src/share/vm/oops/instanceKlass.hpp
  3636. +++ b/src/share/vm/oops/instanceKlass.hpp
  3637. @@ -102,6 +102,22 @@ public:
  3638. virtual void do_field(fieldDescriptor* fd) = 0;
  3639. };
  3640. +// (tw) Iterates over the fields of the old and new class
  3641. +class FieldEvolutionClosure : public StackObj {
  3642. +public:
  3643. + virtual void do_new_field(fieldDescriptor* fd) = 0;
  3644. + virtual void do_old_field(fieldDescriptor* fd) = 0;
  3645. + virtual void do_changed_field(fieldDescriptor* old_fd, fieldDescriptor *new_fd) = 0;
  3646. +};
  3647. +
  3648. +// (tw) Iterates over the methods of the old and new class
  3649. +class MethodEvolutionClosure : public StackObj {
  3650. +public:
  3651. + virtual void do_new_method(methodOop oop) = 0;
  3652. + virtual void do_old_method(methodOop oop) = 0;
  3653. + virtual void do_changed_method(methodOop oldOop, methodOop newOop) = 0;
  3654. +};
  3655. +
  3656. #ifndef PRODUCT
  3657. // Print fields.
  3658. // If "obj" argument to constructor is NULL, prints static fields, otherwise prints non-static fields.
  3659. @@ -287,6 +303,11 @@ class instanceKlass: public Klass {
  3660. // _idnum_allocated_count.
  3661. u1 _init_state; // state of class
  3662. + // (tw) Field that allows for a short-path when calculating updated fields for the second time and
  3663. + // no fields changed. Testing performance impact with this, can be removed later when the update
  3664. + // information is cached.
  3665. + bool _fields_not_changed;
  3666. +
  3667. u1 _reference_type; // reference type
  3668. // embedded Java vtable follows here
  3669. @@ -454,6 +475,7 @@ class instanceKlass: public Klass {
  3670. // initialization (virtuals from Klass)
  3671. bool should_be_initialized() const; // means that initialize should be called
  3672. void initialize(TRAPS);
  3673. + void initialize_redefined_class();
  3674. void link_class(TRAPS);
  3675. bool link_class_or_fail(TRAPS); // returns false on failure
  3676. void unlink_class();
  3677. @@ -631,6 +653,7 @@ class instanceKlass: public Klass {
  3678. static void get_jmethod_id_length_value(jmethodID* cache, size_t idnum,
  3679. size_t *length_p, jmethodID* id_p);
  3680. jmethodID jmethod_id_or_null(methodOop method);
  3681. + bool update_jmethod_id(methodOop method, jmethodID newMethodID);
  3682. // cached itable index support
  3683. void set_cached_itable_index(size_t idnum, int index);
  3684. @@ -713,6 +736,7 @@ class instanceKlass: public Klass {
  3685. // subclass/subinterface checks
  3686. bool implements_interface(klassOop k) const;
  3687. + bool implements_interface_any_version(klassOop k) const;
  3688. // Access to the implementor of an interface.
  3689. klassOop implementor() const
  3690. @@ -762,6 +786,12 @@ class instanceKlass: public Klass {
  3691. void do_local_static_fields(FieldClosure* cl);
  3692. void do_nonstatic_fields(FieldClosure* cl); // including inherited fields
  3693. void do_local_static_fields(void f(fieldDescriptor*, TRAPS), TRAPS);
  3694. + void do_fields_evolution(FieldEvolutionClosure *cl);
  3695. + void store_update_information(GrowableArray<int> &values);
  3696. + void clear_update_information();
  3697. + void store_type_check_information(GrowableArray< Pair<int, klassOop> > &values);
  3698. + void clear_type_check_information();
  3699. +
  3700. void methods_do(void f(methodOop method));
  3701. void array_klasses_do(void f(klassOop k));
  3702. diff --git a/src/share/vm/oops/instanceKlassKlass.cpp b/src/share/vm/oops/instanceKlassKlass.cpp
  3703. index 8e7dc12..63d6dc4 100644
  3704. --- a/src/share/vm/oops/instanceKlassKlass.cpp
  3705. +++ b/src/share/vm/oops/instanceKlassKlass.cpp
  3706. @@ -480,6 +480,28 @@ void instanceKlassKlass::oop_print_on(oop obj, outputStream* st) {
  3707. instanceKlass* ik = instanceKlass::cast(klassOop(obj));
  3708. klassKlass::oop_print_on(obj, st);
  3709. + // (tw) Output revision number and revision numbers of older / newer and oldest / newest version of this class.
  3710. +
  3711. + st->print(BULLET"revision: %d", ik->revision_number());
  3712. +
  3713. + if (ik->new_version() != NULL) {
  3714. + st->print(" (newer=%d)", ik->new_version()->klass_part()->revision_number());
  3715. + }
  3716. +
  3717. + if (ik->newest_version() != ik->new_version() && ik->newest_version() != obj) {
  3718. + st->print(" (newest=%d)", ik->newest_version()->klass_part()->revision_number());
  3719. + }
  3720. +
  3721. + if (ik->old_version() != NULL) {
  3722. + st->print(" (old=%d)", ik->old_version()->klass_part()->revision_number());
  3723. + }
  3724. +
  3725. + if (ik->oldest_version() != ik->old_version() && ik->oldest_version() != obj) {
  3726. + st->print(" (oldest=%d)", ik->oldest_version()->klass_part()->revision_number());
  3727. + }
  3728. +
  3729. + st->cr();
  3730. +
  3731. st->print(BULLET"instance size: %d", ik->size_helper()); st->cr();
  3732. st->print(BULLET"klass size: %d", ik->object_size()); st->cr();
  3733. st->print(BULLET"access: "); ik->access_flags().print_on(st); st->cr();
  3734. @@ -663,7 +685,7 @@ void instanceKlassKlass::oop_verify_on(oop obj, outputStream* st) {
  3735. }
  3736. guarantee(sib->as_klassOop()->is_klass(), "should be klass");
  3737. guarantee(sib->as_klassOop()->is_perm(), "should be in permspace");
  3738. - guarantee(sib->super() == super, "siblings should have same superklass");
  3739. + guarantee(sib->super() == super || super->klass_part()->newest_version() == SystemDictionary::Object_klass(), "siblings should have same superklass");
  3740. sib = sib->next_sibling();
  3741. }
  3742. diff --git a/src/share/vm/oops/instanceRefKlass.cpp b/src/share/vm/oops/instanceRefKlass.cpp
  3743. index 7db4f03..1171487 100644
  3744. --- a/src/share/vm/oops/instanceRefKlass.cpp
  3745. +++ b/src/share/vm/oops/instanceRefKlass.cpp
  3746. @@ -455,10 +455,13 @@ void instanceRefKlass::update_nonstatic_oop_maps(klassOop k) {
  3747. instanceKlass* ik = instanceKlass::cast(k);
  3748. // Check that we have the right class
  3749. - debug_only(static bool first_time = true);
  3750. - assert(k == SystemDictionary::Reference_klass() && first_time,
  3751. - "Invalid update of maps");
  3752. - debug_only(first_time = false);
  3753. +
  3754. + // (tw) Asserts no longer valid for class redefinition
  3755. + // debug_only(static bool first_time = true);
  3756. +
  3757. + //assert(k == SystemDictionary::Reference_klass() && first_time,
  3758. + // "Invalid update of maps");
  3759. + //debug_only(first_time = false);
  3760. assert(ik->nonstatic_oop_map_count() == 1, "just checking");
  3761. OopMapBlock* map = ik->start_of_nonstatic_oop_maps();
  3762. diff --git a/src/share/vm/oops/klass.cpp b/src/share/vm/oops/klass.cpp
  3763. index ff33181..28537e2 100644
  3764. --- a/src/share/vm/oops/klass.cpp
  3765. +++ b/src/share/vm/oops/klass.cpp
  3766. @@ -55,6 +55,26 @@ bool Klass::is_subclass_of(klassOop k) const {
  3767. return false;
  3768. }
  3769. +void Klass::update_supers_to_newest_version() {
  3770. +
  3771. + if (super() != NULL) set_super(super()->klass_part()->newest_version());
  3772. +
  3773. + for (uint i=0; i<primary_super_limit(); i++) {
  3774. + klassOop cur = _primary_supers[i];
  3775. + if (cur != NULL) {
  3776. + _primary_supers[i] = cur->klass_part()->newest_version();
  3777. + }
  3778. + }
  3779. +
  3780. + // Scan the array-of-objects
  3781. + int cnt = secondary_supers()->length();
  3782. + for (int i = 0; i < cnt; i++) {
  3783. + klassOop cur = (klassOop)secondary_supers()->obj_at(i);
  3784. + if (cur != NULL) {
  3785. + secondary_supers()->obj_at_put(i, cur->klass_part()->newest_version());
  3786. + }
  3787. + }
  3788. +}
  3789. bool Klass::search_secondary_supers(klassOop k) const {
  3790. // Put some extra logic here out-of-line, before the search proper.
  3791. // This cuts down the size of the inline method.
  3792. @@ -170,6 +190,16 @@ klassOop Klass::base_create_klass_oop(KlassHandle& klass, int size,
  3793. kl->set_alloc_size(0);
  3794. TRACE_INIT_ID(kl);
  3795. + kl->set_redefinition_flags(Klass::NoRedefinition);
  3796. + kl->set_redefining(false);
  3797. + kl->set_new_version(NULL);
  3798. + kl->set_old_version(NULL);
  3799. + kl->set_redefinition_index(-1);
  3800. + kl->set_revision_number(-1);
  3801. + kl->set_field_redefinition_policy(DynamicCheck);
  3802. + kl->set_static_field_redefinition_policy(AccessDeletedMembers);
  3803. + kl->set_method_redefinition_policy(AccessDeletedMembers);
  3804. +
  3805. kl->set_prototype_header(markOopDesc::prototype());
  3806. kl->set_biased_lock_revocation_count(0);
  3807. kl->set_last_biased_lock_bulk_revocation_time(0);
  3808. @@ -241,7 +271,7 @@ void Klass::initialize_supers(klassOop k, TRAPS) {
  3809. set_super(NULL);
  3810. oop_store_without_check((oop*) &_primary_supers[0], (oop) this->as_klassOop());
  3811. assert(super_depth() == 0, "Object must already be initialized properly");
  3812. - } else if (k != super() || k == SystemDictionary::Object_klass()) {
  3813. + } else if (k != super() || k->klass_part()->super() == NULL) {
  3814. assert(super() == NULL || super() == SystemDictionary::Object_klass(),
  3815. "initialize this only once to a non-trivial value");
  3816. set_super(k);
  3817. diff --git a/src/share/vm/oops/klass.hpp b/src/share/vm/oops/klass.hpp
  3818. index a449e87..52364ba 100644
  3819. --- a/src/share/vm/oops/klass.hpp
  3820. +++ b/src/share/vm/oops/klass.hpp
  3821. @@ -171,6 +171,7 @@ class Klass_vtbl {
  3822. void* operator new(size_t ignored, KlassHandle& klass, int size, TRAPS);
  3823. };
  3824. +template<class L, class R> class Pair;
  3825. class Klass : public Klass_vtbl {
  3826. friend class VMStructs;
  3827. @@ -223,6 +224,39 @@ class Klass : public Klass_vtbl {
  3828. oop* oop_block_beg() const { return adr_secondary_super_cache(); }
  3829. oop* oop_block_end() const { return adr_next_sibling() + 1; }
  3830. + // (tw) Different class redefinition flags of code evolution.
  3831. + enum RedefinitionFlags {
  3832. +
  3833. + // This class is not redefined at all!
  3834. + NoRedefinition,
  3835. +
  3836. + // There are changes to the class meta data.
  3837. + ModifyClass = 1,
  3838. +
  3839. + // The size of the class meta data changes.
  3840. + ModifyClassSize = ModifyClass << 1,
  3841. +
  3842. + // There are change to the instance format.
  3843. + ModifyInstances = ModifyClassSize << 1,
  3844. +
  3845. + // The size of instances changes.
  3846. + ModifyInstanceSize = ModifyInstances << 1,
  3847. +
  3848. + // A super type of this class is removed.
  3849. + RemoveSuperType = ModifyInstanceSize << 1,
  3850. +
  3851. + // This class (or one of its super classes) has an instance transformer method.
  3852. + HasInstanceTransformer = RemoveSuperType << 1,
  3853. + };
  3854. +
  3855. + // (tw) Different policies dealing with deleted fields / methods in old code.
  3856. + enum RedefinitionPolicy {
  3857. + StaticCheck,
  3858. + DynamicCheck,
  3859. + AccessDeletedMembers,
  3860. + AccessOldMembers
  3861. + };
  3862. +
  3863. protected:
  3864. //
  3865. // The oop block. All oop fields must be declared here and only oop fields
  3866. @@ -242,6 +276,10 @@ class Klass : public Klass_vtbl {
  3867. oop _java_mirror;
  3868. // Superclass
  3869. klassOop _super;
  3870. + // Old class
  3871. + klassOop _old_version;
  3872. + // New class
  3873. + klassOop _new_version;
  3874. // First subclass (NULL if none); _subklass->next_sibling() is next one
  3875. klassOop _subklass;
  3876. // Sibling link (or NULL); links all subklasses of a klass
  3877. @@ -254,6 +292,19 @@ class Klass : public Klass_vtbl {
  3878. jint _modifier_flags; // Processed access flags, for use by Class.getModifiers.
  3879. AccessFlags _access_flags; // Access flags. The class/interface distinction is stored here.
  3880. + // (tw) Non-oop fields for enhanced class redefinition
  3881. + jint _revision_number; // The revision number for redefined classes
  3882. + jint _redefinition_index; // Index of this class when performing the redefinition
  3883. + bool _subtype_changed;
  3884. + int _redefinition_flags; // Level of class redefinition
  3885. + bool _is_copying_backwards; // Does the class need to copy fields backwards? => possibly overwrite itself?
  3886. + int * _update_information; // Update information
  3887. + Pair<int, klassOop> * _type_check_information; // Offsets of object fields that need a type check
  3888. + char _method_redefinition_policy;
  3889. + char _field_redefinition_policy;
  3890. + char _static_field_redefinition_policy;
  3891. + bool _is_redefining;
  3892. +
  3893. #ifndef PRODUCT
  3894. int _verify_count; // to avoid redundant verifies
  3895. #endif
  3896. @@ -302,6 +353,99 @@ class Klass : public Klass_vtbl {
  3897. klassOop secondary_super_cache() const { return _secondary_super_cache; }
  3898. void set_secondary_super_cache(klassOop k) { oop_store_without_check((oop*) &_secondary_super_cache, (oop) k); }
  3899. + // BEGIN class redefinition utilities
  3900. +
  3901. + // double links between new and old version of a class
  3902. + klassOop old_version() const { return _old_version; }
  3903. + void set_old_version(klassOop klass) { assert(_old_version == NULL || klass == NULL, "Can only be set once!"); _old_version = klass; }
  3904. + klassOop new_version() const { return _new_version; }
  3905. + void set_new_version(klassOop klass) { assert(_new_version == NULL || klass == NULL, "Can only be set once!"); _new_version = klass; }
  3906. +
  3907. + // A subtype of this class is no longer a subtype
  3908. + bool has_subtype_changed() const { return _subtype_changed; }
  3909. + void set_subtype_changed(bool b) { assert(is_newest_version() || new_version()->klass_part()->is_newest_version(), "must be newest or second newest version");
  3910. + _subtype_changed = b; }
  3911. + // state of being redefined
  3912. + int redefinition_index() const { return _redefinition_index; }
  3913. + void set_redefinition_index(int index) { _redefinition_index = index; }
  3914. + void set_redefining(bool b) { _is_redefining = b; }
  3915. + bool is_redefining() const { return _is_redefining; }
  3916. + int redefinition_flags() const { return _redefinition_flags; }
  3917. + bool check_redefinition_flag(int flags) const { return (_redefinition_flags & flags) != 0; }
  3918. + void set_redefinition_flags(int flags) { _redefinition_flags = flags; }
  3919. + bool is_copying_backwards() const { return _is_copying_backwards; }
  3920. + void set_copying_backwards(bool b) { _is_copying_backwards = b; }
  3921. +
  3922. + // update information
  3923. + int *update_information() const { return _update_information; }
  3924. + void set_update_information(int *info) { _update_information = info; }
  3925. + Pair<int, klassOop> *type_check_information() const { return _type_check_information; }
  3926. + void set_type_check_information(Pair<int, klassOop> *info) { _type_check_information = info; }
  3927. +
  3928. + bool is_same_or_older_version(klassOop klass) const {
  3929. + if (Klass::cast(klass) == this) { return true; }
  3930. + else if (_old_version == NULL) { return false; }
  3931. + else { return _old_version->klass_part()->is_same_or_older_version(klass); }
  3932. + }
  3933. +
  3934. + // Revision number for redefined classes, -1 for originally loaded classes
  3935. + jint revision_number() const {
  3936. + return _revision_number;
  3937. + }
  3938. +
  3939. + bool was_redefined() const {
  3940. + return _revision_number != -1;
  3941. + }
  3942. +
  3943. + void set_revision_number(jint number) {
  3944. + _revision_number = number;
  3945. + }
  3946. +
  3947. + char method_redefinition_policy() {
  3948. + return _method_redefinition_policy;
  3949. + }
  3950. +
  3951. + void set_method_redefinition_policy(char v) {
  3952. + _method_redefinition_policy = v;
  3953. + }
  3954. +
  3955. + char field_redefinition_policy() {
  3956. + return _field_redefinition_policy;
  3957. + }
  3958. +
  3959. + void set_field_redefinition_policy(char v) {
  3960. + _field_redefinition_policy = v;
  3961. + }
  3962. +
  3963. + char static_field_redefinition_policy() {
  3964. + return _static_field_redefinition_policy;
  3965. + }
  3966. +
  3967. + void set_static_field_redefinition_policy(char v) {
  3968. + _static_field_redefinition_policy = v;
  3969. + }
  3970. +
  3971. + klassOop oldest_version() const {
  3972. + if (_old_version == NULL) { return this->as_klassOop(); }
  3973. + else { return _old_version->klass_part()->oldest_version(); };
  3974. + }
  3975. +
  3976. + klassOop newest_version() const {
  3977. + if (_new_version == NULL) { return this->as_klassOop(); }
  3978. + else { return _new_version->klass_part()->newest_version(); };
  3979. + }
  3980. +
  3981. + klassOop active_version() const {
  3982. + if (_new_version == NULL || _new_version->klass_part()->is_redefining()) { return this->as_klassOop(); assert(!this->is_redefining(), "just checking"); }
  3983. + else { return _new_version->klass_part()->active_version(); };
  3984. + }
  3985. +
  3986. + bool is_newest_version() const {
  3987. + return _new_version == NULL;
  3988. + }
  3989. +
  3990. + // END class redefinition utilities
  3991. +
  3992. objArrayOop secondary_supers() const { return _secondary_supers; }
  3993. void set_secondary_supers(objArrayOop k) { oop_store_without_check((oop*) &_secondary_supers, (oop) k); }
  3994. @@ -362,6 +506,8 @@ class Klass : public Klass_vtbl {
  3995. void set_next_sibling(klassOop s);
  3996. oop* adr_super() const { return (oop*)&_super; }
  3997. + oop* adr_old_version() const { return (oop*)&_old_version; }
  3998. + oop* adr_new_version() const { return (oop*)&_new_version; }
  3999. oop* adr_primary_supers() const { return (oop*)&_primary_supers[0]; }
  4000. oop* adr_secondary_super_cache() const { return (oop*)&_secondary_super_cache; }
  4001. oop* adr_secondary_supers()const { return (oop*)&_secondary_supers; }
  4002. @@ -491,6 +637,7 @@ class Klass : public Klass_vtbl {
  4003. return search_secondary_supers(k);
  4004. }
  4005. }
  4006. + void update_supers_to_newest_version();
  4007. bool search_secondary_supers(klassOop k) const;
  4008. // Find LCA in class hierarchy
  4009. @@ -818,6 +965,8 @@ class Klass : public Klass_vtbl {
  4010. inline oop klassOopDesc::java_mirror() const { return klass_part()->java_mirror(); }
  4011. +inline klassOop klassOopDesc::old_version() const { return klass_part()->old_version(); }
  4012. +inline klassOop klassOopDesc::new_version() const { return klass_part()->new_version(); }
  4013. #endif // SHARE_VM_OOPS_KLASS_HPP
  4014. diff --git a/src/share/vm/oops/klassKlass.cpp b/src/share/vm/oops/klassKlass.cpp
  4015. index 06809d5..9c08f32 100644
  4016. --- a/src/share/vm/oops/klassKlass.cpp
  4017. +++ b/src/share/vm/oops/klassKlass.cpp
  4018. @@ -68,6 +68,8 @@ void klassKlass::oop_follow_contents(oop obj) {
  4019. Klass* k = Klass::cast(klassOop(obj));
  4020. // If we are alive it is valid to keep our superclass and subtype caches alive
  4021. MarkSweep::mark_and_push(k->adr_super());
  4022. + MarkSweep::mark_and_push(k->adr_old_version());
  4023. + MarkSweep::mark_and_push(k->adr_new_version());
  4024. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  4025. MarkSweep::mark_and_push(k->adr_primary_supers()+i);
  4026. MarkSweep::mark_and_push(k->adr_secondary_super_cache());
  4027. @@ -87,6 +89,8 @@ void klassKlass::oop_follow_contents(ParCompactionManager* cm,
  4028. Klass* k = Klass::cast(klassOop(obj));
  4029. // If we are alive it is valid to keep our superclass and subtype caches alive
  4030. PSParallelCompact::mark_and_push(cm, k->adr_super());
  4031. + PSParallelCompact::mark_and_push(cm, k->adr_old_version());
  4032. + PSParallelCompact::mark_and_push(cm, k->adr_new_version());
  4033. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  4034. PSParallelCompact::mark_and_push(cm, k->adr_primary_supers()+i);
  4035. PSParallelCompact::mark_and_push(cm, k->adr_secondary_super_cache());
  4036. @@ -106,6 +110,8 @@ int klassKlass::oop_oop_iterate(oop obj, OopClosure* blk) {
  4037. int size = oop_size(obj);
  4038. Klass* k = Klass::cast(klassOop(obj));
  4039. blk->do_oop(k->adr_super());
  4040. + blk->do_oop(k->adr_old_version());
  4041. + blk->do_oop(k->adr_new_version());
  4042. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  4043. blk->do_oop(k->adr_primary_supers()+i);
  4044. blk->do_oop(k->adr_secondary_super_cache());
  4045. @@ -134,6 +140,10 @@ int klassKlass::oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) {
  4046. oop* adr;
  4047. adr = k->adr_super();
  4048. if (mr.contains(adr)) blk->do_oop(adr);
  4049. + adr = k->adr_old_version();
  4050. + if (mr.contains(adr)) blk->do_oop(adr);
  4051. + adr = k->adr_new_version();
  4052. + if (mr.contains(adr)) blk->do_oop(adr);
  4053. for (juint i = 0; i < Klass::primary_super_limit(); i++) {
  4054. adr = k->adr_primary_supers()+i;
  4055. if (mr.contains(adr)) blk->do_oop(adr);
  4056. @@ -147,6 +157,8 @@ int klassKlass::oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) {
  4057. // The following are "weak links" in the perm gen and are
  4058. // treated specially in a later phase of a perm gen collection.
  4059. assert(oop(k)->is_perm(), "should be in perm");
  4060. + assert(oop(k->adr_old_version())->is_perm(), "should be in perm");
  4061. + assert(oop(k->adr_new_version())->is_perm(), "should be in perm");
  4062. assert(oop(k->adr_subklass())->is_perm(), "should be in perm");
  4063. assert(oop(k->adr_next_sibling())->is_perm(), "should be in perm");
  4064. if (blk->should_remember_klasses()
  4065. @@ -167,6 +179,8 @@ int klassKlass::oop_adjust_pointers(oop obj) {
  4066. Klass* k = Klass::cast(klassOop(obj));
  4067. MarkSweep::adjust_pointer(k->adr_super());
  4068. + MarkSweep::adjust_pointer(k->adr_new_version());
  4069. + MarkSweep::adjust_pointer(k->adr_old_version());
  4070. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  4071. MarkSweep::adjust_pointer(k->adr_primary_supers()+i);
  4072. MarkSweep::adjust_pointer(k->adr_secondary_super_cache());
  4073. diff --git a/src/share/vm/oops/klassOop.hpp b/src/share/vm/oops/klassOop.hpp
  4074. index f212fc5..9731a9c 100644
  4075. --- a/src/share/vm/oops/klassOop.hpp
  4076. +++ b/src/share/vm/oops/klassOop.hpp
  4077. @@ -41,8 +41,10 @@ class klassOopDesc : public oopDesc {
  4078. // returns the Klass part containing dispatching behavior
  4079. Klass* klass_part() const { return (Klass*)((address)this + sizeof(klassOopDesc)); }
  4080. - // Convenience wrapper
  4081. + // Convenience wrappers
  4082. inline oop java_mirror() const;
  4083. + inline klassOop old_version() const;
  4084. + inline klassOop new_version() const;
  4085. private:
  4086. // These have no implementation since klassOop should never be accessed in this fashion
  4087. diff --git a/src/share/vm/oops/klassVtable.cpp b/src/share/vm/oops/klassVtable.cpp
  4088. index ff22444..8d39611 100644
  4089. --- a/src/share/vm/oops/klassVtable.cpp
  4090. +++ b/src/share/vm/oops/klassVtable.cpp
  4091. @@ -97,7 +97,8 @@ void klassVtable::compute_vtable_size_and_num_mirandas(int &vtable_length,
  4092. vtable_length = Universe::base_vtable_size();
  4093. }
  4094. - if (super == NULL && !Universe::is_bootstrapping() &&
  4095. + // (tw) TODO: Check if we can relax the condition on a fixed base vtable size
  4096. + /*if (super == NULL && !Universe::is_bootstrapping() &&
  4097. vtable_length != Universe::base_vtable_size()) {
  4098. // Someone is attempting to redefine java.lang.Object incorrectly. The
  4099. // only way this should happen is from
  4100. @@ -107,9 +108,9 @@ void klassVtable::compute_vtable_size_and_num_mirandas(int &vtable_length,
  4101. vtable_length = Universe::base_vtable_size();
  4102. }
  4103. assert(super != NULL || vtable_length == Universe::base_vtable_size(),
  4104. - "bad vtable size for class Object");
  4105. + "bad vtable size for class Object");*/
  4106. assert(vtable_length % vtableEntry::size() == 0, "bad vtable length");
  4107. - assert(vtable_length >= Universe::base_vtable_size(), "vtable too small");
  4108. + //assert(vtable_length >= Universe::base_vtable_size(), "vtable too small");
  4109. }
  4110. int klassVtable::index_of(methodOop m, int len) const {
  4111. @@ -678,20 +679,6 @@ bool klassVtable::check_no_old_or_obsolete_entries() {
  4112. return true;
  4113. }
  4114. -void klassVtable::dump_vtable() {
  4115. - tty->print_cr("vtable dump --");
  4116. - for (int i = 0; i < length(); i++) {
  4117. - methodOop m = unchecked_method_at(i);
  4118. - if (m != NULL) {
  4119. - tty->print(" (%5d) ", i);
  4120. - m->access_flags().print_on(tty);
  4121. - tty->print(" -- ");
  4122. - m->print_name(tty);
  4123. - tty->cr();
  4124. - }
  4125. - }
  4126. -}
  4127. -
  4128. // CDS/RedefineClasses support - clear vtables so they can be reinitialized
  4129. void klassVtable::clear_vtable() {
  4130. for (int i = 0; i < _length; i++) table()[i].clear();
  4131. @@ -1262,6 +1249,7 @@ void klassVtable::verify(outputStream* st, bool forced) {
  4132. void klassVtable::verify_against(outputStream* st, klassVtable* vt, int index) {
  4133. vtableEntry* vte = &vt->table()[index];
  4134. + if (vte->method() == NULL || table()[index].method() == NULL) return;
  4135. if (vte->method()->name() != table()[index].method()->name() ||
  4136. vte->method()->signature() != table()[index].method()->signature()) {
  4137. fatal("mismatched name/signature of vtable entries");
  4138. @@ -1281,6 +1269,8 @@ void klassVtable::print() {
  4139. void vtableEntry::verify(klassVtable* vt, outputStream* st) {
  4140. NOT_PRODUCT(FlagSetting fs(IgnoreLockingAssertions, true));
  4141. + // (tw) TODO: Check: Does not hold?
  4142. + if (method() != NULL) {
  4143. assert(method() != NULL, "must have set method");
  4144. method()->verify();
  4145. // we sub_type, because it could be a miranda method
  4146. @@ -1288,7 +1278,13 @@ void vtableEntry::verify(klassVtable* vt, outputStream* st) {
  4147. #ifndef PRODUCT
  4148. print();
  4149. #endif
  4150. - fatal(err_msg("vtableEntry " PTR_FORMAT ": method is from subclass", this));
  4151. + klassOop first_klass = vt->klass()();
  4152. + klassOop second_klass = method()->method_holder();
  4153. + // (tw) the following fatal does not work for old versions of classes
  4154. + if (first_klass->klass_part()->is_newest_version()) {
  4155. + //fatal1("vtableEntry %#lx: method is from subclass", this);
  4156. + }
  4157. + }
  4158. }
  4159. }
  4160. @@ -1296,7 +1292,7 @@ void vtableEntry::verify(klassVtable* vt, outputStream* st) {
  4161. void vtableEntry::print() {
  4162. ResourceMark rm;
  4163. - tty->print("vtableEntry %s: ", method()->name()->as_C_string());
  4164. + tty->print("vtableEntry %s: ", (method() == NULL) ? "null" : method()->name()->as_C_string());
  4165. if (Verbose) {
  4166. tty->print("m %#lx ", (address)method());
  4167. }
  4168. @@ -1363,6 +1359,33 @@ void klassVtable::print_statistics() {
  4169. tty->print_cr("%6d bytes total", total);
  4170. }
  4171. +bool klassVtable::check_no_old_entries() {
  4172. + // Check that there really is no entry
  4173. + for (int i = 0; i < length(); i++) {
  4174. + methodOop m = unchecked_method_at(i);
  4175. + if (m != NULL) {
  4176. + if (m->is_old() || !m->method_holder()->klass_part()->is_newest_version()) {
  4177. + return false;
  4178. + }
  4179. + }
  4180. + }
  4181. + return true;
  4182. +}
  4183. +
  4184. +void klassVtable::dump_vtable() {
  4185. + tty->print_cr("vtable dump --");
  4186. + for (int i = 0; i < length(); i++) {
  4187. + methodOop m = unchecked_method_at(i);
  4188. + if (m != NULL) {
  4189. + tty->print(" (%5d) ", i);
  4190. + m->access_flags().print_on(tty);
  4191. + tty->print(" -- ");
  4192. + m->print_name(tty);
  4193. + tty->cr();
  4194. + }
  4195. + }
  4196. +}
  4197. +
  4198. int klassItable::_total_classes; // Total no. of classes with itables
  4199. long klassItable::_total_size; // Total no. of bytes used for itables
  4200. diff --git a/src/share/vm/oops/klassVtable.hpp b/src/share/vm/oops/klassVtable.hpp
  4201. index 405b0c7..0c8d2f7 100644
  4202. --- a/src/share/vm/oops/klassVtable.hpp
  4203. +++ b/src/share/vm/oops/klassVtable.hpp
  4204. @@ -100,6 +100,7 @@ class klassVtable : public ResourceObj {
  4205. int methods_length, bool * trace_name_printed);
  4206. bool check_no_old_or_obsolete_entries();
  4207. void dump_vtable();
  4208. + bool check_no_old_entries();
  4209. // Garbage collection
  4210. void oop_follow_contents();
  4211. diff --git a/src/share/vm/oops/methodKlass.cpp b/src/share/vm/oops/methodKlass.cpp
  4212. index 75d0b09..f1b7d2f 100644
  4213. --- a/src/share/vm/oops/methodKlass.cpp
  4214. +++ b/src/share/vm/oops/methodKlass.cpp
  4215. @@ -93,6 +93,10 @@ methodOop methodKlass::allocate(constMethodHandle xconst,
  4216. m->set_adapter_entry(NULL);
  4217. m->clear_code(); // from_c/from_i get set to c2i/i2i
  4218. + m->set_forward_method(NULL);
  4219. + m->set_new_version(NULL);
  4220. + m->set_old_version(NULL);
  4221. +
  4222. if (access_flags.is_native()) {
  4223. m->clear_native_function();
  4224. m->set_signature_handler(NULL);
  4225. @@ -122,6 +126,9 @@ void methodKlass::oop_follow_contents(oop obj) {
  4226. // Performance tweak: We skip iterating over the klass pointer since we
  4227. // know that Universe::methodKlassObj never moves.
  4228. MarkSweep::mark_and_push(m->adr_constMethod());
  4229. + MarkSweep::mark_and_push(m->adr_forward_method());
  4230. + MarkSweep::mark_and_push(m->adr_new_version());
  4231. + MarkSweep::mark_and_push(m->adr_old_version());
  4232. if (m->method_data() != NULL) {
  4233. MarkSweep::mark_and_push(m->adr_method_data());
  4234. }
  4235. @@ -135,6 +142,9 @@ void methodKlass::oop_follow_contents(ParCompactionManager* cm,
  4236. // Performance tweak: We skip iterating over the klass pointer since we
  4237. // know that Universe::methodKlassObj never moves.
  4238. PSParallelCompact::mark_and_push(cm, m->adr_constMethod());
  4239. + PSParallelCompact::mark_and_push(cm, m->adr_forward_method());
  4240. + PSParallelCompact::mark_and_push(cm, m->adr_new_version());
  4241. + PSParallelCompact::mark_and_push(cm, m->adr_old_version());
  4242. #ifdef COMPILER2
  4243. if (m->method_data() != NULL) {
  4244. PSParallelCompact::mark_and_push(cm, m->adr_method_data());
  4245. @@ -152,6 +162,9 @@ int methodKlass::oop_oop_iterate(oop obj, OopClosure* blk) {
  4246. // Performance tweak: We skip iterating over the klass pointer since we
  4247. // know that Universe::methodKlassObj never moves
  4248. blk->do_oop(m->adr_constMethod());
  4249. + blk->do_oop(m->adr_forward_method());
  4250. + blk->do_oop(m->adr_new_version());
  4251. + blk->do_oop(m->adr_old_version());
  4252. if (m->method_data() != NULL) {
  4253. blk->do_oop(m->adr_method_data());
  4254. }
  4255. @@ -170,6 +183,12 @@ int methodKlass::oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) {
  4256. oop* adr;
  4257. adr = m->adr_constMethod();
  4258. if (mr.contains(adr)) blk->do_oop(adr);
  4259. + adr = m->adr_new_version();
  4260. + if (mr.contains(adr)) blk->do_oop(adr);
  4261. + adr = m->adr_forward_method();
  4262. + if (mr.contains(adr)) blk->do_oop(adr);
  4263. + adr = m->adr_old_version();
  4264. + if (mr.contains(adr)) blk->do_oop(adr);
  4265. if (m->method_data() != NULL) {
  4266. adr = m->adr_method_data();
  4267. if (mr.contains(adr)) blk->do_oop(adr);
  4268. @@ -187,6 +206,9 @@ int methodKlass::oop_adjust_pointers(oop obj) {
  4269. // Performance tweak: We skip iterating over the klass pointer since we
  4270. // know that Universe::methodKlassObj never moves.
  4271. MarkSweep::adjust_pointer(m->adr_constMethod());
  4272. + MarkSweep::adjust_pointer(m->adr_forward_method());
  4273. + MarkSweep::adjust_pointer(m->adr_new_version());
  4274. + MarkSweep::adjust_pointer(m->adr_old_version());
  4275. if (m->method_data() != NULL) {
  4276. MarkSweep::adjust_pointer(m->adr_method_data());
  4277. }
  4278. @@ -202,6 +224,9 @@ int methodKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) {
  4279. assert(obj->is_method(), "should be method");
  4280. methodOop m = methodOop(obj);
  4281. PSParallelCompact::adjust_pointer(m->adr_constMethod());
  4282. + PSParallelCompact::adjust_pointer(m->adr_forward_method());
  4283. + PSParallelCompact::adjust_pointer(m->adr_new_version());
  4284. + PSParallelCompact::adjust_pointer(m->adr_old_version());
  4285. #ifdef COMPILER2
  4286. if (m->method_data() != NULL) {
  4287. PSParallelCompact::adjust_pointer(m->adr_method_data());
  4288. @@ -222,7 +247,18 @@ void methodKlass::oop_print_on(oop obj, outputStream* st) {
  4289. methodOop m = methodOop(obj);
  4290. // get the effect of PrintOopAddress, always, for methods:
  4291. st->print_cr(" - this oop: "INTPTR_FORMAT, (intptr_t)m);
  4292. - st->print (" - method holder: "); m->method_holder()->print_value_on(st); st->cr();
  4293. + st->print (" - method holder: "); m->method_holder()->print_value_on(st);
  4294. +
  4295. + if (m->method_holder()->klass_part()->new_version() != NULL) {
  4296. + st->print(" (old)");
  4297. + }
  4298. + st->cr();
  4299. +
  4300. + st->print_cr(" - is obsolete: %d", (int)(m->is_obsolete()));
  4301. + st->print_cr(" - is old: %d", (int)(m->is_old()));
  4302. + st->print_cr(" - new version: "INTPTR_FORMAT" ", (address)(m->new_version()));
  4303. + st->print_cr(" - old version: "INTPTR_FORMAT" ", (address)(m->old_version()));
  4304. + st->print_cr(" - holder revision: %d", m->method_holder()->klass_part()->revision_number());
  4305. st->print (" - constants: "INTPTR_FORMAT" ", (address)m->constants());
  4306. m->constants()->print_value_on(st); st->cr();
  4307. st->print (" - access: 0x%x ", m->access_flags().as_int()); m->access_flags().print_on(st); st->cr();
  4308. diff --git a/src/share/vm/oops/methodOop.cpp b/src/share/vm/oops/methodOop.cpp
  4309. index 4f59d3a..5cdf147 100644
  4310. --- a/src/share/vm/oops/methodOop.cpp
  4311. +++ b/src/share/vm/oops/methodOop.cpp
  4312. @@ -328,6 +328,70 @@ void methodOopDesc::cleanup_inline_caches() {
  4313. }
  4314. +bool methodOopDesc::is_in_code_section(int bci) {
  4315. + // There is no table => every bci is in the code section table.
  4316. + if (!constMethod()->has_code_section_table()) return true;
  4317. +
  4318. + constMethodOop m = constMethod();
  4319. + for (int i = 0; i < m->code_section_entries(); ++i) {
  4320. + u2 new_index = m->code_section_new_index_at(i);
  4321. + u2 length = m->code_section_length_at(i);
  4322. + if (bci >= new_index && bci < new_index + length) {
  4323. + // We are in a specified code section.
  4324. + return true;
  4325. + }
  4326. + }
  4327. +
  4328. + return false;
  4329. +}
  4330. +
  4331. +int methodOopDesc::calculate_forward_bci(int bci, methodOop new_method) {
  4332. + int original_bci = -1;
  4333. + if (constMethod()->has_code_section_table()) {
  4334. + assert(is_in_code_section(bci), "can only forward in section");
  4335. + // First calculate back to original bci.
  4336. + constMethodOop m = constMethod();
  4337. + for (int i = 0; i < m->code_section_entries(); ++i) {
  4338. + u2 new_index = m->code_section_new_index_at(i);
  4339. + u2 original_index = m->code_section_original_index_at(i);
  4340. + u2 length = m->code_section_length_at(i);
  4341. + if (bci >= new_index && bci < new_index + length) {
  4342. + // We are in a specified code section.
  4343. + original_bci = bci - new_index + original_index;
  4344. + break;
  4345. + }
  4346. + }
  4347. + assert (original_bci != -1, "must have been in code section");
  4348. + } else {
  4349. + // No code sections specified => we are in an original method.
  4350. + original_bci = bci;
  4351. + }
  4352. +
  4353. + // We know the original bci => match to new method.
  4354. + int new_bci = -1;
  4355. + if (new_method->constMethod()->has_code_section_table()) {
  4356. + // Map to new bci.
  4357. + constMethodOop m = new_method->constMethod();
  4358. + for (int i = 0; i < m->code_section_entries(); ++i) {
  4359. + u2 new_index = m->code_section_new_index_at(i);
  4360. + u2 original_index = m->code_section_original_index_at(i);
  4361. + u2 length = m->code_section_length_at(i);
  4362. + if (original_bci >= original_index && original_bci < original_index + length) {
  4363. + new_bci = original_bci - original_index + new_index;
  4364. + break;
  4365. + }
  4366. + }
  4367. + assert (new_bci != -1, "must have found new code section");
  4368. +
  4369. + } else {
  4370. + // We are in an original method.
  4371. + new_bci = original_bci;
  4372. + }
  4373. +
  4374. + return new_bci;
  4375. +}
  4376. +
  4377. +
  4378. int methodOopDesc::extra_stack_words() {
  4379. // not an inline function, to avoid a header dependency on Interpreter
  4380. return extra_stack_entries() * Interpreter::stackElementSize;
  4381. @@ -1061,6 +1125,9 @@ methodHandle methodOopDesc::clone_with_new_data(methodHandle m, u_char* new_code
  4382. // Reset correct method/const method, method size, and parameter info
  4383. newm->set_constMethod(newcm);
  4384. + newm->set_forward_method(newm->forward_method());
  4385. + newm->set_new_version(newm->new_version());
  4386. + newm->set_old_version(newm->old_version());
  4387. newm->constMethod()->set_code_size(new_code_length);
  4388. newm->constMethod()->set_constMethod_size(new_const_method_size);
  4389. newm->set_method_size(new_method_size);
  4390. diff --git a/src/share/vm/oops/methodOop.hpp b/src/share/vm/oops/methodOop.hpp
  4391. index 486e106..11e52bb 100644
  4392. --- a/src/share/vm/oops/methodOop.hpp
  4393. +++ b/src/share/vm/oops/methodOop.hpp
  4394. @@ -114,6 +114,11 @@ class methodOopDesc : public oopDesc {
  4395. AccessFlags _access_flags; // Access flags
  4396. int _vtable_index; // vtable index of this method (see VtableIndexFlag)
  4397. // note: can have vtables with >2**16 elements (because of inheritance)
  4398. + // (tw) Newer version of method available?
  4399. + methodOop _forward_method;
  4400. + methodOop _new_version;
  4401. + methodOop _old_version;
  4402. +
  4403. #ifdef CC_INTERP
  4404. int _result_index; // C++ interpreter needs for converting results to/from stack
  4405. #endif
  4406. @@ -175,6 +180,32 @@ class methodOopDesc : public oopDesc {
  4407. int name_index() const { return constMethod()->name_index(); }
  4408. void set_name_index(int index) { constMethod()->set_name_index(index); }
  4409. + methodOop forward_method() const {return _forward_method; }
  4410. + void set_forward_method(methodOop m) { _forward_method = m; }
  4411. + bool has_forward_method() const { return forward_method() != NULL; }
  4412. + methodOop new_version() const {return _new_version; }
  4413. + void set_new_version(methodOop m) { _new_version = m; }
  4414. + methodOop newest_version() { if(_new_version == NULL) return this; else return new_version()->newest_version(); }
  4415. +
  4416. + methodOop old_version() const {return _old_version; };
  4417. + void set_old_version(methodOop m) {
  4418. + if (m == NULL) {
  4419. + _old_version = NULL;
  4420. + return;
  4421. + }
  4422. +
  4423. + assert(_old_version == NULL, "may only be set once");
  4424. + assert(this->code_size() == m->code_size(), "must have same code length");
  4425. + _old_version = m;
  4426. + }
  4427. +
  4428. + methodOop oldest_version() const {
  4429. + if(_old_version == NULL) return (methodOop)this;
  4430. + else {
  4431. + return old_version()->oldest_version();
  4432. + }
  4433. + }
  4434. +
  4435. // signature
  4436. Symbol* signature() const { return constants()->symbol_at(signature_index()); }
  4437. int signature_index() const { return constMethod()->signature_index(); }
  4438. @@ -670,6 +701,10 @@ class methodOopDesc : public oopDesc {
  4439. // Inline cache support
  4440. void cleanup_inline_caches();
  4441. + // (tw) Method forwarding support.
  4442. + bool is_in_code_section(int bci);
  4443. + int calculate_forward_bci(int bci, methodOop new_method);
  4444. +
  4445. // Find if klass for method is loaded
  4446. bool is_klass_loaded_by_klass_index(int klass_index) const;
  4447. bool is_klass_loaded(int refinfo_index, bool must_be_resolved = false) const;
  4448. @@ -734,6 +769,9 @@ class methodOopDesc : public oopDesc {
  4449. // Garbage collection support
  4450. oop* adr_constMethod() const { return (oop*)&_constMethod; }
  4451. + oop* adr_forward_method() const { return (oop*)&_forward_method; }
  4452. + oop* adr_new_version() const { return (oop*)&_new_version; }
  4453. + oop* adr_old_version() const { return (oop*)&_old_version; }
  4454. oop* adr_method_data() const { return (oop*)&_method_data; }
  4455. };
  4456. diff --git a/src/share/vm/oops/oop.hpp b/src/share/vm/oops/oop.hpp
  4457. index 5982c88..4873fca 100644
  4458. --- a/src/share/vm/oops/oop.hpp
  4459. +++ b/src/share/vm/oops/oop.hpp
  4460. @@ -95,6 +95,7 @@ class oopDesc {
  4461. narrowOop* compressed_klass_addr();
  4462. void set_klass(klassOop k);
  4463. + void set_klass_no_check(klassOop k);
  4464. // For klass field compression
  4465. int klass_gap() const;
  4466. @@ -135,6 +136,7 @@ class oopDesc {
  4467. bool is_array() const;
  4468. bool is_objArray() const;
  4469. bool is_klass() const;
  4470. + bool is_instanceKlass() const;
  4471. bool is_thread() const;
  4472. bool is_method() const;
  4473. bool is_constMethod() const;
  4474. diff --git a/src/share/vm/oops/oop.inline.hpp b/src/share/vm/oops/oop.inline.hpp
  4475. index f4eb2f7..0acb346 100644
  4476. --- a/src/share/vm/oops/oop.inline.hpp
  4477. +++ b/src/share/vm/oops/oop.inline.hpp
  4478. @@ -123,6 +123,14 @@ inline void oopDesc::set_klass(klassOop k) {
  4479. }
  4480. }
  4481. +inline void oopDesc::set_klass_no_check(klassOop k) {
  4482. + if (UseCompressedOops) {
  4483. + oop_store_without_check(compressed_klass_addr(), (oop)k);
  4484. + } else {
  4485. + oop_store_without_check(klass_addr(), (oop) k);
  4486. + }
  4487. +}
  4488. +
  4489. inline int oopDesc::klass_gap() const {
  4490. return *(int*)(((intptr_t)this) + klass_gap_offset_in_bytes());
  4491. }
  4492. @@ -156,6 +164,7 @@ inline bool oopDesc::is_objArray() const { return blueprint()->oop_is_
  4493. inline bool oopDesc::is_typeArray() const { return blueprint()->oop_is_typeArray(); }
  4494. inline bool oopDesc::is_javaArray() const { return blueprint()->oop_is_javaArray(); }
  4495. inline bool oopDesc::is_klass() const { return blueprint()->oop_is_klass(); }
  4496. +inline bool oopDesc::is_instanceKlass() const { return blueprint()->oop_is_instanceKlass(); }
  4497. inline bool oopDesc::is_thread() const { return blueprint()->oop_is_thread(); }
  4498. inline bool oopDesc::is_method() const { return blueprint()->oop_is_method(); }
  4499. inline bool oopDesc::is_constMethod() const { return blueprint()->oop_is_constMethod(); }
  4500. diff --git a/src/share/vm/prims/jni.cpp b/src/share/vm/prims/jni.cpp
  4501. index 8d82439..0e95b14 100644
  4502. --- a/src/share/vm/prims/jni.cpp
  4503. +++ b/src/share/vm/prims/jni.cpp
  4504. @@ -406,7 +406,7 @@ JNI_ENTRY(jclass, jni_DefineClass(JNIEnv *env, const char *name, jobject loaderR
  4505. }
  4506. }
  4507. klassOop k = SystemDictionary::resolve_from_stream(class_name, class_loader,
  4508. - Handle(), &st, true,
  4509. + Handle(), &st, true, KlassHandle(),
  4510. CHECK_NULL);
  4511. if (TraceClassResolution && k != NULL) {
  4512. diff --git a/src/share/vm/prims/jvm.cpp b/src/share/vm/prims/jvm.cpp
  4513. index 839c11f..a82f450 100644
  4514. --- a/src/share/vm/prims/jvm.cpp
  4515. +++ b/src/share/vm/prims/jvm.cpp
  4516. @@ -909,7 +909,7 @@ static jclass jvm_define_class_common(JNIEnv *env, const char *name,
  4517. Handle protection_domain (THREAD, JNIHandles::resolve(pd));
  4518. klassOop k = SystemDictionary::resolve_from_stream(class_name, class_loader,
  4519. protection_domain, &st,
  4520. - verify != 0,
  4521. + verify != 0, KlassHandle(),
  4522. CHECK_NULL);
  4523. if (TraceClassResolution && k != NULL) {
  4524. diff --git a/src/share/vm/prims/jvmtiEnv.cpp b/src/share/vm/prims/jvmtiEnv.cpp
  4525. index 4ac6b82..30b8e84 100644
  4526. --- a/src/share/vm/prims/jvmtiEnv.cpp
  4527. +++ b/src/share/vm/prims/jvmtiEnv.cpp
  4528. @@ -290,7 +290,10 @@ JvmtiEnv::RetransformClasses(jint class_count, const jclass* classes) {
  4529. class_definitions[index].klass = jcls;
  4530. }
  4531. VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_retransform);
  4532. - VMThread::execute(&op);
  4533. + {
  4534. + MutexLocker sd_mutex(RedefineClasses_lock);
  4535. + VMThread::execute(&op);
  4536. + }
  4537. return (op.check_error());
  4538. } /* end RetransformClasses */
  4539. @@ -299,9 +302,12 @@ JvmtiEnv::RetransformClasses(jint class_count, const jclass* classes) {
  4540. // class_definitions - pre-checked for NULL
  4541. jvmtiError
  4542. JvmtiEnv::RedefineClasses(jint class_count, const jvmtiClassDefinition* class_definitions) {
  4543. -//TODO: add locking
  4544. +
  4545. VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_redefine);
  4546. - VMThread::execute(&op);
  4547. + {
  4548. + MutexLocker sd_mutex(RedefineClasses_lock);
  4549. + VMThread::execute(&op);
  4550. + }
  4551. return (op.check_error());
  4552. } /* end RedefineClasses */
  4553. diff --git a/src/share/vm/prims/jvmtiExport.cpp b/src/share/vm/prims/jvmtiExport.cpp
  4554. index ec8ede3..2bd5983 100644
  4555. --- a/src/share/vm/prims/jvmtiExport.cpp
  4556. +++ b/src/share/vm/prims/jvmtiExport.cpp
  4557. @@ -2296,7 +2296,7 @@ JvmtiDynamicCodeEventCollector::JvmtiDynamicCodeEventCollector() : _code_blobs(N
  4558. // iterate over any code blob descriptors collected and post a
  4559. // DYNAMIC_CODE_GENERATED event to the profiler.
  4560. JvmtiDynamicCodeEventCollector::~JvmtiDynamicCodeEventCollector() {
  4561. - assert(!JavaThread::current()->owns_locks(), "all locks must be released to post deferred events");
  4562. + assert(!JavaThread::current()->owns_locks_but_redefine_classes_lock(), "all locks must be released to post deferred events");
  4563. // iterate over any code blob descriptors that we collected
  4564. if (_code_blobs != NULL) {
  4565. for (int i=0; i<_code_blobs->length(); i++) {
  4566. diff --git a/src/share/vm/prims/jvmtiImpl.cpp b/src/share/vm/prims/jvmtiImpl.cpp
  4567. index d3fa140..f4f8b57 100644
  4568. --- a/src/share/vm/prims/jvmtiImpl.cpp
  4569. +++ b/src/share/vm/prims/jvmtiImpl.cpp
  4570. @@ -286,6 +286,8 @@ address JvmtiBreakpoint::getBcp() {
  4571. void JvmtiBreakpoint::each_method_version_do(method_action meth_act) {
  4572. ((methodOopDesc*)_method->*meth_act)(_bci);
  4573. + // DCEVM: TODO: Check how we can implement this differently here!
  4574. +
  4575. // add/remove breakpoint to/from versions of the method that
  4576. // are EMCP. Directly or transitively obsolete methods are
  4577. // not saved in the PreviousVersionInfo.
  4578. diff --git a/src/share/vm/prims/jvmtiRedefineClasses.cpp b/src/share/vm/prims/jvmtiRedefineClasses.cpp
  4579. index 606be1c..ef4f380 100644
  4580. --- a/src/share/vm/prims/jvmtiRedefineClasses.cpp
  4581. +++ b/src/share/vm/prims/jvmtiRedefineClasses.cpp
  4582. @@ -1,5 +1,5 @@
  4583. /*
  4584. - * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
  4585. + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  4586. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4587. *
  4588. * This code is free software; you can redistribute it and/or modify it
  4589. @@ -30,581 +30,637 @@
  4590. #include "interpreter/rewriter.hpp"
  4591. #include "memory/gcLocker.hpp"
  4592. #include "memory/universe.inline.hpp"
  4593. -#include "oops/fieldStreams.hpp"
  4594. +#include "memory/cardTableRS.hpp"
  4595. #include "oops/klassVtable.hpp"
  4596. +#include "oops/fieldStreams.hpp"
  4597. #include "prims/jvmtiImpl.hpp"
  4598. #include "prims/jvmtiRedefineClasses.hpp"
  4599. +#include "prims/jvmtiClassFileReconstituter.hpp"
  4600. #include "prims/methodComparator.hpp"
  4601. -#include "prims/methodHandles.hpp"
  4602. #include "runtime/deoptimization.hpp"
  4603. #include "runtime/relocator.hpp"
  4604. #include "utilities/bitMap.inline.hpp"
  4605. +#include "compiler/compileBroker.hpp"
  4606. objArrayOop VM_RedefineClasses::_old_methods = NULL;
  4607. objArrayOop VM_RedefineClasses::_new_methods = NULL;
  4608. -methodOop* VM_RedefineClasses::_matching_old_methods = NULL;
  4609. -methodOop* VM_RedefineClasses::_matching_new_methods = NULL;
  4610. -methodOop* VM_RedefineClasses::_deleted_methods = NULL;
  4611. -methodOop* VM_RedefineClasses::_added_methods = NULL;
  4612. +int* VM_RedefineClasses::_matching_old_methods = NULL;
  4613. +int* VM_RedefineClasses::_matching_new_methods = NULL;
  4614. +int* VM_RedefineClasses::_deleted_methods = NULL;
  4615. +int* VM_RedefineClasses::_added_methods = NULL;
  4616. int VM_RedefineClasses::_matching_methods_length = 0;
  4617. int VM_RedefineClasses::_deleted_methods_length = 0;
  4618. int VM_RedefineClasses::_added_methods_length = 0;
  4619. klassOop VM_RedefineClasses::_the_class_oop = NULL;
  4620. +// Holds the revision number of the current class redefinition
  4621. +int VM_RedefineClasses::_revision_number = -1;
  4622. -VM_RedefineClasses::VM_RedefineClasses(jint class_count,
  4623. - const jvmtiClassDefinition *class_defs,
  4624. - JvmtiClassLoadKind class_load_kind) {
  4625. +VM_RedefineClasses::VM_RedefineClasses(jint class_count, const jvmtiClassDefinition *class_defs, JvmtiClassLoadKind class_load_kind)
  4626. + : VM_GC_Operation(Universe::heap()->total_full_collections(), GCCause::_jvmti_force_gc) {
  4627. + RC_TIMER_START(_timer_total);
  4628. _class_count = class_count;
  4629. _class_defs = class_defs;
  4630. _class_load_kind = class_load_kind;
  4631. - _res = JVMTI_ERROR_NONE;
  4632. + _updated_oops = NULL;
  4633. + _result = JVMTI_ERROR_NONE;
  4634. }
  4635. -bool VM_RedefineClasses::doit_prologue() {
  4636. - if (_class_count == 0) {
  4637. - _res = JVMTI_ERROR_NONE;
  4638. - return false;
  4639. +VM_RedefineClasses::~VM_RedefineClasses() {
  4640. + {
  4641. + MonitorLockerEx ml(RedefinitionSync_lock);
  4642. + Threads::set_wait_at_instrumentation_entry(false);
  4643. + ml.notify_all();
  4644. + }
  4645. +
  4646. + unlock_threads();
  4647. + RC_TIMER_STOP(_timer_total);
  4648. +
  4649. + if (TimeRedefineClasses) {
  4650. + tty->print_cr("Timing Prologue: %d", _timer_prologue.milliseconds());
  4651. + tty->print_cr("Timing Class Loading: %d", _timer_class_loading.milliseconds());
  4652. + tty->print_cr("Timing Waiting for Lock: %d", _timer_wait_for_locks.milliseconds());
  4653. + tty->print_cr("Timing Class Linking: %d", _timer_class_linking.milliseconds());
  4654. + tty->print_cr("Timing Check Type: %d", _timer_check_type.milliseconds());
  4655. + tty->print_cr("Timing Prepare Redefinition: %d", _timer_prepare_redefinition.milliseconds());
  4656. + tty->print_cr("Timing Redefinition GC: %d", _timer_redefinition.milliseconds());
  4657. + tty->print_cr("Timing Epilogue: %d", _timer_vm_op_epilogue.milliseconds());
  4658. + tty->print_cr("------------------------------------------------------------------");
  4659. + tty->print_cr("Total Time: %d", _timer_total.milliseconds());
  4660. }
  4661. - if (_class_defs == NULL) {
  4662. - _res = JVMTI_ERROR_NULL_POINTER;
  4663. - return false;
  4664. +}
  4665. +
  4666. +// Searches for all affected classes and performs a sorting such that a supertype is always before a subtype.
  4667. +jvmtiError VM_RedefineClasses::find_sorted_affected_classes(GrowableArray<instanceKlassHandle> *all_affected_klasses) {
  4668. +
  4669. + // Create array with all classes for which the redefine command was given
  4670. + GrowableArray<instanceKlassHandle> klasses_to_redefine;
  4671. + for (int i=0; i<_class_count; i++) {
  4672. + oop mirror = JNIHandles::resolve_non_null(_class_defs[i].klass);
  4673. + instanceKlassHandle klass_handle(Thread::current(), java_lang_Class::as_klassOop(mirror));
  4674. + klasses_to_redefine.append(klass_handle);
  4675. + assert(klass_handle->new_version() == NULL, "Must be new class");
  4676. }
  4677. - for (int i = 0; i < _class_count; i++) {
  4678. - if (_class_defs[i].klass == NULL) {
  4679. - _res = JVMTI_ERROR_INVALID_CLASS;
  4680. - return false;
  4681. - }
  4682. - if (_class_defs[i].class_byte_count == 0) {
  4683. - _res = JVMTI_ERROR_INVALID_CLASS_FORMAT;
  4684. - return false;
  4685. - }
  4686. - if (_class_defs[i].class_bytes == NULL) {
  4687. - _res = JVMTI_ERROR_NULL_POINTER;
  4688. - return false;
  4689. +
  4690. + // Find classes not directly redefined, but affected by a redefinition (because one of its supertypes is redefined)
  4691. + GrowableArray<instanceKlassHandle> affected_classes;
  4692. + FindAffectedKlassesClosure closure(&klasses_to_redefine, &affected_classes);
  4693. +
  4694. + // Trace affected classes
  4695. + if (RC_TRACE_ENABLED(0x00000001)) {
  4696. + RC_TRACE(0x00000001, ("Klasses affected: %d",
  4697. + affected_classes.length()));
  4698. + for (int i=0; i<affected_classes.length(); i++) {
  4699. + RC_TRACE(0x00000001, ("%s",
  4700. + affected_classes.at(i)->name()->as_C_string()));
  4701. }
  4702. }
  4703. - // Start timer after all the sanity checks; not quite accurate, but
  4704. - // better than adding a bunch of stop() calls.
  4705. - RC_TIMER_START(_timer_vm_op_prologue);
  4706. + // Add the array of affected classes and the array of redefined classes to get a list of all classes that need a redefinition
  4707. + all_affected_klasses->appendAll(&klasses_to_redefine);
  4708. + all_affected_klasses->appendAll(&affected_classes);
  4709. - // We first load new class versions in the prologue, because somewhere down the
  4710. - // call chain it is required that the current thread is a Java thread.
  4711. - _res = load_new_class_versions(Thread::current());
  4712. - if (_res != JVMTI_ERROR_NONE) {
  4713. - // Free os::malloc allocated memory in load_new_class_version.
  4714. - os::free(_scratch_classes);
  4715. - RC_TIMER_STOP(_timer_vm_op_prologue);
  4716. - return false;
  4717. + // Sort the affected klasses such that a supertype is always on a smaller array index than its subtype.
  4718. + jvmtiError result = do_topological_class_sorting(_class_defs, _class_count, &affected_classes, all_affected_klasses, Thread::current());
  4719. + if (RC_TRACE_ENABLED(0x00000001)) {
  4720. + RC_TRACE(0x00000001, ("Redefine order: "));
  4721. + for (int i=0; i<all_affected_klasses->length(); i++) {
  4722. + RC_TRACE(0x00000001, ("%s",
  4723. + all_affected_klasses->at(i)->name()->as_C_string()));
  4724. + }
  4725. }
  4726. - RC_TIMER_STOP(_timer_vm_op_prologue);
  4727. - return true;
  4728. + return result;
  4729. }
  4730. -void VM_RedefineClasses::doit() {
  4731. - Thread *thread = Thread::current();
  4732. +// Searches for the class bytes of the given class and returns them as a byte array.
  4733. +jvmtiError VM_RedefineClasses::find_class_bytes(instanceKlassHandle the_class, const unsigned char **class_bytes, jint *class_byte_count, jboolean *not_changed) {
  4734. - if (UseSharedSpaces) {
  4735. - // Sharing is enabled so we remap the shared readonly space to
  4736. - // shared readwrite, private just in case we need to redefine
  4737. - // a shared class. We do the remap during the doit() phase of
  4738. - // the safepoint to be safer.
  4739. - if (!CompactingPermGenGen::remap_shared_readonly_as_readwrite()) {
  4740. - RC_TRACE_WITH_THREAD(0x00000001, thread,
  4741. - ("failed to remap shared readonly space to readwrite, private"));
  4742. - _res = JVMTI_ERROR_INTERNAL;
  4743. - return;
  4744. + *not_changed = false;
  4745. +
  4746. + // Search for the index in the redefinition array that corresponds to the current class
  4747. + int j;
  4748. + for (j=0; j<_class_count; j++) {
  4749. + oop mirror = JNIHandles::resolve_non_null(_class_defs[j].klass);
  4750. + klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
  4751. + if (the_class_oop == the_class()) {
  4752. + break;
  4753. }
  4754. }
  4755. - for (int i = 0; i < _class_count; i++) {
  4756. - redefine_single_class(_class_defs[i].klass, _scratch_classes[i], thread);
  4757. - }
  4758. - // Disable any dependent concurrent compilations
  4759. - SystemDictionary::notice_modification();
  4760. + if (j == _class_count) {
  4761. - // Set flag indicating that some invariants are no longer true.
  4762. - // See jvmtiExport.hpp for detailed explanation.
  4763. - JvmtiExport::set_has_redefined_a_class();
  4764. + *not_changed = true;
  4765. -// check_class() is optionally called for product bits, but is
  4766. -// always called for non-product bits.
  4767. -#ifdef PRODUCT
  4768. - if (RC_TRACE_ENABLED(0x00004000)) {
  4769. -#endif
  4770. - RC_TRACE_WITH_THREAD(0x00004000, thread, ("calling check_class"));
  4771. - SystemDictionary::classes_do(check_class, thread);
  4772. -#ifdef PRODUCT
  4773. - }
  4774. -#endif
  4775. -}
  4776. + // Redefine with same bytecodes. This is a class that is only indirectly affected by redefinition,
  4777. + // so the user did not specify a different bytecode for that class.
  4778. -void VM_RedefineClasses::doit_epilogue() {
  4779. - // Free os::malloc allocated memory.
  4780. - // The memory allocated in redefine will be free'ed in next VM operation.
  4781. - os::free(_scratch_classes);
  4782. -
  4783. - if (RC_TRACE_ENABLED(0x00000004)) {
  4784. - // Used to have separate timers for "doit" and "all", but the timer
  4785. - // overhead skewed the measurements.
  4786. - jlong doit_time = _timer_rsc_phase1.milliseconds() +
  4787. - _timer_rsc_phase2.milliseconds();
  4788. - jlong all_time = _timer_vm_op_prologue.milliseconds() + doit_time;
  4789. -
  4790. - RC_TRACE(0x00000004, ("vm_op: all=" UINT64_FORMAT
  4791. - " prologue=" UINT64_FORMAT " doit=" UINT64_FORMAT, all_time,
  4792. - _timer_vm_op_prologue.milliseconds(), doit_time));
  4793. - RC_TRACE(0x00000004,
  4794. - ("redefine_single_class: phase1=" UINT64_FORMAT " phase2=" UINT64_FORMAT,
  4795. - _timer_rsc_phase1.milliseconds(), _timer_rsc_phase2.milliseconds()));
  4796. + if (the_class->get_cached_class_file_bytes() == NULL) {
  4797. + // not cached, we need to reconstitute the class file from VM representation
  4798. + constantPoolHandle constants(Thread::current(), the_class->constants());
  4799. + ObjectLocker ol(constants, Thread::current()); // lock constant pool while we query it
  4800. +
  4801. + JvmtiClassFileReconstituter reconstituter(the_class);
  4802. + if (reconstituter.get_error() != JVMTI_ERROR_NONE) {
  4803. + return reconstituter.get_error();
  4804. + }
  4805. +
  4806. + *class_byte_count = (jint)reconstituter.class_file_size();
  4807. + *class_bytes = (unsigned char*)reconstituter.class_file_bytes();
  4808. +
  4809. + } else {
  4810. +
  4811. + // it is cached, get it from the cache
  4812. + *class_byte_count = the_class->get_cached_class_file_len();
  4813. + *class_bytes = the_class->get_cached_class_file_bytes();
  4814. + }
  4815. +
  4816. + } else {
  4817. +
  4818. + // Redefine with bytecodes at index j
  4819. + *class_bytes = _class_defs[j].class_bytes;
  4820. + *class_byte_count = _class_defs[j].class_byte_count;
  4821. }
  4822. +
  4823. + return JVMTI_ERROR_NONE;
  4824. }
  4825. -bool VM_RedefineClasses::is_modifiable_class(oop klass_mirror) {
  4826. - // classes for primitives cannot be redefined
  4827. - if (java_lang_Class::is_primitive(klass_mirror)) {
  4828. +// Prologue of the VM operation, called on the Java thread in parallel to normal program execution
  4829. +bool VM_RedefineClasses::doit_prologue() {
  4830. +
  4831. + _revision_number++;
  4832. + RC_TRACE(0x00000001, ("Redefinition with revision number %d started!", _revision_number));
  4833. +
  4834. + assert(Thread::current()->is_Java_thread(), "must be Java thread");
  4835. + RC_TIMER_START(_timer_prologue);
  4836. +
  4837. + if (!check_arguments()) {
  4838. + RC_TIMER_STOP(_timer_prologue);
  4839. return false;
  4840. }
  4841. - klassOop the_class_oop = java_lang_Class::as_klassOop(klass_mirror);
  4842. - // classes for arrays cannot be redefined
  4843. - if (the_class_oop == NULL || !Klass::cast(the_class_oop)->oop_is_instance()) {
  4844. +
  4845. + // We first load new class versions in the prologue, because somewhere down the
  4846. + // call chain it is required that the current thread is a Java thread.
  4847. + _new_classes = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<instanceKlassHandle>(5, true);
  4848. + _result = load_new_class_versions(Thread::current());
  4849. +
  4850. + RC_TRACE(0x00000001, ("Loaded new class versions!"));
  4851. + if (_result != JVMTI_ERROR_NONE) {
  4852. + RC_TRACE(0x00000001, ("error occured: %d!", _result));
  4853. + delete _new_classes;
  4854. + _new_classes = NULL;
  4855. + RC_TIMER_STOP(_timer_prologue);
  4856. return false;
  4857. }
  4858. +
  4859. + RC_TRACE(0x00000001, ("nearly finished"));
  4860. + VM_GC_Operation::doit_prologue();
  4861. + RC_TIMER_STOP(_timer_prologue);
  4862. + RC_TRACE(0x00000001, ("doit_prologue finished!"));
  4863. return true;
  4864. }
  4865. -// Append the current entry at scratch_i in scratch_cp to *merge_cp_p
  4866. -// where the end of *merge_cp_p is specified by *merge_cp_length_p. For
  4867. -// direct CP entries, there is just the current entry to append. For
  4868. -// indirect and double-indirect CP entries, there are zero or more
  4869. -// referenced CP entries along with the current entry to append.
  4870. -// Indirect and double-indirect CP entries are handled by recursive
  4871. -// calls to append_entry() as needed. The referenced CP entries are
  4872. -// always appended to *merge_cp_p before the referee CP entry. These
  4873. -// referenced CP entries may already exist in *merge_cp_p in which case
  4874. -// there is nothing extra to append and only the current entry is
  4875. -// appended.
  4876. -void VM_RedefineClasses::append_entry(constantPoolHandle scratch_cp,
  4877. - int scratch_i, constantPoolHandle *merge_cp_p, int *merge_cp_length_p,
  4878. - TRAPS) {
  4879. -
  4880. - // append is different depending on entry tag type
  4881. - switch (scratch_cp->tag_at(scratch_i).value()) {
  4882. -
  4883. - // The old verifier is implemented outside the VM. It loads classes,
  4884. - // but does not resolve constant pool entries directly so we never
  4885. - // see Class entries here with the old verifier. Similarly the old
  4886. - // verifier does not like Class entries in the input constant pool.
  4887. - // The split-verifier is implemented in the VM so it can optionally
  4888. - // and directly resolve constant pool entries to load classes. The
  4889. - // split-verifier can accept either Class entries or UnresolvedClass
  4890. - // entries in the input constant pool. We revert the appended copy
  4891. - // back to UnresolvedClass so that either verifier will be happy
  4892. - // with the constant pool entry.
  4893. - case JVM_CONSTANT_Class:
  4894. - {
  4895. - // revert the copy to JVM_CONSTANT_UnresolvedClass
  4896. - (*merge_cp_p)->unresolved_klass_at_put(*merge_cp_length_p,
  4897. - scratch_cp->klass_name_at(scratch_i));
  4898. -
  4899. - if (scratch_i != *merge_cp_length_p) {
  4900. - // The new entry in *merge_cp_p is at a different index than
  4901. - // the new entry in scratch_cp so we need to map the index values.
  4902. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  4903. - }
  4904. - (*merge_cp_length_p)++;
  4905. - } break;
  4906. -
  4907. - // these are direct CP entries so they can be directly appended,
  4908. - // but double and long take two constant pool entries
  4909. - case JVM_CONSTANT_Double: // fall through
  4910. - case JVM_CONSTANT_Long:
  4911. - {
  4912. - constantPoolOopDesc::copy_entry_to(scratch_cp, scratch_i, *merge_cp_p, *merge_cp_length_p,
  4913. - THREAD);
  4914. -
  4915. - if (scratch_i != *merge_cp_length_p) {
  4916. - // The new entry in *merge_cp_p is at a different index than
  4917. - // the new entry in scratch_cp so we need to map the index values.
  4918. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  4919. - }
  4920. - (*merge_cp_length_p) += 2;
  4921. - } break;
  4922. -
  4923. - // these are direct CP entries so they can be directly appended
  4924. - case JVM_CONSTANT_Float: // fall through
  4925. - case JVM_CONSTANT_Integer: // fall through
  4926. - case JVM_CONSTANT_Utf8: // fall through
  4927. -
  4928. - // This was an indirect CP entry, but it has been changed into
  4929. - // an interned string so this entry can be directly appended.
  4930. - case JVM_CONSTANT_String: // fall through
  4931. -
  4932. - // These were indirect CP entries, but they have been changed into
  4933. - // Symbol*s so these entries can be directly appended.
  4934. - case JVM_CONSTANT_UnresolvedClass: // fall through
  4935. - case JVM_CONSTANT_UnresolvedString:
  4936. - {
  4937. - constantPoolOopDesc::copy_entry_to(scratch_cp, scratch_i, *merge_cp_p, *merge_cp_length_p,
  4938. - THREAD);
  4939. +// Checks basic properties of the arguments of the redefinition command.
  4940. +bool VM_RedefineClasses::check_arguments() {
  4941. +
  4942. + if (_class_count == 0) RC_ABORT(JVMTI_ERROR_NONE);
  4943. + if (_class_defs == NULL) RC_ABORT(JVMTI_ERROR_NULL_POINTER);
  4944. + for (int i = 0; i < _class_count; i++) {
  4945. + if (_class_defs[i].klass == NULL) RC_ABORT(JVMTI_ERROR_INVALID_CLASS);
  4946. + if (_class_defs[i].class_byte_count == 0) RC_ABORT(JVMTI_ERROR_INVALID_CLASS_FORMAT);
  4947. + if (_class_defs[i].class_bytes == NULL) RC_ABORT(JVMTI_ERROR_NULL_POINTER);
  4948. + }
  4949. +
  4950. + return true;
  4951. +}
  4952. +
  4953. +jvmtiError VM_RedefineClasses::check_exception() const {
  4954. + Thread* THREAD = Thread::current();
  4955. + if (HAS_PENDING_EXCEPTION) {
  4956. +
  4957. + Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  4958. + RC_TRACE(0x00000001, ("parse_stream exception: '%s'",
  4959. + ex_name->as_C_string()));
  4960. + if (TraceRedefineClasses >= 1) {
  4961. + java_lang_Throwable::print(PENDING_EXCEPTION, tty);
  4962. + tty->print_cr("");
  4963. + }
  4964. + CLEAR_PENDING_EXCEPTION;
  4965. +
  4966. + if (ex_name == vmSymbols::java_lang_UnsupportedClassVersionError()) {
  4967. + return JVMTI_ERROR_UNSUPPORTED_VERSION;
  4968. + } else if (ex_name == vmSymbols::java_lang_ClassFormatError()) {
  4969. + return JVMTI_ERROR_INVALID_CLASS_FORMAT;
  4970. + } else if (ex_name == vmSymbols::java_lang_ClassCircularityError()) {
  4971. + return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  4972. + } else if (ex_name == vmSymbols::java_lang_NoClassDefFoundError()) {
  4973. + // The message will be "XXX (wrong name: YYY)"
  4974. + return JVMTI_ERROR_NAMES_DONT_MATCH;
  4975. + } else if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  4976. + return JVMTI_ERROR_OUT_OF_MEMORY;
  4977. + } else {
  4978. + // Just in case more exceptions can be thrown..
  4979. + return JVMTI_ERROR_FAILS_VERIFICATION;
  4980. + }
  4981. + }
  4982. +
  4983. + return JVMTI_ERROR_NONE;
  4984. +}
  4985. +
  4986. +// Loads all new class versions and stores the instanceKlass handles in an array.
  4987. +jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) {
  4988. +
  4989. + ResourceMark rm(THREAD);
  4990. +
  4991. + RC_TRACE(0x00000001, ("==================================================================="));
  4992. + RC_TRACE(0x00000001, ("load new class versions (%d)",
  4993. + _class_count));
  4994. +
  4995. + // Retrieve an array of all classes that need to be redefined
  4996. + GrowableArray<instanceKlassHandle> all_affected_klasses;
  4997. + jvmtiError err = find_sorted_affected_classes(&all_affected_klasses);
  4998. + if (err != JVMTI_ERROR_NONE) {
  4999. + RC_TRACE(0x00000001, ("Error finding sorted affected classes: %d",
  5000. + (int)err));
  5001. + return err;
  5002. + }
  5003. +
  5004. +
  5005. + JvmtiThreadState *state = JvmtiThreadState::state_for(JavaThread::current());
  5006. +
  5007. + _max_redefinition_flags = Klass::NoRedefinition;
  5008. + jvmtiError result = JVMTI_ERROR_NONE;
  5009. +
  5010. + for (int i=0; i<all_affected_klasses.length(); i++) {
  5011. + RC_TRACE(0x00000002, ("Processing affected class %d of %d",
  5012. + i+1, all_affected_klasses.length()));
  5013. +
  5014. + instanceKlassHandle the_class = all_affected_klasses.at(i);
  5015. + RC_TRACE(0x00000002, ("name=%s",
  5016. + the_class->name()->as_C_string()));
  5017. +
  5018. + the_class->link_class(THREAD);
  5019. + result = check_exception();
  5020. + if (result != JVMTI_ERROR_NONE) break;
  5021. +
  5022. + // Find new class bytes
  5023. + const unsigned char* class_bytes;
  5024. + jint class_byte_count;
  5025. + jvmtiError error;
  5026. + jboolean not_changed;
  5027. + if ((error = find_class_bytes(the_class, &class_bytes, &class_byte_count, &not_changed)) != JVMTI_ERROR_NONE) {
  5028. + RC_TRACE(0x00000001, ("Error finding class bytes: %d",
  5029. + (int)error));
  5030. + result = error;
  5031. + break;
  5032. + }
  5033. + assert(class_bytes != NULL && class_byte_count != 0, "Class bytes defined at this point!");
  5034. +
  5035. +
  5036. + // Set redefined class handle in JvmtiThreadState class.
  5037. + // This redefined class is sent to agent event handler for class file
  5038. + // load hook event.
  5039. + state->set_class_being_redefined(&the_class, _class_load_kind);
  5040. +
  5041. + RC_TRACE(0x00000002, ("Before resolving from stream"));
  5042. +
  5043. + RC_TIMER_STOP(_timer_prologue);
  5044. + RC_TIMER_START(_timer_class_loading);
  5045. +
  5046. +
  5047. + // Parse the stream.
  5048. + Handle the_class_loader(THREAD, the_class->class_loader());
  5049. + Handle protection_domain(THREAD, the_class->protection_domain());
  5050. + Symbol* the_class_sym = the_class->name();
  5051. + ClassFileStream st((u1*) class_bytes, class_byte_count, (char *)"__VM_RedefineClasses__");
  5052. + instanceKlassHandle new_class(THREAD, SystemDictionary::resolve_from_stream(the_class_sym,
  5053. + the_class_loader,
  5054. + protection_domain,
  5055. + &st,
  5056. + true,
  5057. + the_class,
  5058. + THREAD));
  5059. +
  5060. + not_changed = false;
  5061. +
  5062. + RC_TIMER_STOP(_timer_class_loading);
  5063. + RC_TIMER_START(_timer_prologue);
  5064. +
  5065. + RC_TRACE(0x00000002, ("After resolving class from stream!"));
  5066. + // Clear class_being_redefined just to be sure.
  5067. + state->clear_class_being_redefined();
  5068. +
  5069. + result = check_exception();
  5070. + if (result != JVMTI_ERROR_NONE) break;
  5071. +
  5072. +#ifdef ASSERT
  5073. +
  5074. + assert(new_class() != NULL, "Class could not be loaded!");
  5075. + assert(new_class() != the_class(), "must be different");
  5076. + assert(new_class->new_version() == NULL && new_class->old_version() != NULL, "");
  5077. +
  5078. +
  5079. + objArrayOop k_interfaces = new_class->local_interfaces();
  5080. + for (int j=0; j<k_interfaces->length(); j++) {
  5081. + assert(((klassOop)k_interfaces->obj_at(j))->klass_part()->is_newest_version(), "just checking");
  5082. + }
  5083. +
  5084. + if (!THREAD->is_Compiler_thread()) {
  5085. +
  5086. + RC_TRACE(0x00000002, ("name=%s loader="INTPTR_FORMAT" protection_domain="INTPTR_FORMAT" ",
  5087. + the_class->name()->as_C_string(),
  5088. + (address)(the_class->class_loader()),
  5089. + (address)(the_class->protection_domain())));
  5090. + // If we are on the compiler thread, we must not try to resolve a class.
  5091. + klassOop systemLookup = SystemDictionary::resolve_or_null(the_class->name(), the_class->class_loader(), the_class->protection_domain(), THREAD);
  5092. +
  5093. + if (systemLookup != NULL) {
  5094. + assert(systemLookup == new_class->old_version(), "Old class must be in system dictionary!");
  5095. +
  5096. +
  5097. + Klass *subklass = new_class()->klass_part()->subklass();
  5098. + while (subklass != NULL) {
  5099. + assert(subklass->new_version() == NULL, "Most recent version of class!");
  5100. + subklass = subklass->next_sibling();
  5101. + }
  5102. + } else {
  5103. + // This can happen for reflection generated classes.. ?
  5104. + CLEAR_PENDING_EXCEPTION;
  5105. + }
  5106. + }
  5107. - if (scratch_i != *merge_cp_length_p) {
  5108. - // The new entry in *merge_cp_p is at a different index than
  5109. - // the new entry in scratch_cp so we need to map the index values.
  5110. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5111. +#endif
  5112. +
  5113. + if (RC_TRACE_ENABLED(0x00000001)) {
  5114. + if (new_class->layout_helper() != the_class->layout_helper()) {
  5115. + RC_TRACE(0x00000001, ("Instance size change for class %s: new=%d old=%d",
  5116. + new_class->name()->as_C_string(),
  5117. + new_class->layout_helper(),
  5118. + the_class->layout_helper()));
  5119. }
  5120. - (*merge_cp_length_p)++;
  5121. - } break;
  5122. + }
  5123. - // this is an indirect CP entry so it needs special handling
  5124. - case JVM_CONSTANT_NameAndType:
  5125. - {
  5126. - int name_ref_i = scratch_cp->name_ref_index_at(scratch_i);
  5127. - int new_name_ref_i = find_or_append_indirect_entry(scratch_cp, name_ref_i, merge_cp_p,
  5128. - merge_cp_length_p, THREAD);
  5129. -
  5130. - int signature_ref_i = scratch_cp->signature_ref_index_at(scratch_i);
  5131. - int new_signature_ref_i = find_or_append_indirect_entry(scratch_cp, signature_ref_i,
  5132. - merge_cp_p, merge_cp_length_p,
  5133. - THREAD);
  5134. -
  5135. - // If the referenced entries already exist in *merge_cp_p, then
  5136. - // both new_name_ref_i and new_signature_ref_i will both be 0.
  5137. - // In that case, all we are appending is the current entry.
  5138. - if (new_name_ref_i != name_ref_i) {
  5139. - RC_TRACE(0x00080000,
  5140. - ("NameAndType entry@%d name_ref_index change: %d to %d",
  5141. - *merge_cp_length_p, name_ref_i, new_name_ref_i));
  5142. - }
  5143. - if (new_signature_ref_i != signature_ref_i) {
  5144. - RC_TRACE(0x00080000,
  5145. - ("NameAndType entry@%d signature_ref_index change: %d to %d",
  5146. - *merge_cp_length_p, signature_ref_i, new_signature_ref_i));
  5147. - }
  5148. -
  5149. - (*merge_cp_p)->name_and_type_at_put(*merge_cp_length_p,
  5150. - new_name_ref_i, new_signature_ref_i);
  5151. - if (scratch_i != *merge_cp_length_p) {
  5152. - // The new entry in *merge_cp_p is at a different index than
  5153. - // the new entry in scratch_cp so we need to map the index values.
  5154. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5155. - }
  5156. - (*merge_cp_length_p)++;
  5157. - } break;
  5158. -
  5159. - // this is a double-indirect CP entry so it needs special handling
  5160. - case JVM_CONSTANT_Fieldref: // fall through
  5161. - case JVM_CONSTANT_InterfaceMethodref: // fall through
  5162. - case JVM_CONSTANT_Methodref:
  5163. - {
  5164. - int klass_ref_i = scratch_cp->uncached_klass_ref_index_at(scratch_i);
  5165. - int new_klass_ref_i = find_or_append_indirect_entry(scratch_cp, klass_ref_i,
  5166. - merge_cp_p, merge_cp_length_p, THREAD);
  5167. - int name_and_type_ref_i = scratch_cp->uncached_name_and_type_ref_index_at(scratch_i);
  5168. - int new_name_and_type_ref_i = find_or_append_indirect_entry(scratch_cp, name_and_type_ref_i,
  5169. - merge_cp_p, merge_cp_length_p, THREAD);
  5170. -
  5171. - const char *entry_name;
  5172. - switch (scratch_cp->tag_at(scratch_i).value()) {
  5173. - case JVM_CONSTANT_Fieldref:
  5174. - entry_name = "Fieldref";
  5175. - (*merge_cp_p)->field_at_put(*merge_cp_length_p, new_klass_ref_i,
  5176. - new_name_and_type_ref_i);
  5177. - break;
  5178. - case JVM_CONSTANT_InterfaceMethodref:
  5179. - entry_name = "IFMethodref";
  5180. - (*merge_cp_p)->interface_method_at_put(*merge_cp_length_p,
  5181. - new_klass_ref_i, new_name_and_type_ref_i);
  5182. - break;
  5183. - case JVM_CONSTANT_Methodref:
  5184. - entry_name = "Methodref";
  5185. - (*merge_cp_p)->method_at_put(*merge_cp_length_p, new_klass_ref_i,
  5186. - new_name_and_type_ref_i);
  5187. - break;
  5188. - default:
  5189. - guarantee(false, "bad switch");
  5190. + // Set the new version of the class
  5191. + new_class->set_revision_number(_revision_number);
  5192. + new_class->set_redefinition_index(i);
  5193. + the_class->set_new_version(new_class());
  5194. + _new_classes->append(new_class);
  5195. +
  5196. + assert(new_class->new_version() == NULL, "");
  5197. +
  5198. + int redefinition_flags = Klass::NoRedefinition;
  5199. +
  5200. + if (not_changed) {
  5201. + redefinition_flags = Klass::NoRedefinition;
  5202. + } else if (AllowAdvancedClassRedefinition) {
  5203. + redefinition_flags = calculate_redefinition_flags(new_class);
  5204. + } else {
  5205. + jvmtiError allowed = check_redefinition_allowed(new_class);
  5206. + if (allowed != JVMTI_ERROR_NONE) {
  5207. + RC_TRACE(0x00000001, ("Error redefinition not allowed!"));
  5208. + result = allowed;
  5209. break;
  5210. }
  5211. + redefinition_flags = Klass::ModifyClass;
  5212. + }
  5213. +
  5214. + if (new_class->super() != NULL) {
  5215. + redefinition_flags = redefinition_flags | new_class->super()->klass_part()->redefinition_flags();
  5216. + }
  5217. +
  5218. + for (int j=0; j<new_class->local_interfaces()->length(); j++) {
  5219. + redefinition_flags = redefinition_flags | ((klassOop)new_class->local_interfaces()->obj_at(j))->klass_part()->redefinition_flags();
  5220. + }
  5221. +
  5222. + new_class->set_redefinition_flags(redefinition_flags);
  5223. - if (klass_ref_i != new_klass_ref_i) {
  5224. - RC_TRACE(0x00080000, ("%s entry@%d class_index changed: %d to %d",
  5225. - entry_name, *merge_cp_length_p, klass_ref_i, new_klass_ref_i));
  5226. + _max_redefinition_flags = _max_redefinition_flags | redefinition_flags;
  5227. +
  5228. + if ((redefinition_flags & Klass::ModifyInstances) != 0) {
  5229. + // TODO: Check if watch access flags of static fields are updated correctly.
  5230. + calculate_instance_update_information(_new_classes->at(i)());
  5231. + } else {
  5232. + assert(new_class->layout_helper() >> 1 == new_class->old_version()->klass_part()->layout_helper() >> 1, "must be equal");
  5233. + assert(new_class->fields()->length() == ((instanceKlass*)new_class->old_version()->klass_part())->fields()->length(), "must be equal");
  5234. +
  5235. + fieldDescriptor fd_new;
  5236. + fieldDescriptor fd_old;
  5237. + for (JavaFieldStream fs(new_class); !fs.done(); fs.next()) {
  5238. + fd_new.initialize(new_class(), fs.index());
  5239. + fd_old.initialize(new_class->old_version(), fs.index());
  5240. + transfer_special_access_flags(&fd_old, &fd_new);
  5241. }
  5242. - if (name_and_type_ref_i != new_name_and_type_ref_i) {
  5243. - RC_TRACE(0x00080000,
  5244. - ("%s entry@%d name_and_type_index changed: %d to %d",
  5245. - entry_name, *merge_cp_length_p, name_and_type_ref_i,
  5246. - new_name_and_type_ref_i));
  5247. + }
  5248. +
  5249. + if (RC_TRACE_ENABLED(0x00000008)) {
  5250. + if (new_class->super() != NULL) {
  5251. + RC_TRACE(0x00000008, ("Super class is %s",
  5252. + new_class->super()->klass_part()->name()->as_C_string()));
  5253. }
  5254. + }
  5255. +
  5256. +#ifdef ASSERT
  5257. + assert(new_class->super() == NULL || new_class->super()->klass_part()->new_version() == NULL, "Super klass must be newest version!");
  5258. +
  5259. + the_class->vtable()->verify(tty);
  5260. + new_class->vtable()->verify(tty);
  5261. +#endif
  5262. +
  5263. + RC_TRACE(0x00000002, ("Verification done!"));
  5264. +
  5265. + if (i == all_affected_klasses.length() - 1) {
  5266. - if (scratch_i != *merge_cp_length_p) {
  5267. - // The new entry in *merge_cp_p is at a different index than
  5268. - // the new entry in scratch_cp so we need to map the index values.
  5269. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5270. + // This was the last class processed => check if additional classes have been loaded in the meantime
  5271. +
  5272. + RC_TIMER_STOP(_timer_prologue);
  5273. + lock_threads();
  5274. + RC_TIMER_START(_timer_prologue);
  5275. +
  5276. + for (int j=0; j<all_affected_klasses.length(); j++) {
  5277. +
  5278. + klassOop initial_klass = all_affected_klasses.at(j)();
  5279. + Klass *initial_subklass = initial_klass->klass_part()->subklass();
  5280. + Klass *cur_klass = initial_subklass;
  5281. + while(cur_klass != NULL) {
  5282. +
  5283. + if(cur_klass->oop_is_instance() && cur_klass->is_newest_version()) {
  5284. + instanceKlassHandle handle(THREAD, cur_klass->as_klassOop());
  5285. + if (!all_affected_klasses.contains(handle)) {
  5286. +
  5287. + int k = i + 1;
  5288. + for (; k<all_affected_klasses.length(); k++) {
  5289. + if (all_affected_klasses.at(k)->is_subtype_of(cur_klass->as_klassOop())) {
  5290. + break;
  5291. + }
  5292. + }
  5293. + all_affected_klasses.insert_before(k, handle);
  5294. + RC_TRACE(0x00000002, ("Adding newly loaded class to affected classes: %s",
  5295. + cur_klass->name()->as_C_string()));
  5296. + }
  5297. + }
  5298. +
  5299. + cur_klass = cur_klass->next_sibling();
  5300. + }
  5301. }
  5302. - (*merge_cp_length_p)++;
  5303. - } break;
  5304. - // this is an indirect CP entry so it needs special handling
  5305. - case JVM_CONSTANT_MethodType:
  5306. - {
  5307. - int ref_i = scratch_cp->method_type_index_at(scratch_i);
  5308. - int new_ref_i = find_or_append_indirect_entry(scratch_cp, ref_i, merge_cp_p,
  5309. - merge_cp_length_p, THREAD);
  5310. - if (new_ref_i != ref_i) {
  5311. - RC_TRACE(0x00080000,
  5312. - ("MethodType entry@%d ref_index change: %d to %d",
  5313. - *merge_cp_length_p, ref_i, new_ref_i));
  5314. - }
  5315. - (*merge_cp_p)->method_type_index_at_put(*merge_cp_length_p, new_ref_i);
  5316. - if (scratch_i != *merge_cp_length_p) {
  5317. - // The new entry in *merge_cp_p is at a different index than
  5318. - // the new entry in scratch_cp so we need to map the index values.
  5319. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5320. - }
  5321. - (*merge_cp_length_p)++;
  5322. - } break;
  5323. -
  5324. - // this is an indirect CP entry so it needs special handling
  5325. - case JVM_CONSTANT_MethodHandle:
  5326. - {
  5327. - int ref_kind = scratch_cp->method_handle_ref_kind_at(scratch_i);
  5328. - int ref_i = scratch_cp->method_handle_index_at(scratch_i);
  5329. - int new_ref_i = find_or_append_indirect_entry(scratch_cp, ref_i, merge_cp_p,
  5330. - merge_cp_length_p, THREAD);
  5331. - if (new_ref_i != ref_i) {
  5332. - RC_TRACE(0x00080000,
  5333. - ("MethodHandle entry@%d ref_index change: %d to %d",
  5334. - *merge_cp_length_p, ref_i, new_ref_i));
  5335. - }
  5336. - (*merge_cp_p)->method_handle_index_at_put(*merge_cp_length_p, ref_kind, new_ref_i);
  5337. - if (scratch_i != *merge_cp_length_p) {
  5338. - // The new entry in *merge_cp_p is at a different index than
  5339. - // the new entry in scratch_cp so we need to map the index values.
  5340. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5341. - }
  5342. - (*merge_cp_length_p)++;
  5343. - } break;
  5344. -
  5345. - // this is an indirect CP entry so it needs special handling
  5346. - case JVM_CONSTANT_InvokeDynamic:
  5347. - {
  5348. - // Index of the bootstrap specifier in the operands array
  5349. - int old_bs_i = scratch_cp->invoke_dynamic_bootstrap_specifier_index(scratch_i);
  5350. - int new_bs_i = find_or_append_operand(scratch_cp, old_bs_i, merge_cp_p,
  5351. - merge_cp_length_p, THREAD);
  5352. - // The bootstrap method NameAndType_info index
  5353. - int old_ref_i = scratch_cp->invoke_dynamic_name_and_type_ref_index_at(scratch_i);
  5354. - int new_ref_i = find_or_append_indirect_entry(scratch_cp, old_ref_i, merge_cp_p,
  5355. - merge_cp_length_p, THREAD);
  5356. - if (new_bs_i != old_bs_i) {
  5357. - RC_TRACE(0x00080000,
  5358. - ("InvokeDynamic entry@%d bootstrap_method_attr_index change: %d to %d",
  5359. - *merge_cp_length_p, old_bs_i, new_bs_i));
  5360. - }
  5361. - if (new_ref_i != old_ref_i) {
  5362. - RC_TRACE(0x00080000,
  5363. - ("InvokeDynamic entry@%d name_and_type_index change: %d to %d",
  5364. - *merge_cp_length_p, old_ref_i, new_ref_i));
  5365. - }
  5366. -
  5367. - (*merge_cp_p)->invoke_dynamic_at_put(*merge_cp_length_p, new_bs_i, new_ref_i);
  5368. - if (scratch_i != *merge_cp_length_p) {
  5369. - // The new entry in *merge_cp_p is at a different index than
  5370. - // the new entry in scratch_cp so we need to map the index values.
  5371. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5372. - }
  5373. - (*merge_cp_length_p)++;
  5374. - } break;
  5375. -
  5376. - // At this stage, Class or UnresolvedClass could be here, but not
  5377. - // ClassIndex
  5378. - case JVM_CONSTANT_ClassIndex: // fall through
  5379. -
  5380. - // Invalid is used as the tag for the second constant pool entry
  5381. - // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should
  5382. - // not be seen by itself.
  5383. - case JVM_CONSTANT_Invalid: // fall through
  5384. -
  5385. - // At this stage, String or UnresolvedString could be here, but not
  5386. - // StringIndex
  5387. - case JVM_CONSTANT_StringIndex: // fall through
  5388. -
  5389. - // At this stage JVM_CONSTANT_UnresolvedClassInError should not be
  5390. - // here
  5391. - case JVM_CONSTANT_UnresolvedClassInError: // fall through
  5392. + int new_count = all_affected_klasses.length() - 1 - i;
  5393. + if (new_count != 0) {
  5394. - default:
  5395. - {
  5396. - // leave a breadcrumb
  5397. - jbyte bad_value = scratch_cp->tag_at(scratch_i).value();
  5398. - ShouldNotReachHere();
  5399. - } break;
  5400. - } // end switch tag value
  5401. -} // end append_entry()
  5402. -
  5403. -
  5404. -int VM_RedefineClasses::find_or_append_indirect_entry(constantPoolHandle scratch_cp,
  5405. - int ref_i, constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS) {
  5406. -
  5407. - int new_ref_i = ref_i;
  5408. - bool match = (ref_i < *merge_cp_length_p) &&
  5409. - scratch_cp->compare_entry_to(ref_i, *merge_cp_p, ref_i, THREAD);
  5410. -
  5411. - if (!match) {
  5412. - // forward reference in *merge_cp_p or not a direct match
  5413. - int found_i = scratch_cp->find_matching_entry(ref_i, *merge_cp_p, THREAD);
  5414. - if (found_i != 0) {
  5415. - guarantee(found_i != ref_i, "compare_entry_to() and find_matching_entry() do not agree");
  5416. - // Found a matching entry somewhere else in *merge_cp_p so just need a mapping entry.
  5417. - new_ref_i = found_i;
  5418. - map_index(scratch_cp, ref_i, found_i);
  5419. - } else {
  5420. - // no match found so we have to append this entry to *merge_cp_p
  5421. - append_entry(scratch_cp, ref_i, merge_cp_p, merge_cp_length_p, THREAD);
  5422. - // The above call to append_entry() can only append one entry
  5423. - // so the post call query of *merge_cp_length_p is only for
  5424. - // the sake of consistency.
  5425. - new_ref_i = *merge_cp_length_p - 1;
  5426. - }
  5427. - }
  5428. -
  5429. - return new_ref_i;
  5430. -} // end find_or_append_indirect_entry()
  5431. -
  5432. -
  5433. -// Append a bootstrap specifier into the merge_cp operands that is semantically equal
  5434. -// to the scratch_cp operands bootstrap specifier passed by the old_bs_i index.
  5435. -// Recursively append new merge_cp entries referenced by the new bootstrap specifier.
  5436. -void VM_RedefineClasses::append_operand(constantPoolHandle scratch_cp, int old_bs_i,
  5437. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS) {
  5438. -
  5439. - int old_ref_i = scratch_cp->operand_bootstrap_method_ref_index_at(old_bs_i);
  5440. - int new_ref_i = find_or_append_indirect_entry(scratch_cp, old_ref_i, merge_cp_p,
  5441. - merge_cp_length_p, THREAD);
  5442. - if (new_ref_i != old_ref_i) {
  5443. - RC_TRACE(0x00080000,
  5444. - ("operands entry@%d bootstrap method ref_index change: %d to %d",
  5445. - _operands_cur_length, old_ref_i, new_ref_i));
  5446. - }
  5447. -
  5448. - typeArrayOop merge_ops = (*merge_cp_p)->operands();
  5449. - int new_bs_i = _operands_cur_length;
  5450. - // We have _operands_cur_length == 0 when the merge_cp operands is empty yet.
  5451. - // However, the operand_offset_at(0) was set in the extend_operands() call.
  5452. - int new_base = (new_bs_i == 0) ? (*merge_cp_p)->operand_offset_at(0)
  5453. - : (*merge_cp_p)->operand_next_offset_at(new_bs_i - 1);
  5454. - int argc = scratch_cp->operand_argument_count_at(old_bs_i);
  5455. -
  5456. - constantPoolOopDesc::operand_offset_at_put(merge_ops, _operands_cur_length, new_base);
  5457. - merge_ops->short_at_put(new_base++, new_ref_i);
  5458. - merge_ops->short_at_put(new_base++, argc);
  5459. -
  5460. - for (int i = 0; i < argc; i++) {
  5461. - int old_arg_ref_i = scratch_cp->operand_argument_index_at(old_bs_i, i);
  5462. - int new_arg_ref_i = find_or_append_indirect_entry(scratch_cp, old_arg_ref_i, merge_cp_p,
  5463. - merge_cp_length_p, THREAD);
  5464. - merge_ops->short_at_put(new_base++, new_arg_ref_i);
  5465. - if (new_arg_ref_i != old_arg_ref_i) {
  5466. - RC_TRACE(0x00080000,
  5467. - ("operands entry@%d bootstrap method argument ref_index change: %d to %d",
  5468. - _operands_cur_length, old_arg_ref_i, new_arg_ref_i));
  5469. - }
  5470. - }
  5471. - if (old_bs_i != _operands_cur_length) {
  5472. - // The bootstrap specifier in *merge_cp_p is at a different index than
  5473. - // that in scratch_cp so we need to map the index values.
  5474. - map_operand_index(old_bs_i, new_bs_i);
  5475. - }
  5476. - _operands_cur_length++;
  5477. -} // end append_operand()
  5478. -
  5479. -
  5480. -int VM_RedefineClasses::find_or_append_operand(constantPoolHandle scratch_cp,
  5481. - int old_bs_i, constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS) {
  5482. -
  5483. - int new_bs_i = old_bs_i; // bootstrap specifier index
  5484. - bool match = (old_bs_i < _operands_cur_length) &&
  5485. - scratch_cp->compare_operand_to(old_bs_i, *merge_cp_p, old_bs_i, THREAD);
  5486. -
  5487. - if (!match) {
  5488. - // forward reference in *merge_cp_p or not a direct match
  5489. - int found_i = scratch_cp->find_matching_operand(old_bs_i, *merge_cp_p,
  5490. - _operands_cur_length, THREAD);
  5491. - if (found_i != -1) {
  5492. - guarantee(found_i != old_bs_i, "compare_operand_to() and find_matching_operand() disagree");
  5493. - // found a matching operand somewhere else in *merge_cp_p so just need a mapping
  5494. - new_bs_i = found_i;
  5495. - map_operand_index(old_bs_i, found_i);
  5496. - } else {
  5497. - // no match found so we have to append this bootstrap specifier to *merge_cp_p
  5498. - append_operand(scratch_cp, old_bs_i, merge_cp_p, merge_cp_length_p, THREAD);
  5499. - new_bs_i = _operands_cur_length - 1;
  5500. + unlock_threads();
  5501. + RC_TRACE(0x00000001, ("Found new number of affected classes: %d",
  5502. + new_count));
  5503. + }
  5504. }
  5505. }
  5506. - return new_bs_i;
  5507. -} // end find_or_append_operand()
  5508. + if (result != JVMTI_ERROR_NONE) {
  5509. + rollback();
  5510. + return result;
  5511. + }
  5512. +
  5513. + RC_TIMER_STOP(_timer_prologue);
  5514. + RC_TIMER_START(_timer_class_linking);
  5515. + // Link and verify new classes _after_ all classes have been updated in the system dictionary!
  5516. + for (int i=0; i<all_affected_klasses.length(); i++) {
  5517. + instanceKlassHandle the_class = all_affected_klasses.at(i);
  5518. + instanceKlassHandle new_class(the_class->new_version());
  5519. +
  5520. + RC_TRACE(0x00000002, ("Linking class %d/%d %s",
  5521. + i,
  5522. + all_affected_klasses.length(),
  5523. + the_class->name()->as_C_string()));
  5524. + new_class->link_class(THREAD);
  5525. -void VM_RedefineClasses::finalize_operands_merge(constantPoolHandle merge_cp, TRAPS) {
  5526. - if (merge_cp->operands() == NULL) {
  5527. - return;
  5528. + result = check_exception();
  5529. + if (result != JVMTI_ERROR_NONE) break;
  5530. }
  5531. - // Shrink the merge_cp operands
  5532. - merge_cp->shrink_operands(_operands_cur_length, CHECK);
  5533. + RC_TIMER_STOP(_timer_class_linking);
  5534. + RC_TIMER_START(_timer_prologue);
  5535. - if (RC_TRACE_ENABLED(0x00040000)) {
  5536. - // don't want to loop unless we are tracing
  5537. - int count = 0;
  5538. - for (int i = 1; i < _operands_index_map_p->length(); i++) {
  5539. - int value = _operands_index_map_p->at(i);
  5540. - if (value != -1) {
  5541. - RC_TRACE_WITH_THREAD(0x00040000, THREAD,
  5542. - ("operands_index_map[%d]: old=%d new=%d", count, i, value));
  5543. - count++;
  5544. - }
  5545. + if (result != JVMTI_ERROR_NONE) {
  5546. + rollback();
  5547. + return result;
  5548. + }
  5549. +
  5550. + RC_TRACE(0x00000002, ("All classes loaded!"));
  5551. +
  5552. +#ifdef ASSERT
  5553. + for (int i=0; i<all_affected_klasses.length(); i++) {
  5554. + instanceKlassHandle the_class = all_affected_klasses.at(i);
  5555. + assert(the_class->new_version() != NULL, "Must have been redefined");
  5556. + instanceKlassHandle new_version = instanceKlassHandle(THREAD, the_class->new_version());
  5557. + assert(new_version->new_version() == NULL, "Must be newest version");
  5558. +
  5559. + if (!(new_version->super() == NULL || new_version->super()->klass_part()->new_version() == NULL)) {
  5560. + new_version()->print();
  5561. + new_version->super()->print();
  5562. + }
  5563. + assert(new_version->super() == NULL || new_version->super()->klass_part()->new_version() == NULL, "Super class must be newest version");
  5564. + }
  5565. +
  5566. + SystemDictionary::classes_do(check_class, THREAD);
  5567. +
  5568. +#endif
  5569. +
  5570. + RC_TRACE(0x00000001, ("Finished verification!"));
  5571. + return JVMTI_ERROR_NONE;
  5572. +}
  5573. +
  5574. +void VM_RedefineClasses::lock_threads() {
  5575. +
  5576. + RC_TIMER_START(_timer_wait_for_locks);
  5577. +
  5578. +
  5579. + JavaThread *javaThread = Threads::first();
  5580. + while (javaThread != NULL) {
  5581. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  5582. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  5583. + compilerThread->set_should_bailout(true);
  5584. + }
  5585. + javaThread = javaThread->next();
  5586. + }
  5587. +
  5588. + int cnt = 0;
  5589. + javaThread = Threads::first();
  5590. + while (javaThread != NULL) {
  5591. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  5592. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  5593. + compilerThread->compilation_mutex()->lock();
  5594. + cnt++;
  5595. + }
  5596. + javaThread = javaThread->next();
  5597. + }
  5598. +
  5599. + RC_TRACE(0x00000002, ("Locked %d compiler threads", cnt));
  5600. +
  5601. + cnt = 0;
  5602. + javaThread = Threads::first();
  5603. + while (javaThread != NULL) {
  5604. + if (javaThread != Thread::current()) {
  5605. + javaThread->redefine_classes_mutex()->lock();
  5606. }
  5607. + javaThread = javaThread->next();
  5608. }
  5609. - // Clean-up
  5610. - _operands_index_map_p = NULL;
  5611. - _operands_cur_length = 0;
  5612. - _operands_index_map_count = 0;
  5613. -} // end finalize_operands_merge()
  5614. -void VM_RedefineClasses::swap_all_method_annotations(int i, int j, instanceKlassHandle scratch_class) {
  5615. - typeArrayOop save;
  5616. + RC_TRACE(0x00000002, ("Locked %d threads", cnt));
  5617. +
  5618. + RC_TIMER_STOP(_timer_wait_for_locks);
  5619. +}
  5620. +
  5621. +void VM_RedefineClasses::unlock_threads() {
  5622. +
  5623. + int cnt = 0;
  5624. + JavaThread *javaThread = Threads::first();
  5625. + Thread *thread = Thread::current();
  5626. + while (javaThread != NULL) {
  5627. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  5628. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  5629. + if (compilerThread->compilation_mutex()->owned_by_self()) {
  5630. + compilerThread->compilation_mutex()->unlock();
  5631. + cnt++;
  5632. + }
  5633. + }
  5634. + javaThread = javaThread->next();
  5635. + }
  5636. - save = scratch_class->get_method_annotations_of(i);
  5637. - scratch_class->set_method_annotations_of(i, scratch_class->get_method_annotations_of(j));
  5638. - scratch_class->set_method_annotations_of(j, save);
  5639. + RC_TRACE(0x00000002, ("Unlocked %d compiler threads", cnt));
  5640. - save = scratch_class->get_method_parameter_annotations_of(i);
  5641. - scratch_class->set_method_parameter_annotations_of(i, scratch_class->get_method_parameter_annotations_of(j));
  5642. - scratch_class->set_method_parameter_annotations_of(j, save);
  5643. + cnt = 0;
  5644. + javaThread = Threads::first();
  5645. + while (javaThread != NULL) {
  5646. + if (javaThread != Thread::current()) {
  5647. + if (javaThread->redefine_classes_mutex()->owned_by_self()) {
  5648. + javaThread->redefine_classes_mutex()->unlock();
  5649. + }
  5650. + }
  5651. + javaThread = javaThread->next();
  5652. + }
  5653. - save = scratch_class->get_method_default_annotations_of(i);
  5654. - scratch_class->set_method_default_annotations_of(i, scratch_class->get_method_default_annotations_of(j));
  5655. - scratch_class->set_method_default_annotations_of(j, save);
  5656. + RC_TRACE(0x00000002, ("Unlocked %d threads", cnt));
  5657. }
  5658. +jvmtiError VM_RedefineClasses::check_redefinition_allowed(instanceKlassHandle scratch_class) {
  5659. +
  5660. +
  5661. +
  5662. + // Compatibility mode => check for unsupported modification
  5663. +
  5664. +
  5665. + assert(scratch_class->old_version() != NULL, "must have old version");
  5666. + instanceKlassHandle the_class(scratch_class->old_version());
  5667. -jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions(
  5668. - instanceKlassHandle the_class,
  5669. - instanceKlassHandle scratch_class) {
  5670. int i;
  5671. // Check superclasses, or rather their names, since superclasses themselves can be
  5672. // requested to replace.
  5673. // Check for NULL superclass first since this might be java.lang.Object
  5674. if (the_class->super() != scratch_class->super() &&
  5675. - (the_class->super() == NULL || scratch_class->super() == NULL ||
  5676. - Klass::cast(the_class->super())->name() !=
  5677. - Klass::cast(scratch_class->super())->name())) {
  5678. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  5679. + (the_class->super() == NULL || scratch_class->super() == NULL ||
  5680. + Klass::cast(the_class->super())->name() !=
  5681. + Klass::cast(scratch_class->super())->name())) {
  5682. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  5683. }
  5684. // Check if the number, names and order of directly implemented interfaces are the same.
  5685. @@ -622,8 +678,8 @@ jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions(
  5686. }
  5687. for (i = 0; i < n_intfs; i++) {
  5688. if (Klass::cast((klassOop) k_interfaces->obj_at(i))->name() !=
  5689. - Klass::cast((klassOop) k_new_interfaces->obj_at(i))->name()) {
  5690. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  5691. + Klass::cast((klassOop) k_new_interfaces->obj_at(i))->name()) {
  5692. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  5693. }
  5694. }
  5695. @@ -772,12 +828,8 @@ jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions(
  5696. idnum_owner->set_method_idnum(new_num);
  5697. }
  5698. k_new_method->set_method_idnum(old_num);
  5699. - swap_all_method_annotations(old_num, new_num, scratch_class);
  5700. }
  5701. }
  5702. - RC_TRACE(0x00008000, ("Method matched: new: %s [%d] == old: %s [%d]",
  5703. - k_new_method->name_and_sig_as_C_string(), ni,
  5704. - k_old_method->name_and_sig_as_C_string(), oi));
  5705. // advance to next pair of methods
  5706. ++oi;
  5707. ++ni;
  5708. @@ -786,11 +838,11 @@ jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions(
  5709. // method added, see if it is OK
  5710. new_flags = (jushort) k_new_method->access_flags().get_flags();
  5711. if ((new_flags & JVM_ACC_PRIVATE) == 0
  5712. - // hack: private should be treated as final, but alas
  5713. - || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5714. - ) {
  5715. - // new methods must be private
  5716. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED;
  5717. + // hack: private should be treated as final, but alas
  5718. + || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5719. + ) {
  5720. + // new methods must be private
  5721. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED;
  5722. }
  5723. {
  5724. u2 num = the_class->next_method_idnum();
  5725. @@ -805,24 +857,19 @@ jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions(
  5726. idnum_owner->set_method_idnum(new_num);
  5727. }
  5728. k_new_method->set_method_idnum(num);
  5729. - swap_all_method_annotations(new_num, num, scratch_class);
  5730. }
  5731. - RC_TRACE(0x00008000, ("Method added: new: %s [%d]",
  5732. - k_new_method->name_and_sig_as_C_string(), ni));
  5733. ++ni; // advance to next new method
  5734. break;
  5735. case deleted:
  5736. // method deleted, see if it is OK
  5737. old_flags = (jushort) k_old_method->access_flags().get_flags();
  5738. if ((old_flags & JVM_ACC_PRIVATE) == 0
  5739. - // hack: private should be treated as final, but alas
  5740. - || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5741. - ) {
  5742. - // deleted methods must be private
  5743. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED;
  5744. + // hack: private should be treated as final, but alas
  5745. + || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5746. + ) {
  5747. + // deleted methods must be private
  5748. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED;
  5749. }
  5750. - RC_TRACE(0x00008000, ("Method deleted: old: %s [%d]",
  5751. - k_old_method->name_and_sig_as_C_string(), oi));
  5752. ++oi; // advance to next old method
  5753. break;
  5754. default:
  5755. @@ -833,2254 +880,1783 @@ jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions(
  5756. return JVMTI_ERROR_NONE;
  5757. }
  5758. +int VM_RedefineClasses::calculate_redefinition_flags(instanceKlassHandle new_class) {
  5759. -// Find new constant pool index value for old constant pool index value
  5760. -// by seaching the index map. Returns zero (0) if there is no mapped
  5761. -// value for the old constant pool index.
  5762. -int VM_RedefineClasses::find_new_index(int old_index) {
  5763. - if (_index_map_count == 0) {
  5764. - // map is empty so nothing can be found
  5765. - return 0;
  5766. - }
  5767. -
  5768. - if (old_index < 1 || old_index >= _index_map_p->length()) {
  5769. - // The old_index is out of range so it is not mapped. This should
  5770. - // not happen in regular constant pool merging use, but it can
  5771. - // happen if a corrupt annotation is processed.
  5772. - return 0;
  5773. - }
  5774. + int result = Klass::NoRedefinition;
  5775. - int value = _index_map_p->at(old_index);
  5776. - if (value == -1) {
  5777. - // the old_index is not mapped
  5778. - return 0;
  5779. - }
  5780. - return value;
  5781. -} // end find_new_index()
  5782. + RC_TRACE(0x00000002, ("Comparing different class versions of class %s",
  5783. + new_class->name()->as_C_string()));
  5784. -// Find new bootstrap specifier index value for old bootstrap specifier index
  5785. -// value by seaching the index map. Returns zero (-1) if there is no mapped
  5786. -// value for the old bootstrap specifier index.
  5787. -int VM_RedefineClasses::find_new_operand_index(int old_index) {
  5788. - if (_operands_index_map_count == 0) {
  5789. - // map is empty so nothing can be found
  5790. - return -1;
  5791. - }
  5792. + assert(new_class->old_version() != NULL, "must have old version");
  5793. + instanceKlassHandle the_class(new_class->old_version());
  5794. - if (old_index == -1 || old_index >= _operands_index_map_p->length()) {
  5795. - // The old_index is out of range so it is not mapped.
  5796. - // This should not happen in regular constant pool merging use.
  5797. - return -1;
  5798. + // Check whether class is in the error init state.
  5799. + if (the_class->is_in_error_state()) {
  5800. + // TBD #5057930: special error code is needed in 1.6
  5801. + //result = Klass::union_redefinition_level(result, Klass::Invalid);
  5802. }
  5803. - int value = _operands_index_map_p->at(old_index);
  5804. -
  5805. - return value;
  5806. -} // end find_new_operand_index()
  5807. -
  5808. -
  5809. -// Returns true if the current mismatch is due to a resolved/unresolved
  5810. -// class pair. Otherwise, returns false.
  5811. -bool VM_RedefineClasses::is_unresolved_class_mismatch(constantPoolHandle cp1,
  5812. - int index1, constantPoolHandle cp2, int index2) {
  5813. + int i;
  5814. - jbyte t1 = cp1->tag_at(index1).value();
  5815. - if (t1 != JVM_CONSTANT_Class && t1 != JVM_CONSTANT_UnresolvedClass) {
  5816. - return false; // wrong entry type; not our special case
  5817. - }
  5818. + //////////////////////////////////////////////////////////////////////////////////////////////////////////
  5819. + // Check superclasses
  5820. + assert(new_class->super() == NULL || new_class->super()->klass_part()->is_newest_version(), "");
  5821. + if (the_class->super() != new_class->super()) {
  5822. + // Super class changed
  5823. +
  5824. + klassOop cur_klass = the_class->super();
  5825. + while (cur_klass != NULL) {
  5826. + if (!new_class->is_subclass_of(cur_klass->klass_part()->newest_version())) {
  5827. + RC_TRACE(0x00000002, ("Removed super class %s",
  5828. + cur_klass->klass_part()->name()->as_C_string()));
  5829. + result = result | Klass::RemoveSuperType | Klass::ModifyInstances | Klass::ModifyClass;
  5830. +
  5831. + if (!cur_klass->klass_part()->has_subtype_changed()) {
  5832. + RC_TRACE(0x00000002, ("Subtype changed of class %s",
  5833. + cur_klass->klass_part()->name()->as_C_string()));
  5834. + cur_klass->klass_part()->set_subtype_changed(true);
  5835. + }
  5836. + }
  5837. - jbyte t2 = cp2->tag_at(index2).value();
  5838. - if (t2 != JVM_CONSTANT_Class && t2 != JVM_CONSTANT_UnresolvedClass) {
  5839. - return false; // wrong entry type; not our special case
  5840. - }
  5841. + cur_klass = cur_klass->klass_part()->super();
  5842. + }
  5843. - if (t1 == t2) {
  5844. - return false; // not a mismatch; not our special case
  5845. + cur_klass = new_class->super();
  5846. + while (cur_klass != NULL) {
  5847. + if (!the_class->is_subclass_of(cur_klass->klass_part()->old_version())) {
  5848. + RC_TRACE(0x00000002, ("Added super class %s",
  5849. + cur_klass->klass_part()->name()->as_C_string()));
  5850. + result = result | Klass::ModifyClass | Klass::ModifyInstances;
  5851. + }
  5852. + cur_klass = cur_klass->klass_part()->super();
  5853. + }
  5854. + }
  5855. +
  5856. + //////////////////////////////////////////////////////////////////////////////////////////////////////////
  5857. + // Check interfaces
  5858. +
  5859. + // Interfaces removed?
  5860. + objArrayOop old_interfaces = the_class->transitive_interfaces();
  5861. + for (i = 0; i<old_interfaces->length(); i++) {
  5862. + instanceKlassHandle old_interface((klassOop)old_interfaces->obj_at(i));
  5863. + if (!new_class->implements_interface_any_version(old_interface())) {
  5864. + result = result | Klass::RemoveSuperType | Klass::ModifyClass;
  5865. + RC_TRACE(0x00000002, ("Removed interface %s",
  5866. + old_interface->name()->as_C_string()));
  5867. +
  5868. + if (!old_interface->has_subtype_changed()) {
  5869. + RC_TRACE(0x00000002, ("Subtype changed of interface %s",
  5870. + old_interface->name()->as_C_string()));
  5871. + old_interface->set_subtype_changed(true);
  5872. + }
  5873. + }
  5874. }
  5875. - char *s1 = cp1->klass_name_at(index1)->as_C_string();
  5876. - char *s2 = cp2->klass_name_at(index2)->as_C_string();
  5877. - if (strcmp(s1, s2) != 0) {
  5878. - return false; // strings don't match; not our special case
  5879. + // Interfaces added?
  5880. + objArrayOop new_interfaces = new_class->transitive_interfaces();
  5881. + for (i = 0; i<new_interfaces->length(); i++) {
  5882. + if (!the_class->implements_interface_any_version((klassOop)new_interfaces->obj_at(i))) {
  5883. + result = result | Klass::ModifyClass;
  5884. + RC_TRACE(0x00000002, ("Added interface %s",
  5885. + ((klassOop)new_interfaces->obj_at(i))->klass_part()->name()->as_C_string()));
  5886. + }
  5887. }
  5888. - return true; // made it through the gauntlet; this is our special case
  5889. -} // end is_unresolved_class_mismatch()
  5890. -
  5891. -// Returns true if the current mismatch is due to a resolved/unresolved
  5892. -// string pair. Otherwise, returns false.
  5893. -bool VM_RedefineClasses::is_unresolved_string_mismatch(constantPoolHandle cp1,
  5894. - int index1, constantPoolHandle cp2, int index2) {
  5895. -
  5896. - jbyte t1 = cp1->tag_at(index1).value();
  5897. - if (t1 != JVM_CONSTANT_String && t1 != JVM_CONSTANT_UnresolvedString) {
  5898. - return false; // wrong entry type; not our special case
  5899. - }
  5900. -
  5901. - jbyte t2 = cp2->tag_at(index2).value();
  5902. - if (t2 != JVM_CONSTANT_String && t2 != JVM_CONSTANT_UnresolvedString) {
  5903. - return false; // wrong entry type; not our special case
  5904. + // Check whether class modifiers are the same.
  5905. + jushort old_flags = (jushort) the_class->access_flags().get_flags();
  5906. + jushort new_flags = (jushort) new_class->access_flags().get_flags();
  5907. + if (old_flags != new_flags) {
  5908. + // TODO (tw): Can this have any effects?
  5909. }
  5910. - if (t1 == t2) {
  5911. - return false; // not a mismatch; not our special case
  5912. - }
  5913. -
  5914. - char *s1 = cp1->string_at_noresolve(index1);
  5915. - char *s2 = cp2->string_at_noresolve(index2);
  5916. - if (strcmp(s1, s2) != 0) {
  5917. - return false; // strings don't match; not our special case
  5918. + // Check if the number, names, types and order of fields declared in these classes
  5919. + // are the same.
  5920. + JavaFieldStream old_fs(the_class);
  5921. + JavaFieldStream new_fs(new_class);
  5922. + for (; !old_fs.done() && !new_fs.done(); old_fs.next(), new_fs.next()) {
  5923. + // access
  5924. + old_flags = old_fs.access_flags().as_short();
  5925. + new_flags = new_fs.access_flags().as_short();
  5926. + if ((old_flags ^ new_flags) & JVM_RECOGNIZED_FIELD_MODIFIERS) {
  5927. + // (tw) Can this have any effects?
  5928. + }
  5929. + // offset
  5930. + if (old_fs.offset() != new_fs.offset()) {
  5931. + result = result | Klass::ModifyInstances;
  5932. + }
  5933. + // name and signature
  5934. + Symbol* name_sym1 = the_class->constants()->symbol_at(old_fs.name_index());
  5935. + Symbol* sig_sym1 = the_class->constants()->symbol_at(old_fs.signature_index());
  5936. + Symbol* name_sym2 = new_class->constants()->symbol_at(new_fs.name_index());
  5937. + Symbol* sig_sym2 = new_class->constants()->symbol_at(new_fs.signature_index());
  5938. + if (name_sym1 != name_sym2 || sig_sym1 != sig_sym2) {
  5939. + result = result | Klass::ModifyInstances;
  5940. + }
  5941. }
  5942. - return true; // made it through the gauntlet; this is our special case
  5943. -} // end is_unresolved_string_mismatch()
  5944. -
  5945. -
  5946. -jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) {
  5947. - // For consistency allocate memory using os::malloc wrapper.
  5948. - _scratch_classes = (instanceKlassHandle *)
  5949. - os::malloc(sizeof(instanceKlassHandle) * _class_count, mtInternal);
  5950. - if (_scratch_classes == NULL) {
  5951. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5952. + if (!old_fs.done() || !new_fs.done()) {
  5953. + result = result | Klass::ModifyInstances;
  5954. }
  5955. - ResourceMark rm(THREAD);
  5956. -
  5957. - JvmtiThreadState *state = JvmtiThreadState::state_for(JavaThread::current());
  5958. - // state can only be NULL if the current thread is exiting which
  5959. - // should not happen since we're trying to do a RedefineClasses
  5960. - guarantee(state != NULL, "exiting thread calling load_new_class_versions");
  5961. - for (int i = 0; i < _class_count; i++) {
  5962. - oop mirror = JNIHandles::resolve_non_null(_class_defs[i].klass);
  5963. - // classes for primitives cannot be redefined
  5964. - if (!is_modifiable_class(mirror)) {
  5965. - return JVMTI_ERROR_UNMODIFIABLE_CLASS;
  5966. - }
  5967. - klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
  5968. - instanceKlassHandle the_class = instanceKlassHandle(THREAD, the_class_oop);
  5969. - Symbol* the_class_sym = the_class->name();
  5970. -
  5971. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5972. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  5973. - ("loading name=%s kind=%d (avail_mem=" UINT64_FORMAT "K)",
  5974. - the_class->external_name(), _class_load_kind,
  5975. - os::available_memory() >> 10));
  5976. -
  5977. - ClassFileStream st((u1*) _class_defs[i].class_bytes,
  5978. - _class_defs[i].class_byte_count, (char *)"__VM_RedefineClasses__");
  5979. -
  5980. - // Parse the stream.
  5981. - Handle the_class_loader(THREAD, the_class->class_loader());
  5982. - Handle protection_domain(THREAD, the_class->protection_domain());
  5983. - // Set redefined class handle in JvmtiThreadState class.
  5984. - // This redefined class is sent to agent event handler for class file
  5985. - // load hook event.
  5986. - state->set_class_being_redefined(&the_class, _class_load_kind);
  5987. + // Do a parallel walk through the old and new methods. Detect
  5988. + // cases where they match (exist in both), have been added in
  5989. + // the new methods, or have been deleted (exist only in the
  5990. + // old methods). The class file parser places methods in order
  5991. + // by method name, but does not order overloaded methods by
  5992. + // signature. In order to determine what fate befell the methods,
  5993. + // this code places the overloaded new methods that have matching
  5994. + // old methods in the same order as the old methods and places
  5995. + // new overloaded methods at the end of overloaded methods of
  5996. + // that name. The code for this order normalization is adapted
  5997. + // from the algorithm used in instanceKlass::find_method().
  5998. + // Since we are swapping out of order entries as we find them,
  5999. + // we only have to search forward through the overloaded methods.
  6000. + // Methods which are added and have the same name as an existing
  6001. + // method (but different signature) will be put at the end of
  6002. + // the methods with that name, and the name mismatch code will
  6003. + // handle them.
  6004. + objArrayHandle k_old_methods(the_class->methods());
  6005. + objArrayHandle k_new_methods(new_class->methods());
  6006. + int n_old_methods = k_old_methods->length();
  6007. + int n_new_methods = k_new_methods->length();
  6008. - klassOop k = SystemDictionary::parse_stream(the_class_sym,
  6009. - the_class_loader,
  6010. - protection_domain,
  6011. - &st,
  6012. - THREAD);
  6013. - // Clear class_being_redefined just to be sure.
  6014. - state->clear_class_being_redefined();
  6015. + int ni = 0;
  6016. + int oi = 0;
  6017. + while (true) {
  6018. + methodOop k_old_method;
  6019. + methodOop k_new_method;
  6020. + enum { matched, added, deleted, undetermined } method_was = undetermined;
  6021. - // TODO: if this is retransform, and nothing changed we can skip it
  6022. -
  6023. - instanceKlassHandle scratch_class (THREAD, k);
  6024. -
  6025. - if (HAS_PENDING_EXCEPTION) {
  6026. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  6027. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  6028. - RC_TRACE_WITH_THREAD(0x00000002, THREAD, ("parse_stream exception: '%s'",
  6029. - ex_name->as_C_string()));
  6030. - CLEAR_PENDING_EXCEPTION;
  6031. -
  6032. - if (ex_name == vmSymbols::java_lang_UnsupportedClassVersionError()) {
  6033. - return JVMTI_ERROR_UNSUPPORTED_VERSION;
  6034. - } else if (ex_name == vmSymbols::java_lang_ClassFormatError()) {
  6035. - return JVMTI_ERROR_INVALID_CLASS_FORMAT;
  6036. - } else if (ex_name == vmSymbols::java_lang_ClassCircularityError()) {
  6037. - return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  6038. - } else if (ex_name == vmSymbols::java_lang_NoClassDefFoundError()) {
  6039. - // The message will be "XXX (wrong name: YYY)"
  6040. - return JVMTI_ERROR_NAMES_DONT_MATCH;
  6041. - } else if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  6042. - return JVMTI_ERROR_OUT_OF_MEMORY;
  6043. - } else { // Just in case more exceptions can be thrown..
  6044. - return JVMTI_ERROR_FAILS_VERIFICATION;
  6045. - }
  6046. - }
  6047. -
  6048. - // Ensure class is linked before redefine
  6049. - if (!the_class->is_linked()) {
  6050. - the_class->link_class(THREAD);
  6051. - if (HAS_PENDING_EXCEPTION) {
  6052. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  6053. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  6054. - RC_TRACE_WITH_THREAD(0x00000002, THREAD, ("link_class exception: '%s'",
  6055. - ex_name->as_C_string()));
  6056. - CLEAR_PENDING_EXCEPTION;
  6057. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  6058. - return JVMTI_ERROR_OUT_OF_MEMORY;
  6059. + if (oi >= n_old_methods) {
  6060. + if (ni >= n_new_methods) {
  6061. + break; // we've looked at everything, done
  6062. + }
  6063. + // New method at the end
  6064. + k_new_method = (methodOop) k_new_methods->obj_at(ni);
  6065. + method_was = added;
  6066. + } else if (ni >= n_new_methods) {
  6067. + // Old method, at the end, is deleted
  6068. + k_old_method = (methodOop) k_old_methods->obj_at(oi);
  6069. + method_was = deleted;
  6070. + } else {
  6071. + // There are more methods in both the old and new lists
  6072. + k_old_method = (methodOop) k_old_methods->obj_at(oi);
  6073. + k_new_method = (methodOop) k_new_methods->obj_at(ni);
  6074. + if (k_old_method->name() != k_new_method->name()) {
  6075. + // Methods are sorted by method name, so a mismatch means added
  6076. + // or deleted
  6077. + if (k_old_method->name()->fast_compare(k_new_method->name()) > 0) {
  6078. + method_was = added;
  6079. } else {
  6080. - return JVMTI_ERROR_INTERNAL;
  6081. + method_was = deleted;
  6082. + }
  6083. + } else if (k_old_method->signature() == k_new_method->signature()) {
  6084. + // Both the name and signature match
  6085. + method_was = matched;
  6086. + } else {
  6087. + // The name matches, but the signature doesn't, which means we have to
  6088. + // search forward through the new overloaded methods.
  6089. + int nj; // outside the loop for post-loop check
  6090. + for (nj = ni + 1; nj < n_new_methods; nj++) {
  6091. + methodOop m = (methodOop)k_new_methods->obj_at(nj);
  6092. + if (k_old_method->name() != m->name()) {
  6093. + // reached another method name so no more overloaded methods
  6094. + method_was = deleted;
  6095. + break;
  6096. + }
  6097. + if (k_old_method->signature() == m->signature()) {
  6098. + // found a match so swap the methods
  6099. + k_new_methods->obj_at_put(ni, m);
  6100. + k_new_methods->obj_at_put(nj, k_new_method);
  6101. + k_new_method = m;
  6102. + method_was = matched;
  6103. + break;
  6104. + }
  6105. + }
  6106. +
  6107. + if (nj >= n_new_methods) {
  6108. + // reached the end without a match; so method was deleted
  6109. + method_was = deleted;
  6110. }
  6111. }
  6112. }
  6113. - // Do the validity checks in compare_and_normalize_class_versions()
  6114. - // before verifying the byte codes. By doing these checks first, we
  6115. - // limit the number of functions that require redirection from
  6116. - // the_class to scratch_class. In particular, we don't have to
  6117. - // modify JNI GetSuperclass() and thus won't change its performance.
  6118. - jvmtiError res = compare_and_normalize_class_versions(the_class,
  6119. - scratch_class);
  6120. - if (res != JVMTI_ERROR_NONE) {
  6121. - return res;
  6122. + switch (method_was) {
  6123. + case matched:
  6124. + // methods match, be sure modifiers do too
  6125. + old_flags = (jushort) k_old_method->access_flags().get_flags();
  6126. + new_flags = (jushort) k_new_method->access_flags().get_flags();
  6127. + if ((old_flags ^ new_flags) & ~(JVM_ACC_NATIVE)) {
  6128. + // (tw) Can this have any effects? Probably yes on vtables?
  6129. + result = result | Klass::ModifyClass;
  6130. }
  6131. -
  6132. - // verify what the caller passed us
  6133. {
  6134. - // The bug 6214132 caused the verification to fail.
  6135. - // Information about the_class and scratch_class is temporarily
  6136. - // recorded into jvmtiThreadState. This data is used to redirect
  6137. - // the_class to scratch_class in the JVM_* functions called by the
  6138. - // verifier. Please, refer to jvmtiThreadState.hpp for the detailed
  6139. - // description.
  6140. - RedefineVerifyMark rvm(&the_class, &scratch_class, state);
  6141. - Verifier::verify(
  6142. - scratch_class, Verifier::ThrowException, true, THREAD);
  6143. - }
  6144. -
  6145. - if (HAS_PENDING_EXCEPTION) {
  6146. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  6147. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  6148. - RC_TRACE_WITH_THREAD(0x00000002, THREAD,
  6149. - ("verify_byte_codes exception: '%s'", ex_name->as_C_string()));
  6150. - CLEAR_PENDING_EXCEPTION;
  6151. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  6152. - return JVMTI_ERROR_OUT_OF_MEMORY;
  6153. - } else {
  6154. - // tell the caller the bytecodes are bad
  6155. - return JVMTI_ERROR_FAILS_VERIFICATION;
  6156. + u2 new_num = k_new_method->method_idnum();
  6157. + u2 old_num = k_old_method->method_idnum();
  6158. + if (new_num != old_num) {
  6159. + methodOop idnum_owner = new_class->method_with_idnum(old_num);
  6160. + if (idnum_owner != NULL) {
  6161. + // There is already a method assigned this idnum -- switch them
  6162. + idnum_owner->set_method_idnum(new_num);
  6163. + }
  6164. + k_new_method->set_method_idnum(old_num);
  6165. + RC_TRACE(0x00000002, ("swapping idnum of new and old method %d / %d!",
  6166. + new_num,
  6167. + old_num));
  6168. + // swap_all_method_annotations(old_num, new_num, new_class);
  6169. }
  6170. }
  6171. -
  6172. - res = merge_cp_and_rewrite(the_class, scratch_class, THREAD);
  6173. - if (res != JVMTI_ERROR_NONE) {
  6174. - return res;
  6175. + RC_TRACE(0x00008000, ("Method matched: new: %s [%d] == old: %s [%d]",
  6176. + k_new_method->name_and_sig_as_C_string(), ni,
  6177. + k_old_method->name_and_sig_as_C_string(), oi));
  6178. + // advance to next pair of methods
  6179. + ++oi;
  6180. + ++ni;
  6181. + break;
  6182. + case added:
  6183. + // method added, see if it is OK
  6184. + new_flags = (jushort) k_new_method->access_flags().get_flags();
  6185. + if ((new_flags & JVM_ACC_PRIVATE) == 0
  6186. + // hack: private should be treated as final, but alas
  6187. + || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  6188. + ) {
  6189. + // new methods must be private
  6190. + result = result | Klass::ModifyClass;
  6191. }
  6192. -
  6193. - if (VerifyMergedCPBytecodes) {
  6194. - // verify what we have done during constant pool merging
  6195. - {
  6196. - RedefineVerifyMark rvm(&the_class, &scratch_class, state);
  6197. - Verifier::verify(scratch_class, Verifier::ThrowException, true, THREAD);
  6198. + {
  6199. + u2 num = the_class->next_method_idnum();
  6200. + if (num == constMethodOopDesc::UNSET_IDNUM) {
  6201. + // cannot add any more methods
  6202. + result = result | Klass::ModifyClass;
  6203. }
  6204. -
  6205. - if (HAS_PENDING_EXCEPTION) {
  6206. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  6207. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  6208. - RC_TRACE_WITH_THREAD(0x00000002, THREAD,
  6209. - ("verify_byte_codes post merge-CP exception: '%s'",
  6210. - ex_name->as_C_string()));
  6211. - CLEAR_PENDING_EXCEPTION;
  6212. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  6213. - return JVMTI_ERROR_OUT_OF_MEMORY;
  6214. - } else {
  6215. - // tell the caller that constant pool merging screwed up
  6216. - return JVMTI_ERROR_INTERNAL;
  6217. - }
  6218. + u2 new_num = k_new_method->method_idnum();
  6219. + methodOop idnum_owner = new_class->method_with_idnum(num);
  6220. + if (idnum_owner != NULL) {
  6221. + // There is already a method assigned this idnum -- switch them
  6222. + idnum_owner->set_method_idnum(new_num);
  6223. }
  6224. + k_new_method->set_method_idnum(num);
  6225. + //swap_all_method_annotations(new_num, num, new_class);
  6226. }
  6227. -
  6228. - Rewriter::rewrite(scratch_class, THREAD);
  6229. - if (!HAS_PENDING_EXCEPTION) {
  6230. - Rewriter::relocate_and_link(scratch_class, THREAD);
  6231. + RC_TRACE(0x00000001, ("Method added: new: %s [%d]",
  6232. + k_new_method->name_and_sig_as_C_string(), ni));
  6233. + ++ni; // advance to next new method
  6234. + break;
  6235. + case deleted:
  6236. + // method deleted, see if it is OK
  6237. + old_flags = (jushort) k_old_method->access_flags().get_flags();
  6238. + if ((old_flags & JVM_ACC_PRIVATE) == 0
  6239. + // hack: private should be treated as final, but alas
  6240. + || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  6241. + ) {
  6242. + // deleted methods must be private
  6243. + result = result | Klass::ModifyClass;
  6244. }
  6245. - if (HAS_PENDING_EXCEPTION) {
  6246. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  6247. - CLEAR_PENDING_EXCEPTION;
  6248. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  6249. - return JVMTI_ERROR_OUT_OF_MEMORY;
  6250. - } else {
  6251. - return JVMTI_ERROR_INTERNAL;
  6252. - }
  6253. + RC_TRACE(0x00000001, ("Method deleted: old: %s [%d]",
  6254. + k_old_method->name_and_sig_as_C_string(), oi));
  6255. + ++oi; // advance to next old method
  6256. + break;
  6257. + default:
  6258. + ShouldNotReachHere();
  6259. }
  6260. + }
  6261. +
  6262. + if (new_class()->size() != new_class->old_version()->size()) {
  6263. + result |= Klass::ModifyClassSize;
  6264. + }
  6265. - _scratch_classes[i] = scratch_class;
  6266. + if (new_class->size_helper() != ((instanceKlass*)(new_class->old_version()->klass_part()))->size_helper()) {
  6267. + result |= Klass::ModifyInstanceSize;
  6268. + }
  6269. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  6270. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  6271. - ("loaded name=%s (avail_mem=" UINT64_FORMAT "K)",
  6272. - the_class->external_name(), os::available_memory() >> 10));
  6273. + methodHandle instanceTransformerMethod(new_class->find_method(vmSymbols::transformer_name(), vmSymbols::void_method_signature()));
  6274. + if (!instanceTransformerMethod.is_null() && !instanceTransformerMethod->is_static()) {
  6275. + result |= Klass::HasInstanceTransformer;
  6276. }
  6277. - return JVMTI_ERROR_NONE;
  6278. + // (tw) Check method bodies to be able to return NoChange?
  6279. + return result;
  6280. }
  6281. +void VM_RedefineClasses::calculate_instance_update_information(klassOop new_version) {
  6282. -// Map old_index to new_index as needed. scratch_cp is only needed
  6283. -// for RC_TRACE() calls.
  6284. -void VM_RedefineClasses::map_index(constantPoolHandle scratch_cp,
  6285. - int old_index, int new_index) {
  6286. - if (find_new_index(old_index) != 0) {
  6287. - // old_index is already mapped
  6288. - return;
  6289. - }
  6290. + class UpdateFieldsEvolutionClosure : public FieldEvolutionClosure {
  6291. - if (old_index == new_index) {
  6292. - // no mapping is needed
  6293. - return;
  6294. - }
  6295. + private:
  6296. - _index_map_p->at_put(old_index, new_index);
  6297. - _index_map_count++;
  6298. + GrowableArray<int> info;
  6299. + int curPosition;
  6300. + bool copy_backwards;
  6301. - RC_TRACE(0x00040000, ("mapped tag %d at index %d to %d",
  6302. - scratch_cp->tag_at(old_index).value(), old_index, new_index));
  6303. -} // end map_index()
  6304. + public:
  6305. + bool does_copy_backwards() {
  6306. + return copy_backwards;
  6307. + }
  6308. -// Map old_index to new_index as needed.
  6309. -void VM_RedefineClasses::map_operand_index(int old_index, int new_index) {
  6310. - if (find_new_operand_index(old_index) != -1) {
  6311. - // old_index is already mapped
  6312. - return;
  6313. - }
  6314. + UpdateFieldsEvolutionClosure(klassOop klass) {
  6315. - if (old_index == new_index) {
  6316. - // no mapping is needed
  6317. - return;
  6318. - }
  6319. + int base_offset = instanceOopDesc::base_offset_in_bytes();
  6320. - _operands_index_map_p->at_put(old_index, new_index);
  6321. - _operands_index_map_count++;
  6322. + if (klass->klass_part()->newest_version() == SystemDictionary::Reference_klass()->klass_part()->newest_version()) {
  6323. + base_offset += java_lang_ref_Reference::number_of_fake_oop_fields*size_of_type(T_OBJECT);
  6324. + }
  6325. - RC_TRACE(0x00040000, ("mapped bootstrap specifier at index %d to %d", old_index, new_index));
  6326. -} // end map_index()
  6327. + info.append(base_offset);
  6328. + info.append(0);
  6329. + curPosition = base_offset;
  6330. + copy_backwards = false;
  6331. + }
  6332. + GrowableArray<int> &finish() {
  6333. + info.append(0);
  6334. + return info;
  6335. + }
  6336. -// Merge old_cp and scratch_cp and return the results of the merge via
  6337. -// merge_cp_p. The number of entries in *merge_cp_p is returned via
  6338. -// merge_cp_length_p. The entries in old_cp occupy the same locations
  6339. -// in *merge_cp_p. Also creates a map of indices from entries in
  6340. -// scratch_cp to the corresponding entry in *merge_cp_p. Index map
  6341. -// entries are only created for entries in scratch_cp that occupy a
  6342. -// different location in *merged_cp_p.
  6343. -bool VM_RedefineClasses::merge_constant_pools(constantPoolHandle old_cp,
  6344. - constantPoolHandle scratch_cp, constantPoolHandle *merge_cp_p,
  6345. - int *merge_cp_length_p, TRAPS) {
  6346. + virtual void do_new_field(fieldDescriptor* fd){
  6347. + int alignment = fd->offset() - curPosition;
  6348. + if (alignment > 0) {
  6349. + // This field was aligned, so we need to make sure that we fill the gap
  6350. + fill(alignment);
  6351. + }
  6352. - if (merge_cp_p == NULL) {
  6353. - assert(false, "caller must provide scatch constantPool");
  6354. - return false; // robustness
  6355. - }
  6356. - if (merge_cp_length_p == NULL) {
  6357. - assert(false, "caller must provide scatch CP length");
  6358. - return false; // robustness
  6359. - }
  6360. - // Worst case we need old_cp->length() + scratch_cp()->length(),
  6361. - // but the caller might be smart so make sure we have at least
  6362. - // the minimum.
  6363. - if ((*merge_cp_p)->length() < old_cp->length()) {
  6364. - assert(false, "merge area too small");
  6365. - return false; // robustness
  6366. - }
  6367. + int size = size_of_type(fd->field_type());
  6368. + fill(size);
  6369. + }
  6370. - RC_TRACE_WITH_THREAD(0x00010000, THREAD,
  6371. - ("old_cp_len=%d, scratch_cp_len=%d", old_cp->length(),
  6372. - scratch_cp->length()));
  6373. + private:
  6374. - {
  6375. - // Pass 0:
  6376. - // The old_cp is copied to *merge_cp_p; this means that any code
  6377. - // using old_cp does not have to change. This work looks like a
  6378. - // perfect fit for constantPoolOop::copy_cp_to(), but we need to
  6379. - // handle one special case:
  6380. - // - revert JVM_CONSTANT_Class to JVM_CONSTANT_UnresolvedClass
  6381. - // This will make verification happy.
  6382. -
  6383. - int old_i; // index into old_cp
  6384. -
  6385. - // index zero (0) is not used in constantPools
  6386. - for (old_i = 1; old_i < old_cp->length(); old_i++) {
  6387. - // leave debugging crumb
  6388. - jbyte old_tag = old_cp->tag_at(old_i).value();
  6389. - switch (old_tag) {
  6390. - case JVM_CONSTANT_Class:
  6391. - case JVM_CONSTANT_UnresolvedClass:
  6392. - // revert the copy to JVM_CONSTANT_UnresolvedClass
  6393. - // May be resolving while calling this so do the same for
  6394. - // JVM_CONSTANT_UnresolvedClass (klass_name_at() deals with transition)
  6395. - (*merge_cp_p)->unresolved_klass_at_put(old_i,
  6396. - old_cp->klass_name_at(old_i));
  6397. - break;
  6398. + void fill(int size) {
  6399. + if (info.length() > 0 && info.at(info.length() - 1) < 0) {
  6400. + (*info.adr_at(info.length() - 1)) -= size;
  6401. + } else {
  6402. + info.append(-size);
  6403. + }
  6404. - case JVM_CONSTANT_Double:
  6405. - case JVM_CONSTANT_Long:
  6406. - // just copy the entry to *merge_cp_p, but double and long take
  6407. - // two constant pool entries
  6408. - constantPoolOopDesc::copy_entry_to(old_cp, old_i, *merge_cp_p, old_i, CHECK_0);
  6409. - old_i++;
  6410. - break;
  6411. + curPosition += size;
  6412. + }
  6413. - default:
  6414. - // just copy the entry to *merge_cp_p
  6415. - constantPoolOopDesc::copy_entry_to(old_cp, old_i, *merge_cp_p, old_i, CHECK_0);
  6416. - break;
  6417. + int size_of_type(BasicType type) {
  6418. + int size = 0;
  6419. + switch(type) {
  6420. + case T_BOOLEAN:
  6421. + size = sizeof(jboolean);
  6422. + break;
  6423. +
  6424. + case T_CHAR:
  6425. + size = (sizeof(jchar));
  6426. + break;
  6427. +
  6428. + case T_FLOAT:
  6429. + size = (sizeof(jfloat));
  6430. + break;
  6431. +
  6432. + case T_DOUBLE:
  6433. + size = (sizeof(jdouble));
  6434. + break;
  6435. +
  6436. + case T_BYTE:
  6437. + size = (sizeof(jbyte));
  6438. + break;
  6439. +
  6440. + case T_SHORT:
  6441. + size = (sizeof(jshort));
  6442. + break;
  6443. +
  6444. + case T_INT:
  6445. + size = (sizeof(jint));
  6446. + break;
  6447. +
  6448. + case T_LONG:
  6449. + size = (sizeof(jlong));
  6450. + break;
  6451. +
  6452. + case T_OBJECT:
  6453. + case T_ARRAY:
  6454. + if (UseCompressedOops) {
  6455. + size = sizeof(narrowOop);
  6456. + } else {
  6457. + size = (sizeof(oop));
  6458. + }
  6459. + break;
  6460. +
  6461. + default:
  6462. + ShouldNotReachHere();
  6463. }
  6464. - } // end for each old_cp entry
  6465. - constantPoolOopDesc::copy_operands(old_cp, *merge_cp_p, CHECK_0);
  6466. - (*merge_cp_p)->extend_operands(scratch_cp, CHECK_0);
  6467. + assert(size > 0, "");
  6468. + return size;
  6469. - // We don't need to sanity check that *merge_cp_length_p is within
  6470. - // *merge_cp_p bounds since we have the minimum on-entry check above.
  6471. - (*merge_cp_length_p) = old_i;
  6472. - }
  6473. + }
  6474. +
  6475. + public:
  6476. - // merge_cp_len should be the same as old_cp->length() at this point
  6477. - // so this trace message is really a "warm-and-breathing" message.
  6478. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  6479. - ("after pass 0: merge_cp_len=%d", *merge_cp_length_p));
  6480. + virtual void do_old_field(fieldDescriptor* fd){}
  6481. - int scratch_i; // index into scratch_cp
  6482. - {
  6483. - // Pass 1a:
  6484. - // Compare scratch_cp entries to the old_cp entries that we have
  6485. - // already copied to *merge_cp_p. In this pass, we are eliminating
  6486. - // exact duplicates (matching entry at same index) so we only
  6487. - // compare entries in the common indice range.
  6488. - int increment = 1;
  6489. - int pass1a_length = MIN2(old_cp->length(), scratch_cp->length());
  6490. - for (scratch_i = 1; scratch_i < pass1a_length; scratch_i += increment) {
  6491. - switch (scratch_cp->tag_at(scratch_i).value()) {
  6492. - case JVM_CONSTANT_Double:
  6493. - case JVM_CONSTANT_Long:
  6494. - // double and long take two constant pool entries
  6495. - increment = 2;
  6496. - break;
  6497. + virtual void do_changed_field(fieldDescriptor* old_fd, fieldDescriptor *new_fd){
  6498. - default:
  6499. - increment = 1;
  6500. - break;
  6501. + int alignment = new_fd->offset() - curPosition;
  6502. + if (alignment > 0) {
  6503. + // This field was aligned, so we need to make sure that we fill the gap
  6504. + fill(alignment);
  6505. }
  6506. - bool match = scratch_cp->compare_entry_to(scratch_i, *merge_cp_p,
  6507. - scratch_i, CHECK_0);
  6508. - if (match) {
  6509. - // found a match at the same index so nothing more to do
  6510. - continue;
  6511. - } else if (is_unresolved_class_mismatch(scratch_cp, scratch_i,
  6512. - *merge_cp_p, scratch_i)) {
  6513. - // The mismatch in compare_entry_to() above is because of a
  6514. - // resolved versus unresolved class entry at the same index
  6515. - // with the same string value. Since Pass 0 reverted any
  6516. - // class entries to unresolved class entries in *merge_cp_p,
  6517. - // we go with the unresolved class entry.
  6518. - continue;
  6519. - } else if (is_unresolved_string_mismatch(scratch_cp, scratch_i,
  6520. - *merge_cp_p, scratch_i)) {
  6521. - // The mismatch in compare_entry_to() above is because of a
  6522. - // resolved versus unresolved string entry at the same index
  6523. - // with the same string value. We can live with whichever
  6524. - // happens to be at scratch_i in *merge_cp_p.
  6525. - continue;
  6526. - }
  6527. -
  6528. - int found_i = scratch_cp->find_matching_entry(scratch_i, *merge_cp_p,
  6529. - CHECK_0);
  6530. - if (found_i != 0) {
  6531. - guarantee(found_i != scratch_i,
  6532. - "compare_entry_to() and find_matching_entry() do not agree");
  6533. -
  6534. - // Found a matching entry somewhere else in *merge_cp_p so
  6535. - // just need a mapping entry.
  6536. - map_index(scratch_cp, scratch_i, found_i);
  6537. - continue;
  6538. - }
  6539. -
  6540. - // The find_matching_entry() call above could fail to find a match
  6541. - // due to a resolved versus unresolved class or string entry situation
  6542. - // like we solved above with the is_unresolved_*_mismatch() calls.
  6543. - // However, we would have to call is_unresolved_*_mismatch() over
  6544. - // all of *merge_cp_p (potentially) and that doesn't seem to be
  6545. - // worth the time.
  6546. -
  6547. - // No match found so we have to append this entry and any unique
  6548. - // referenced entries to *merge_cp_p.
  6549. - append_entry(scratch_cp, scratch_i, merge_cp_p, merge_cp_length_p,
  6550. - CHECK_0);
  6551. - }
  6552. - }
  6553. -
  6554. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  6555. - ("after pass 1a: merge_cp_len=%d, scratch_i=%d, index_map_len=%d",
  6556. - *merge_cp_length_p, scratch_i, _index_map_count));
  6557. -
  6558. - if (scratch_i < scratch_cp->length()) {
  6559. - // Pass 1b:
  6560. - // old_cp is smaller than scratch_cp so there are entries in
  6561. - // scratch_cp that we have not yet processed. We take care of
  6562. - // those now.
  6563. - int increment = 1;
  6564. - for (; scratch_i < scratch_cp->length(); scratch_i += increment) {
  6565. - switch (scratch_cp->tag_at(scratch_i).value()) {
  6566. - case JVM_CONSTANT_Double:
  6567. - case JVM_CONSTANT_Long:
  6568. - // double and long take two constant pool entries
  6569. - increment = 2;
  6570. - break;
  6571. + assert(old_fd->field_type() == new_fd->field_type(), "");
  6572. + assert(curPosition == new_fd->offset(), "must be correct offset!");
  6573. - default:
  6574. - increment = 1;
  6575. - break;
  6576. + int offset = old_fd->offset();
  6577. + int size = size_of_type(old_fd->field_type());
  6578. +
  6579. + int prevEnd = -1;
  6580. + if (info.length() > 0 && info.at(info.length() - 1) > 0) {
  6581. + prevEnd = info.at(info.length() - 2) + info.at(info.length() - 1);
  6582. + }
  6583. +
  6584. + if (prevEnd == offset) {
  6585. + info.at_put(info.length() - 2, info.at(info.length() - 2) + size);
  6586. + } else {
  6587. + info.append(size);
  6588. + info.append(offset);
  6589. }
  6590. - int found_i =
  6591. - scratch_cp->find_matching_entry(scratch_i, *merge_cp_p, CHECK_0);
  6592. - if (found_i != 0) {
  6593. - // Found a matching entry somewhere else in *merge_cp_p so
  6594. - // just need a mapping entry.
  6595. - map_index(scratch_cp, scratch_i, found_i);
  6596. - continue;
  6597. + if (old_fd->offset() < new_fd->offset()) {
  6598. + copy_backwards = true;
  6599. }
  6600. - // No match found so we have to append this entry and any unique
  6601. - // referenced entries to *merge_cp_p.
  6602. - append_entry(scratch_cp, scratch_i, merge_cp_p, merge_cp_length_p,
  6603. - CHECK_0);
  6604. + transfer_special_access_flags(old_fd, new_fd);
  6605. +
  6606. + curPosition += size;
  6607. }
  6608. + };
  6609. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  6610. - ("after pass 1b: merge_cp_len=%d, scratch_i=%d, index_map_len=%d",
  6611. - *merge_cp_length_p, scratch_i, _index_map_count));
  6612. + UpdateFieldsEvolutionClosure cl(new_version);
  6613. + ((instanceKlass*)new_version->klass_part())->do_fields_evolution(&cl);
  6614. +
  6615. + GrowableArray<int> result = cl.finish();
  6616. + ((instanceKlass*)new_version->klass_part())->store_update_information(result);
  6617. + ((instanceKlass*)new_version->klass_part())->set_copying_backwards(cl.does_copy_backwards());
  6618. +
  6619. + if (RC_TRACE_ENABLED(0x00000002)) {
  6620. + RC_TRACE(0x00000002, ("Instance update information for %s:",
  6621. + new_version->klass_part()->name()->as_C_string()));
  6622. + if (cl.does_copy_backwards()) {
  6623. + RC_TRACE(0x00000002, ("\tDoes copy backwards!"));
  6624. + }
  6625. + for (int i=0; i<result.length(); i++) {
  6626. + int curNum = result.at(i);
  6627. + if (curNum < 0) {
  6628. + RC_TRACE(0x00000002, ("\t%d CLEAN", curNum));
  6629. + } else if (curNum > 0) {
  6630. + RC_TRACE(0x00000002, ("\t%d COPY from %d", curNum, result.at(i + 1)));
  6631. + i++;
  6632. + } else {
  6633. + RC_TRACE(0x00000002, ("\tEND"));
  6634. + }
  6635. + }
  6636. }
  6637. - finalize_operands_merge(*merge_cp_p, THREAD);
  6638. +}
  6639. - return true;
  6640. -} // end merge_constant_pools()
  6641. -
  6642. -
  6643. -// Merge constant pools between the_class and scratch_class and
  6644. -// potentially rewrite bytecodes in scratch_class to use the merged
  6645. -// constant pool.
  6646. -jvmtiError VM_RedefineClasses::merge_cp_and_rewrite(
  6647. - instanceKlassHandle the_class, instanceKlassHandle scratch_class,
  6648. - TRAPS) {
  6649. - // worst case merged constant pool length is old and new combined
  6650. - int merge_cp_length = the_class->constants()->length()
  6651. - + scratch_class->constants()->length();
  6652. -
  6653. - constantPoolHandle old_cp(THREAD, the_class->constants());
  6654. - constantPoolHandle scratch_cp(THREAD, scratch_class->constants());
  6655. -
  6656. - // Constant pools are not easily reused so we allocate a new one
  6657. - // each time.
  6658. - // merge_cp is created unsafe for concurrent GC processing. It
  6659. - // should be marked safe before discarding it. Even though
  6660. - // garbage, if it crosses a card boundary, it may be scanned
  6661. - // in order to find the start of the first complete object on the card.
  6662. - constantPoolHandle merge_cp(THREAD,
  6663. - oopFactory::new_constantPool(merge_cp_length,
  6664. - oopDesc::IsUnsafeConc,
  6665. - THREAD));
  6666. - int orig_length = old_cp->orig_length();
  6667. - if (orig_length == 0) {
  6668. - // This old_cp is an actual original constant pool. We save
  6669. - // the original length in the merged constant pool so that
  6670. - // merge_constant_pools() can be more efficient. If a constant
  6671. - // pool has a non-zero orig_length() value, then that constant
  6672. - // pool was created by a merge operation in RedefineClasses.
  6673. - merge_cp->set_orig_length(old_cp->length());
  6674. - } else {
  6675. - // This old_cp is a merged constant pool from a previous
  6676. - // RedefineClasses() calls so just copy the orig_length()
  6677. - // value.
  6678. - merge_cp->set_orig_length(old_cp->orig_length());
  6679. +Symbol* VM_RedefineClasses::signature_to_class_name(Symbol* signature) {
  6680. + assert(FieldType::is_obj(signature), "");
  6681. + return SymbolTable::new_symbol(signature->as_C_string() + 1, signature->utf8_length() - 2, Thread::current());
  6682. +}
  6683. +
  6684. +void VM_RedefineClasses::calculate_type_check_information(klassOop klass) {
  6685. + if (klass->klass_part()->is_redefining()) {
  6686. + klass = klass->klass_part()->old_version();
  6687. }
  6688. - ResourceMark rm(THREAD);
  6689. - _index_map_count = 0;
  6690. - _index_map_p = new intArray(scratch_cp->length(), -1);
  6691. + // We found an instance klass!
  6692. + instanceKlass *cur_instance_klass = instanceKlass::cast(klass);
  6693. + GrowableArray< Pair<int, klassOop> > type_check_information;
  6694. - _operands_cur_length = constantPoolOopDesc::operand_array_length(old_cp->operands());
  6695. - _operands_index_map_count = 0;
  6696. - _operands_index_map_p = new intArray(
  6697. - constantPoolOopDesc::operand_array_length(scratch_cp->operands()), -1);
  6698. + class MyFieldClosure : public FieldClosure {
  6699. - // reference to the cp holder is needed for copy_operands()
  6700. - merge_cp->set_pool_holder(scratch_class());
  6701. - bool result = merge_constant_pools(old_cp, scratch_cp, &merge_cp,
  6702. - &merge_cp_length, THREAD);
  6703. - merge_cp->set_pool_holder(NULL);
  6704. + public:
  6705. - if (!result) {
  6706. - // The merge can fail due to memory allocation failure or due
  6707. - // to robustness checks.
  6708. - return JVMTI_ERROR_INTERNAL;
  6709. - }
  6710. -
  6711. - RC_TRACE_WITH_THREAD(0x00010000, THREAD,
  6712. - ("merge_cp_len=%d, index_map_len=%d", merge_cp_length, _index_map_count));
  6713. -
  6714. - if (_index_map_count == 0) {
  6715. - // there is nothing to map between the new and merged constant pools
  6716. -
  6717. - if (old_cp->length() == scratch_cp->length()) {
  6718. - // The old and new constant pools are the same length and the
  6719. - // index map is empty. This means that the three constant pools
  6720. - // are equivalent (but not the same). Unfortunately, the new
  6721. - // constant pool has not gone through link resolution nor have
  6722. - // the new class bytecodes gone through constant pool cache
  6723. - // rewriting so we can't use the old constant pool with the new
  6724. - // class.
  6725. -
  6726. - merge_cp()->set_is_conc_safe(true);
  6727. - merge_cp = constantPoolHandle(); // toss the merged constant pool
  6728. - } else if (old_cp->length() < scratch_cp->length()) {
  6729. - // The old constant pool has fewer entries than the new constant
  6730. - // pool and the index map is empty. This means the new constant
  6731. - // pool is a superset of the old constant pool. However, the old
  6732. - // class bytecodes have already gone through constant pool cache
  6733. - // rewriting so we can't use the new constant pool with the old
  6734. - // class.
  6735. -
  6736. - merge_cp()->set_is_conc_safe(true);
  6737. - merge_cp = constantPoolHandle(); // toss the merged constant pool
  6738. - } else {
  6739. - // The old constant pool has more entries than the new constant
  6740. - // pool and the index map is empty. This means that both the old
  6741. - // and merged constant pools are supersets of the new constant
  6742. - // pool.
  6743. -
  6744. - // Replace the new constant pool with a shrunken copy of the
  6745. - // merged constant pool; the previous new constant pool will
  6746. - // get GCed.
  6747. - set_new_constant_pool(scratch_class, merge_cp, merge_cp_length,
  6748. - THREAD);
  6749. - // drop local ref to the merged constant pool
  6750. - merge_cp()->set_is_conc_safe(true);
  6751. - merge_cp = constantPoolHandle();
  6752. + GrowableArray< Pair<int, klassOop> > *_arr;
  6753. +
  6754. + MyFieldClosure(GrowableArray< Pair<int, klassOop> > *arr) {
  6755. + _arr = arr;
  6756. }
  6757. - } else {
  6758. - if (RC_TRACE_ENABLED(0x00040000)) {
  6759. - // don't want to loop unless we are tracing
  6760. - int count = 0;
  6761. - for (int i = 1; i < _index_map_p->length(); i++) {
  6762. - int value = _index_map_p->at(i);
  6763. -
  6764. - if (value != -1) {
  6765. - RC_TRACE_WITH_THREAD(0x00040000, THREAD,
  6766. - ("index_map[%d]: old=%d new=%d", count, i, value));
  6767. - count++;
  6768. +
  6769. + virtual void do_field(fieldDescriptor* fd) {
  6770. + if (fd->field_type() == T_OBJECT) {
  6771. + Symbol* signature = fd->signature();
  6772. + if (FieldType::is_obj(signature)) {
  6773. + Symbol* name = signature_to_class_name(signature);
  6774. + klassOop field_klass;
  6775. + if (is_field_dangerous(name, fd, field_klass)) {
  6776. + RC_TRACE(0x00000002, ("Found dangerous field %s in klass %s of type %s",
  6777. + fd->name()->as_C_string(),
  6778. + fd->field_holder()->klass_part()->name()->as_C_string(),
  6779. + name->as_C_string()));
  6780. + _arr->append(Pair<int, klassOop>(fd->offset(), field_klass->klass_part()->newest_version()));
  6781. + }
  6782. }
  6783. +
  6784. + // Array fields can never be a problem!
  6785. }
  6786. }
  6787. - // We have entries mapped between the new and merged constant pools
  6788. - // so we have to rewrite some constant pool references.
  6789. - if (!rewrite_cp_refs(scratch_class, THREAD)) {
  6790. - return JVMTI_ERROR_INTERNAL;
  6791. + bool is_field_dangerous(Symbol* klass_name, fieldDescriptor *fd, klassOop &field_klass) {
  6792. + field_klass = SystemDictionary::find(klass_name, fd->field_holder()->klass_part()->class_loader(),
  6793. + fd->field_holder()->klass_part()->protection_domain(), Thread::current());
  6794. + if(field_klass != NULL) {
  6795. + if (field_klass->klass_part()->is_redefining()) {
  6796. + field_klass = field_klass->klass_part()->old_version();
  6797. + }
  6798. + if (field_klass->klass_part()->has_subtype_changed()) {
  6799. + return true;
  6800. + }
  6801. + }
  6802. + return false;
  6803. }
  6804. + };
  6805. +
  6806. + MyFieldClosure fieldClosure(&type_check_information);
  6807. + cur_instance_klass->do_nonstatic_fields(&fieldClosure);
  6808. - // Replace the new constant pool with a shrunken copy of the
  6809. - // merged constant pool so now the rewritten bytecodes have
  6810. - // valid references; the previous new constant pool will get
  6811. - // GCed.
  6812. - set_new_constant_pool(scratch_class, merge_cp, merge_cp_length,
  6813. - THREAD);
  6814. - merge_cp()->set_is_conc_safe(true);
  6815. + if (type_check_information.length() > 0) {
  6816. + type_check_information.append(Pair<int, klassOop>(-1, NULL));
  6817. + cur_instance_klass->store_type_check_information(type_check_information);
  6818. }
  6819. - assert(old_cp()->is_conc_safe(), "Just checking");
  6820. - assert(scratch_cp()->is_conc_safe(), "Just checking");
  6821. +}
  6822. - return JVMTI_ERROR_NONE;
  6823. -} // end merge_cp_and_rewrite()
  6824. +bool VM_RedefineClasses::check_field_value_types() {
  6825. + Thread *THREAD = Thread::current();
  6826. + class CheckFieldTypesClosure : public ObjectClosure {
  6827. -// Rewrite constant pool references in klass scratch_class.
  6828. -bool VM_RedefineClasses::rewrite_cp_refs(instanceKlassHandle scratch_class,
  6829. - TRAPS) {
  6830. + private:
  6831. - // rewrite constant pool references in the methods:
  6832. - if (!rewrite_cp_refs_in_methods(scratch_class, THREAD)) {
  6833. - // propagate failure back to caller
  6834. - return false;
  6835. - }
  6836. + bool _result;
  6837. - // rewrite constant pool references in the class_annotations:
  6838. - if (!rewrite_cp_refs_in_class_annotations(scratch_class, THREAD)) {
  6839. - // propagate failure back to caller
  6840. - return false;
  6841. - }
  6842. + public:
  6843. - // rewrite constant pool references in the fields_annotations:
  6844. - if (!rewrite_cp_refs_in_fields_annotations(scratch_class, THREAD)) {
  6845. - // propagate failure back to caller
  6846. - return false;
  6847. - }
  6848. + CheckFieldTypesClosure() {
  6849. + _result = true;
  6850. + }
  6851. - // rewrite constant pool references in the methods_annotations:
  6852. - if (!rewrite_cp_refs_in_methods_annotations(scratch_class, THREAD)) {
  6853. - // propagate failure back to caller
  6854. - return false;
  6855. - }
  6856. + bool result() { return _result; }
  6857. - // rewrite constant pool references in the methods_parameter_annotations:
  6858. - if (!rewrite_cp_refs_in_methods_parameter_annotations(scratch_class,
  6859. - THREAD)) {
  6860. - // propagate failure back to caller
  6861. - return false;
  6862. + virtual void do_object(oop obj) {
  6863. +
  6864. + if (!_result) {
  6865. + return;
  6866. + }
  6867. +
  6868. + if (obj->is_objArray()) {
  6869. +
  6870. + objArrayOop array = objArrayOop(obj);
  6871. +
  6872. + klassOop element_klass = objArrayKlass::cast(array->klass())->element_klass();
  6873. +
  6874. + if (element_klass->klass_part()->has_subtype_changed()) {
  6875. + int length = array->length();
  6876. + for (int i=0; i<length; i++) {
  6877. + oop element = array->obj_at(i);
  6878. + if (element != NULL && element->blueprint()->newest_version()->klass_part()->is_redefining()) {
  6879. + // Check subtype relationship to static type of array
  6880. + if (!element->blueprint()->newest_version()->klass_part()->is_subtype_of(element_klass->klass_part()->newest_version())) {
  6881. + RC_TRACE(0x00000001, ("Array value is INVALID - abort redefinition (static_type=%s, index=%d, dynamic_type=%s)",
  6882. + element_klass->klass_part()->name()->as_C_string(),
  6883. + i,
  6884. + element->blueprint()->name()->as_C_string()));
  6885. + _result = false;
  6886. + break;
  6887. + }
  6888. + }
  6889. + }
  6890. + }
  6891. +
  6892. + } else {
  6893. + Pair<int, klassOop> *cur = obj->klass()->klass_part()->type_check_information();
  6894. + if (cur != NULL) {
  6895. + // Type check information exists for this oop
  6896. + while ((*cur).left() != -1) {
  6897. + check_field(obj, (*cur).left(), (*cur).right());
  6898. + cur++;
  6899. + }
  6900. + }
  6901. + }
  6902. + }
  6903. +
  6904. + void check_field(oop obj, int offset, klassOop static_type) {
  6905. + oop field_value = obj->obj_field(offset);
  6906. + if (field_value != NULL) {
  6907. + // Field is not null
  6908. + if (field_value->klass()->klass_part()->newest_version()->klass_part()->is_subtype_of(static_type)) {
  6909. + // We are OK
  6910. + RC_TRACE(0x00008000, ("Field value is OK (klass=%s, static_type=%s, offset=%d, dynamic_type=%s)",
  6911. + obj->klass()->klass_part()->name()->as_C_string(),
  6912. + static_type->klass_part()->name()->as_C_string(),
  6913. + offset,
  6914. + field_value->klass()->klass_part()->name()->as_C_string()));
  6915. + } else {
  6916. + // Failure!
  6917. + RC_TRACE(0x00000001, ("Field value is INVALID - abort redefinition (klass=%s, static_type=%s, offset=%d, dynamic_type=%s)",
  6918. + obj->klass()->klass_part()->name()->as_C_string(),
  6919. + static_type->klass_part()->name()->as_C_string(),
  6920. + offset,
  6921. + field_value->klass()->klass_part()->name()->as_C_string()));
  6922. + _result = false;
  6923. + }
  6924. + }
  6925. + }
  6926. + };
  6927. +
  6928. + CheckFieldTypesClosure myObjectClosure;
  6929. +
  6930. + // make sure that heap is parsable (fills TLABs with filler objects)
  6931. + Universe::heap()->ensure_parsability(false); // no need to retire TLABs
  6932. +
  6933. + // do the iteration
  6934. + // If this operation encounters a bad object when using CMS,
  6935. + // consider using safe_object_iterate() which avoids perm gen
  6936. + // objects that may contain bad references.
  6937. + Universe::heap()->object_iterate(&myObjectClosure);
  6938. +
  6939. + // when sharing is enabled we must iterate over the shared spaces
  6940. + if (UseSharedSpaces) {
  6941. + GenCollectedHeap* gch = GenCollectedHeap::heap();
  6942. + CompactingPermGenGen* gen = (CompactingPermGenGen*)gch->perm_gen();
  6943. + gen->ro_space()->object_iterate(&myObjectClosure);
  6944. + gen->rw_space()->object_iterate(&myObjectClosure);
  6945. }
  6946. - // rewrite constant pool references in the methods_default_annotations:
  6947. - if (!rewrite_cp_refs_in_methods_default_annotations(scratch_class,
  6948. - THREAD)) {
  6949. - // propagate failure back to caller
  6950. - return false;
  6951. + return myObjectClosure.result();
  6952. +}
  6953. +
  6954. +void VM_RedefineClasses::clear_type_check_information(klassOop k) {
  6955. + if (k->klass_part()->is_redefining()) {
  6956. + k = k->klass_part()->old_version();
  6957. }
  6958. - return true;
  6959. -} // end rewrite_cp_refs()
  6960. + // We found an instance klass!
  6961. + instanceKlass *cur_instance_klass = instanceKlass::cast(k);
  6962. + cur_instance_klass->clear_type_check_information();
  6963. +}
  6964. +void VM_RedefineClasses::update_active_methods() {
  6965. +
  6966. + RC_TRACE(0x00000002, ("Updating active methods"));
  6967. + JavaThread *java_thread = Threads::first();
  6968. + while (java_thread != NULL) {
  6969. +
  6970. + int stack_depth = 0;
  6971. + if (java_thread->has_last_Java_frame()) {
  6972. +
  6973. + RC_TRACE(0x0000000400, ("checking stack of Java thread %s", java_thread->name()));
  6974. +
  6975. + // vframes are resource allocated
  6976. + Thread* current_thread = Thread::current();
  6977. + ResourceMark rm(current_thread);
  6978. + HandleMark hm(current_thread);
  6979. +
  6980. + RegisterMap reg_map(java_thread);
  6981. + frame f = java_thread->last_frame();
  6982. + vframe* vf = vframe::new_vframe(&f, &reg_map, java_thread);
  6983. + frame* last_entry_frame = NULL;
  6984. +
  6985. + while (vf != NULL) {
  6986. + if (vf->is_java_frame()) {
  6987. + // java frame (interpreted, compiled, ...)
  6988. + javaVFrame *jvf = javaVFrame::cast(vf);
  6989. +
  6990. + if (!(jvf->method()->is_native())) {
  6991. + int bci = jvf->bci();
  6992. + RC_TRACE(0x00000400, ("found method: %s / bci=%d", jvf->method()->name()->as_C_string(), bci));
  6993. + ResourceMark rm(Thread::current());
  6994. + HandleMark hm;
  6995. + instanceKlassHandle klass(jvf->method()->method_holder());
  6996. +
  6997. + if (jvf->method()->new_version() != NULL && jvf->is_interpreted_frame()) {
  6998. +
  6999. +
  7000. + RC_TRACE(0x00000002, ("Found method that should just be updated to the newest version %s",
  7001. + jvf->method()->name_and_sig_as_C_string()));
  7002. +
  7003. + if (RC_TRACE_ENABLED(0x01000000)) {
  7004. + int code_size = jvf->method()->code_size();
  7005. + char *code_base_old = (char*)jvf->method()->code_base();
  7006. + char *code_base_new = (char*)jvf->method()->new_version()->code_base();
  7007. + for (int i=0; i<code_size; i++) {
  7008. + tty->print_cr("old=%d new=%d", *code_base_old++, *code_base_new++);
  7009. + }
  7010. + jvf->method()->print_codes_on(tty);
  7011. + jvf->method()->new_version()->print_codes_on(tty);
  7012. + }
  7013. +
  7014. + assert(jvf->is_interpreted_frame(), "Every frame must be interpreted!");
  7015. + interpretedVFrame *iframe = (interpretedVFrame *)jvf;
  7016. +
  7017. +
  7018. + if (RC_TRACE_ENABLED(0x01000000)) {
  7019. + constantPoolCacheOop cp_old = jvf->method()->constants()->cache();
  7020. + tty->print_cr("old cp");
  7021. + for (int i=0; i<cp_old->length(); i++) {
  7022. + cp_old->entry_at(i)->print(tty, i);
  7023. + }
  7024. + constantPoolCacheOop cp_new = jvf->method()->new_version()->constants()->cache();
  7025. + tty->print_cr("new cp");
  7026. + for (int i=0; i<cp_new->length(); i++) {
  7027. + cp_new->entry_at(i)->print(tty, i);
  7028. + }
  7029. + }
  7030. +
  7031. + iframe->set_method(jvf->method()->new_version(), bci);
  7032. + RC_TRACE(0x00000002, ("Updated method to newer version"));
  7033. + assert(jvf->method()->new_version() == NULL, "must be latest version");
  7034. +
  7035. + }
  7036. + }
  7037. + }
  7038. + vf = vf->sender();
  7039. + }
  7040. + }
  7041. -// Rewrite constant pool references in the methods.
  7042. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods(
  7043. - instanceKlassHandle scratch_class, TRAPS) {
  7044. + // Advance to next thread
  7045. + java_thread = java_thread->next();
  7046. + }
  7047. +}
  7048. - objArrayHandle methods(THREAD, scratch_class->methods());
  7049. +void VM_RedefineClasses::method_forwarding() {
  7050. +
  7051. + int forwarding_count = 0;
  7052. + JavaThread *java_thread = Threads::first();
  7053. + while (java_thread != NULL) {
  7054. +
  7055. + int stack_depth = 0;
  7056. + if (java_thread->has_last_Java_frame()) {
  7057. +
  7058. + RC_TRACE(0x00000400, ("checking stack of Java thread %s", java_thread->name()));
  7059. +
  7060. + // vframes are resource allocated
  7061. + Thread* current_thread = Thread::current();
  7062. + ResourceMark rm(current_thread);
  7063. + HandleMark hm(current_thread);
  7064. +
  7065. + RegisterMap reg_map(java_thread);
  7066. + frame f = java_thread->last_frame();
  7067. + vframe* vf = vframe::new_vframe(&f, &reg_map, java_thread);
  7068. + frame* last_entry_frame = NULL;
  7069. +
  7070. + while (vf != NULL) {
  7071. + if (vf->is_java_frame()) {
  7072. + // java frame (interpreted, compiled, ...)
  7073. + javaVFrame *jvf = javaVFrame::cast(vf);
  7074. +
  7075. + if (!(jvf->method()->is_native())) {
  7076. + RC_TRACE(0x00008000, ("found method: %s",
  7077. + jvf->method()->name()->as_C_string()));
  7078. + ResourceMark rm(Thread::current());
  7079. + HandleMark hm;
  7080. + instanceKlassHandle klass(jvf->method()->method_holder());
  7081. + methodOop m = jvf->method();
  7082. + int bci = jvf->bci();
  7083. + RC_TRACE(0x00008000, ("klass redef %d",
  7084. + klass->is_redefining()));
  7085. +
  7086. + if (klass->new_version() != NULL && m->new_version() == NULL) {
  7087. + RC_TRACE(0x00008000, ("found potential forwarding method: %s",
  7088. + m->name()->as_C_string()));
  7089. +
  7090. + klassOop new_klass = klass->newest_version();
  7091. + methodOop new_method = new_klass->klass_part()->lookup_method(m->name(), m->signature());
  7092. + RC_TRACE(0x00000002, ("%d %d",
  7093. + new_method,
  7094. + new_method->constMethod()->has_code_section_table()));
  7095. +
  7096. + if (new_method != NULL && new_method->constMethod()->has_code_section_table()) {
  7097. + RC_TRACE(0x00008000, ("found code section table for method: %s",
  7098. + new_method->name()->as_C_string()));
  7099. + m->set_forward_method(new_method);
  7100. + if (new_method->max_locals() != m->max_locals()) {
  7101. + tty->print_cr("new_m max locals: %d old_m max locals: %d", new_method->max_locals(), m->max_locals());
  7102. + }
  7103. + assert(new_method->max_locals() == m->max_locals(), "number of locals must match");
  7104. + assert(new_method->max_stack() == m->max_stack(), "number of stack values must match");
  7105. + if (jvf->is_interpreted_frame()) {
  7106. + if (m->is_in_code_section(bci)) {
  7107. + // We must transfer now and cannot delay until next NOP.
  7108. + int new_bci = m->calculate_forward_bci(bci, new_method);
  7109. + interpretedVFrame* iframe = interpretedVFrame::cast(jvf);
  7110. + RC_TRACE(0x00000002, ("Transferring execution of %s to new method old_bci=%d new_bci=%d",
  7111. + new_method->name()->as_C_string(),
  7112. + bci,
  7113. + new_bci));
  7114. + iframe->set_method(new_method, new_bci);
  7115. + } else {
  7116. + RC_TRACE(0x00000002, ("Delaying method forwarding of %s because %d is not in a code section",
  7117. + new_method->name()->as_C_string(),
  7118. + bci));
  7119. + }
  7120. + } else {
  7121. + RC_TRACE(0x00000002, ("Delaying method forwarding of %s because method is compiled",
  7122. + new_method->name()->as_C_string()));
  7123. + }
  7124. + }
  7125. + }
  7126. + }
  7127. + }
  7128. + vf = vf->sender();
  7129. + }
  7130. + }
  7131. - if (methods.is_null() || methods->length() == 0) {
  7132. - // no methods so nothing to do
  7133. - return true;
  7134. + // Advance to next thread
  7135. + java_thread = java_thread->next();
  7136. }
  7137. - // rewrite constant pool references in the methods:
  7138. - for (int i = methods->length() - 1; i >= 0; i--) {
  7139. - methodHandle method(THREAD, (methodOop)methods->obj_at(i));
  7140. - methodHandle new_method;
  7141. - rewrite_cp_refs_in_method(method, &new_method, CHECK_false);
  7142. - if (!new_method.is_null()) {
  7143. - // the method has been replaced so save the new method version
  7144. - methods->obj_at_put(i, new_method());
  7145. + RC_TRACE(0x00000001, ("Method forwarding applied to %d methods",
  7146. + forwarding_count));
  7147. +}
  7148. +
  7149. +bool VM_RedefineClasses::check_method_stacks() {
  7150. +
  7151. + JavaThread *java_thread = Threads::first();
  7152. + while (java_thread != NULL) {
  7153. +
  7154. + int stack_depth = 0;
  7155. + if (java_thread->has_last_Java_frame()) {
  7156. +
  7157. + RC_TRACE(0x00000400, ("checking stack of Java thread %s", java_thread->name()));
  7158. +
  7159. + // vframes are resource allocated
  7160. + Thread* current_thread = Thread::current();
  7161. + ResourceMark rm(current_thread);
  7162. + HandleMark hm(current_thread);
  7163. +
  7164. + RegisterMap reg_map(java_thread);
  7165. + frame f = java_thread->last_frame();
  7166. + vframe* vf = vframe::new_vframe(&f, &reg_map, java_thread);
  7167. + frame* last_entry_frame = NULL;
  7168. +
  7169. + while (vf != NULL) {
  7170. + if (vf->is_java_frame()) {
  7171. + // java frame (interpreted, compiled, ...)
  7172. + javaVFrame *jvf = javaVFrame::cast(vf);
  7173. +
  7174. + if (!(jvf->method()->is_native())) {
  7175. + RC_TRACE(0x00000400, ("found method: %s", jvf->method()->name()->as_C_string()));
  7176. + ResourceMark rm(Thread::current());
  7177. + HandleMark hm;
  7178. + instanceKlassHandle klass(jvf->method()->method_holder());
  7179. +
  7180. + StackValueCollection *locals = jvf->locals();
  7181. + const size_t message_buffer_len = klass->name()->utf8_length() + 1024;
  7182. + char* message_buffer = NEW_RESOURCE_ARRAY(char, message_buffer_len);
  7183. +
  7184. + for (int i=0; i<locals->size(); i++) {
  7185. + StackValue *stack_value = locals->at(i);
  7186. + if (stack_value->type() == T_OBJECT) {
  7187. + Handle obj = stack_value->get_obj();
  7188. + if (!obj.is_null() && obj->klass()->klass_part()->newest_version()->klass_part()->check_redefinition_flag(Klass::RemoveSuperType)) {
  7189. +
  7190. + // OK, so this is a possible failure => check local variable table, if it could be OK.
  7191. + bool result = false;
  7192. + methodOop method = jvf->method();
  7193. + if (method->has_localvariable_table()) {
  7194. + LocalVariableTableElement *elem = jvf->method()->localvariable_table_start();
  7195. + for (int j=0; j<method->localvariable_table_length(); j++) {
  7196. +
  7197. + if (elem->slot == i) {
  7198. +
  7199. + // Matching index found
  7200. +
  7201. + if (elem->start_bci <= jvf->bci() && elem->start_bci + elem->length > jvf->bci()) {
  7202. +
  7203. + // Also in range!!
  7204. + Symbol* signature = jvf->method()->constants()->symbol_at(elem->descriptor_cp_index);
  7205. + Symbol* klass_name = signature_to_class_name(signature);
  7206. +
  7207. + 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();
  7208. + klassOop cur = obj->klass()->klass_part()->newest_version();
  7209. +
  7210. + // Field is not null
  7211. + if (cur->klass_part()->newest_version()->klass_part()->is_subtype_of(local_klass)) {
  7212. + // We are OK
  7213. + RC_TRACE(0x00008000, ("Local variable value is OK (local_klass=%s, cur_klass=%s)",
  7214. + local_klass->klass_part()->name()->as_C_string(), cur->klass_part()->name()->as_C_string()));
  7215. + result = true;
  7216. + } else {
  7217. + // Failure!
  7218. + RC_TRACE(0x00000001, ("Local variable value is INVALID - abort redefinition (local_klass=%s, cur_klass=%s)",
  7219. + local_klass->klass_part()->name()->as_C_string(),
  7220. + cur->klass_part()->name()->as_C_string()));
  7221. + return false;
  7222. + }
  7223. + }
  7224. + }
  7225. +
  7226. + elem++;
  7227. + }
  7228. + } else {
  7229. + RC_TRACE(0x00000002, ("Method %s does not have a local variable table => abort",
  7230. + method->name_and_sig_as_C_string()));
  7231. + }
  7232. +
  7233. + if (!result) {
  7234. + return false;
  7235. + }
  7236. +
  7237. + RC_TRACE(0x00008000, ("Verifying class %s",
  7238. + jvf->method()->method_holder()->klass_part()->name()->as_C_string()));
  7239. +
  7240. + Symbol* exception_name;
  7241. + const size_t message_buffer_len = klass->name()->utf8_length() + 1024;
  7242. + char* message_buffer = NEW_RESOURCE_ARRAY(char, message_buffer_len);
  7243. +
  7244. + Thread::current()->set_pretend_new_universe(true);
  7245. + ClassVerifier split_verifier(klass, Thread::current());
  7246. + split_verifier.verify_method(jvf->method(), Thread::current());
  7247. + exception_name = split_verifier.result();
  7248. + Thread::current()->set_pretend_new_universe(false);
  7249. +
  7250. + if (exception_name != NULL) {
  7251. +
  7252. + RC_TRACE(0x00000001, ("Verification of class %s failed",
  7253. + jvf->method()->method_holder()->klass_part()->name()->as_C_string()));
  7254. + RC_TRACE(0x00000001, ("Exception: %s",
  7255. + exception_name->as_C_string()));
  7256. + RC_TRACE(0x00000001, ("Message: %s",
  7257. + message_buffer));
  7258. + Thread::current()->clear_pending_exception();
  7259. + return false;
  7260. + }
  7261. +
  7262. + }
  7263. + }
  7264. + }
  7265. + }
  7266. + }
  7267. + vf = vf->sender();
  7268. + }
  7269. }
  7270. +
  7271. + // Advance to next thread
  7272. + java_thread = java_thread->next();
  7273. }
  7274. return true;
  7275. }
  7276. +bool VM_RedefineClasses::check_method(methodOop method) {
  7277. -// Rewrite constant pool references in the specific method. This code
  7278. -// was adapted from Rewriter::rewrite_method().
  7279. -void VM_RedefineClasses::rewrite_cp_refs_in_method(methodHandle method,
  7280. - methodHandle *new_method_p, TRAPS) {
  7281. - *new_method_p = methodHandle(); // default is no new method
  7282. + return true;
  7283. +}
  7284. - // We cache a pointer to the bytecodes here in code_base. If GC
  7285. - // moves the methodOop, then the bytecodes will also move which
  7286. - // will likely cause a crash. We create a No_Safepoint_Verifier
  7287. - // object to detect whether we pass a possible safepoint in this
  7288. - // code block.
  7289. - No_Safepoint_Verifier nsv;
  7290. +// Warning: destroys redefinition level values of klasses.
  7291. +bool VM_RedefineClasses::check_loaded_methods() {
  7292. - // Bytecodes and their length
  7293. - address code_base = method->code_base();
  7294. - int code_length = method->code_size();
  7295. + class CheckLoadedMethodsClosure : public ObjectClosure {
  7296. - int bc_length;
  7297. - for (int bci = 0; bci < code_length; bci += bc_length) {
  7298. - address bcp = code_base + bci;
  7299. - Bytecodes::Code c = (Bytecodes::Code)(*bcp);
  7300. + private:
  7301. +
  7302. + bool _result;
  7303. + GrowableArray<klassOop> *_dangerous_klasses;
  7304. - bc_length = Bytecodes::length_for(c);
  7305. - if (bc_length == 0) {
  7306. - // More complicated bytecodes report a length of zero so
  7307. - // we have to try again a slightly different way.
  7308. - bc_length = Bytecodes::length_at(method(), bcp);
  7309. + public:
  7310. + CheckLoadedMethodsClosure(GrowableArray<klassOop> *dangerous_klasses) {
  7311. + _result = true;
  7312. + _dangerous_klasses = dangerous_klasses;
  7313. }
  7314. - assert(bc_length != 0, "impossible bytecode length");
  7315. + bool result() {
  7316. + return _result;
  7317. + }
  7318. - switch (c) {
  7319. - case Bytecodes::_ldc:
  7320. - {
  7321. - int cp_index = *(bcp + 1);
  7322. - int new_index = find_new_index(cp_index);
  7323. + bool is_class_dangerous(klassOop k) {
  7324. + return k->klass_part()->newest_version()->klass_part()->check_redefinition_flag(Klass::RemoveSuperType);
  7325. + }
  7326. - if (StressLdcRewrite && new_index == 0) {
  7327. - // If we are stressing ldc -> ldc_w rewriting, then we
  7328. - // always need a new_index value.
  7329. - new_index = cp_index;
  7330. - }
  7331. - if (new_index != 0) {
  7332. - // the original index is mapped so we have more work to do
  7333. - if (!StressLdcRewrite && new_index <= max_jubyte) {
  7334. - // The new value can still use ldc instead of ldc_w
  7335. - // unless we are trying to stress ldc -> ldc_w rewriting
  7336. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7337. - ("%s@" INTPTR_FORMAT " old=%d, new=%d", Bytecodes::name(c),
  7338. - bcp, cp_index, new_index));
  7339. - *(bcp + 1) = new_index;
  7340. - } else {
  7341. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7342. - ("%s->ldc_w@" INTPTR_FORMAT " old=%d, new=%d",
  7343. - Bytecodes::name(c), bcp, cp_index, new_index));
  7344. - // the new value needs ldc_w instead of ldc
  7345. - u_char inst_buffer[4]; // max instruction size is 4 bytes
  7346. - bcp = (address)inst_buffer;
  7347. - // construct new instruction sequence
  7348. - *bcp = Bytecodes::_ldc_w;
  7349. - bcp++;
  7350. - // Rewriter::rewrite_method() does not rewrite ldc -> ldc_w.
  7351. - // See comment below for difference between put_Java_u2()
  7352. - // and put_native_u2().
  7353. - Bytes::put_Java_u2(bcp, new_index);
  7354. -
  7355. - Relocator rc(method, NULL /* no RelocatorListener needed */);
  7356. - methodHandle m;
  7357. - {
  7358. - Pause_No_Safepoint_Verifier pnsv(&nsv);
  7359. -
  7360. - // ldc is 2 bytes and ldc_w is 3 bytes
  7361. - m = rc.insert_space_at(bci, 3, inst_buffer, THREAD);
  7362. - if (m.is_null() || HAS_PENDING_EXCEPTION) {
  7363. - guarantee(false, "insert_space_at() failed");
  7364. + bool can_be_affected(instanceKlass *klass) {
  7365. +
  7366. + constantPoolOop cp = klass->constants();
  7367. +
  7368. + Thread *THREAD = Thread::current();
  7369. + klassOop k;
  7370. + Symbol* symbol;
  7371. +
  7372. + for (int i=1; i<cp->length(); i++) {
  7373. + jbyte tag = cp->tag_at(i).value();
  7374. + switch(tag) {
  7375. + case JVM_CONSTANT_Long:
  7376. + case JVM_CONSTANT_Double:
  7377. + i++;
  7378. + break;
  7379. +
  7380. + case JVM_CONSTANT_Utf8:
  7381. + case JVM_CONSTANT_Unicode:
  7382. + case JVM_CONSTANT_Integer:
  7383. + case JVM_CONSTANT_Float:
  7384. + case JVM_CONSTANT_String:
  7385. + case JVM_CONSTANT_Fieldref:
  7386. + case JVM_CONSTANT_Methodref:
  7387. + case JVM_CONSTANT_InterfaceMethodref:
  7388. + case JVM_CONSTANT_ClassIndex:
  7389. + case JVM_CONSTANT_UnresolvedString:
  7390. + case JVM_CONSTANT_StringIndex:
  7391. + case JVM_CONSTANT_UnresolvedClassInError:
  7392. + case JVM_CONSTANT_Object:
  7393. + // do nothing
  7394. + break;
  7395. +
  7396. + case JVM_CONSTANT_Class:
  7397. + k = cp->klass_at(i, CHECK_(true));
  7398. + if (is_class_dangerous(k)) {
  7399. + RC_TRACE(0x00000002, ("Class %s is potentially affected, because at cp[%d] references class %s",
  7400. + klass->name()->as_C_string(),
  7401. + i,
  7402. + k->klass_part()->name()->as_C_string()));
  7403. + return true;
  7404. + }
  7405. + break;
  7406. +
  7407. + case JVM_CONSTANT_NameAndType:
  7408. + symbol = cp->symbol_at(cp->signature_ref_index_at(i));
  7409. + if (symbol->byte_at(0) == '(') {
  7410. + // This must be a method
  7411. + SignatureStream signatureStream(symbol);
  7412. + while (true) {
  7413. +
  7414. + if (signatureStream.is_array()) {
  7415. + Symbol* cur_signature = signatureStream.as_symbol(Thread::current());
  7416. + if (is_type_signature_dangerous(cur_signature)) {
  7417. + return true;
  7418. + }
  7419. + } else if (signatureStream.is_object()) {
  7420. + if (is_symbol_dangerous(signatureStream.as_symbol(Thread::current()))) {
  7421. + return true;
  7422. + }
  7423. + }
  7424. +
  7425. + if (signatureStream.at_return_type()) {
  7426. + break;
  7427. + }
  7428. +
  7429. + signatureStream.next();
  7430. }
  7431. +
  7432. + } else if (is_type_signature_dangerous(symbol)) {
  7433. + return true;
  7434. }
  7435. + break;
  7436. - // return the new method so that the caller can update
  7437. - // the containing class
  7438. - *new_method_p = method = m;
  7439. - // switch our bytecode processing loop from the old method
  7440. - // to the new method
  7441. - code_base = method->code_base();
  7442. - code_length = method->code_size();
  7443. - bcp = code_base + bci;
  7444. - c = (Bytecodes::Code)(*bcp);
  7445. - bc_length = Bytecodes::length_for(c);
  7446. - assert(bc_length != 0, "sanity check");
  7447. - } // end we need ldc_w instead of ldc
  7448. - } // end if there is a mapped index
  7449. - } break;
  7450. -
  7451. - // these bytecodes have a two-byte constant pool index
  7452. - case Bytecodes::_anewarray : // fall through
  7453. - case Bytecodes::_checkcast : // fall through
  7454. - case Bytecodes::_getfield : // fall through
  7455. - case Bytecodes::_getstatic : // fall through
  7456. - case Bytecodes::_instanceof : // fall through
  7457. - case Bytecodes::_invokedynamic : // fall through
  7458. - case Bytecodes::_invokeinterface: // fall through
  7459. - case Bytecodes::_invokespecial : // fall through
  7460. - case Bytecodes::_invokestatic : // fall through
  7461. - case Bytecodes::_invokevirtual : // fall through
  7462. - case Bytecodes::_ldc_w : // fall through
  7463. - case Bytecodes::_ldc2_w : // fall through
  7464. - case Bytecodes::_multianewarray : // fall through
  7465. - case Bytecodes::_new : // fall through
  7466. - case Bytecodes::_putfield : // fall through
  7467. - case Bytecodes::_putstatic :
  7468. - {
  7469. - address p = bcp + 1;
  7470. - int cp_index = Bytes::get_Java_u2(p);
  7471. - int new_index = find_new_index(cp_index);
  7472. - if (new_index != 0) {
  7473. - // the original index is mapped so update w/ new value
  7474. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7475. - ("%s@" INTPTR_FORMAT " old=%d, new=%d", Bytecodes::name(c),
  7476. - bcp, cp_index, new_index));
  7477. - // Rewriter::rewrite_method() uses put_native_u2() in this
  7478. - // situation because it is reusing the constant pool index
  7479. - // location for a native index into the constantPoolCache.
  7480. - // Since we are updating the constant pool index prior to
  7481. - // verification and constantPoolCache initialization, we
  7482. - // need to keep the new index in Java byte order.
  7483. - Bytes::put_Java_u2(p, new_index);
  7484. + case JVM_CONSTANT_UnresolvedClass:
  7485. + symbol = cp->unresolved_klass_at(i);
  7486. + if (is_symbol_dangerous(symbol)) {
  7487. + return true;
  7488. + }
  7489. + break;
  7490. +
  7491. + default:
  7492. + ShouldNotReachHere();
  7493. + }
  7494. + }
  7495. +
  7496. + return false;
  7497. + }
  7498. +
  7499. + bool is_type_signature_dangerous(Symbol* signature) {
  7500. + // This must be a field type
  7501. + if (FieldType::is_obj(signature)) {
  7502. + Symbol* name = signature_to_class_name(signature);
  7503. + if (is_symbol_dangerous(name)) {
  7504. + return true;
  7505. + }
  7506. + } else if (FieldType::is_array(signature)) {
  7507. + //jint dimension;
  7508. + //Symbol* object_key;
  7509. + FieldArrayInfo fd;
  7510. + FieldType::get_array_info(signature, fd, Thread::current());
  7511. + if (is_symbol_dangerous(fd.object_key())) {
  7512. + return true;
  7513. }
  7514. - } break;
  7515. + }
  7516. + return false;
  7517. }
  7518. - } // end for each bytecode
  7519. -} // end rewrite_cp_refs_in_method()
  7520. + bool is_symbol_dangerous(Symbol* symbol) {
  7521. + for (int i=0; i<_dangerous_klasses->length(); i++) {
  7522. + if(_dangerous_klasses->at(i)->klass_part()->name() == symbol) {
  7523. + RC_TRACE(0x00000002, ("Found constant pool index %d references class %s",
  7524. + i,
  7525. + symbol->as_C_string()));
  7526. + return true;
  7527. + }
  7528. + }
  7529. + return false;
  7530. + }
  7531. +
  7532. + virtual void do_object(oop obj) {
  7533. +
  7534. + if (!_result) return;
  7535. -// Rewrite constant pool references in the class_annotations field.
  7536. -bool VM_RedefineClasses::rewrite_cp_refs_in_class_annotations(
  7537. - instanceKlassHandle scratch_class, TRAPS) {
  7538. + klassOop klassObj = (klassOop)obj;
  7539. + Thread *THREAD = Thread::current();
  7540. +
  7541. + // We found an instance klass!
  7542. + instanceKlass *klass = instanceKlass::cast(klassObj);
  7543. + instanceKlassHandle handle(klassObj);
  7544. +
  7545. + RC_TRACE(0x00000400, ("Check if verification is necessary for class %s major_version=%d", handle->name()->as_C_string(), handle->major_version()));
  7546. +
  7547. + if (!can_be_affected(klass)) {
  7548. + RC_TRACE(0x00000400, ("Skipping verification of class %s major_version=%d", handle->name()->as_C_string(), handle->major_version()));
  7549. + return;
  7550. + }
  7551. +
  7552. + if (handle->major_version() < Verifier::STACKMAP_ATTRIBUTE_MAJOR_VERSION) {
  7553. + RC_TRACE(0x00000001, ("Failing because cannot verify class %s major_version=%d", handle->name()->as_C_string(), handle->major_version()));
  7554. + _result = false;
  7555. + return;
  7556. + }
  7557. +
  7558. + RC_TRACE(0x00000001, ("Verifying class %s", handle->name()->as_C_string()));
  7559. +
  7560. + if (!Verifier::verify(handle, Verifier::NoException, true, false, Thread::current())) {
  7561. +
  7562. + RC_TRACE(0x00000001, ("Verification of class %s failed", handle->name()->as_C_string()));
  7563. + //Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  7564. + //RC_TRACE(0x00000002, ("exception when verifying class: '%s'", ex_name->as_C_string());
  7565. + //PENDING_EXCEPTION->print();
  7566. + CLEAR_PENDING_EXCEPTION;
  7567. + _result = false;
  7568. + }
  7569. +
  7570. + /*int method_count = klass->methods()->length();
  7571. + for (int i=0; i<method_count; i++) {
  7572. + methodOop cur_method = (methodOop)klass->methods()->obj_at(i);
  7573. + if (!check_method(cur_method)) {
  7574. + RC_TRACE(0x00000001, ("Failed to verify consistency of method %s of klass %s", cur_method->name()->as_C_string(), klass->name()->as_C_string());
  7575. + }
  7576. + }*/
  7577. + }
  7578. + };
  7579. - typeArrayHandle class_annotations(THREAD,
  7580. - scratch_class->class_annotations());
  7581. - if (class_annotations.is_null() || class_annotations->length() == 0) {
  7582. - // no class_annotations so nothing to do
  7583. - return true;
  7584. + // TODO: Check bytecodes in case of interface => class or class => interface etc..
  7585. +
  7586. + GrowableArray<klassOop> dangerous_klasses;
  7587. + for (int i=0; i<_new_classes->length(); i++) {
  7588. + instanceKlassHandle handle = _new_classes->at(i);
  7589. + if (handle->check_redefinition_flag(Klass::RemoveSuperType)) {
  7590. + dangerous_klasses.append(handle());
  7591. + }
  7592. }
  7593. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7594. - ("class_annotations length=%d", class_annotations->length()));
  7595. + CheckLoadedMethodsClosure checkLoadedMethodsClosure(&dangerous_klasses);
  7596. + Thread::current()->set_pretend_new_universe(true);
  7597. + SystemDictionary::classes_do(&checkLoadedMethodsClosure);
  7598. + Thread::current()->set_pretend_new_universe(false);
  7599. +
  7600. - int byte_i = 0; // byte index into class_annotations
  7601. - return rewrite_cp_refs_in_annotations_typeArray(class_annotations, byte_i,
  7602. - THREAD);
  7603. + return checkLoadedMethodsClosure.result();
  7604. }
  7605. +bool VM_RedefineClasses::check_type_consistency() {
  7606. -// Rewrite constant pool references in an annotations typeArray. This
  7607. -// "structure" is adapted from the RuntimeVisibleAnnotations_attribute
  7608. -// that is described in section 4.8.15 of the 2nd-edition of the VM spec:
  7609. -//
  7610. -// annotations_typeArray {
  7611. -// u2 num_annotations;
  7612. -// annotation annotations[num_annotations];
  7613. -// }
  7614. -//
  7615. -bool VM_RedefineClasses::rewrite_cp_refs_in_annotations_typeArray(
  7616. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  7617. + Universe::set_verify_in_progress(true);
  7618. +
  7619. + SystemDictionary::classes_do(calculate_type_check_information);
  7620. + bool result = check_field_value_types();
  7621. + SystemDictionary::classes_do(clear_type_check_information);
  7622. + if (!result) {
  7623. + RC_TRACE(0x00000001, ("Aborting redefinition because of wrong field or array element value!"));
  7624. + Universe::set_verify_in_progress(false);
  7625. + return false;
  7626. + }
  7627. +
  7628. + result = check_method_stacks();
  7629. + if (!result) {
  7630. + RC_TRACE(0x00000001, ("Aborting redefinition because of wrong value on the stack"));
  7631. + Universe::set_verify_in_progress(false);
  7632. + return false;
  7633. + }
  7634. +
  7635. + result = check_loaded_methods();
  7636. + if (!result) {
  7637. + RC_TRACE(0x00000001, ("Aborting redefinition because of wrong loaded method"));
  7638. + Universe::set_verify_in_progress(false);
  7639. + return false;
  7640. + }
  7641. +
  7642. + RC_TRACE(0x00000001, ("Verification passed => hierarchy change is valid!"));
  7643. + Universe::set_verify_in_progress(false);
  7644. + return true;
  7645. +}
  7646. +
  7647. +void VM_RedefineClasses::rollback() {
  7648. + RC_TRACE(0x00000001, ("Rolling back redefinition!"));
  7649. + SystemDictionary::rollback_redefinition();
  7650. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  7651. - // not enough room for num_annotations field
  7652. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7653. - ("length() is too small for num_annotations field"));
  7654. - return false;
  7655. + RC_TRACE(0x00000001, ("After rolling back system dictionary!"));
  7656. + for (int i=0; i<_new_classes->length(); i++) {
  7657. + SystemDictionary::remove_from_hierarchy(_new_classes->at(i));
  7658. }
  7659. - u2 num_annotations = Bytes::get_Java_u2((address)
  7660. - annotations_typeArray->byte_at_addr(byte_i_ref));
  7661. - byte_i_ref += 2;
  7662. + for (int i=0; i<_new_classes->length(); i++) {
  7663. + instanceKlassHandle new_class = _new_classes->at(i);
  7664. + new_class->set_redefining(false);
  7665. + new_class->old_version()->klass_part()->set_new_version(NULL);
  7666. + new_class->set_old_version(NULL);
  7667. + }
  7668. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7669. - ("num_annotations=%d", num_annotations));
  7670. +}
  7671. - int calc_num_annotations = 0;
  7672. - for (; calc_num_annotations < num_annotations; calc_num_annotations++) {
  7673. - if (!rewrite_cp_refs_in_annotation_struct(annotations_typeArray,
  7674. - byte_i_ref, THREAD)) {
  7675. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7676. - ("bad annotation_struct at %d", calc_num_annotations));
  7677. - // propagate failure back to caller
  7678. - return false;
  7679. +template <class T> void VM_RedefineClasses::do_oop_work(T* p) {
  7680. + T heap_oop = oopDesc::load_heap_oop(p);
  7681. + if (!oopDesc::is_null(heap_oop)) {
  7682. + oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
  7683. + if (obj->is_instanceKlass()) {
  7684. + klassOop klass = (klassOop)obj;
  7685. + // DCEVM: note: can overwrite owner of old_klass constants pool with new_klass, so we need to fix it back later
  7686. + if (klass->new_version() != NULL && klass->new_version()->klass_part()->is_redefining()) {
  7687. + obj = klass->klass_part()->new_version();
  7688. + oopDesc::encode_store_heap_oop_not_null(p, obj);
  7689. + }
  7690. + } else if (obj->blueprint()->newest_version() == SystemDictionary::Class_klass()->klass_part()->newest_version()) {
  7691. + // update references to java.lang.Class to point to newest version. Only update references to non-primitive
  7692. + // java.lang.Class instances.
  7693. + klassOop klass_oop = java_lang_Class::as_klassOop(obj);
  7694. + if (klass_oop != NULL) {
  7695. + if (klass_oop->new_version() != NULL && klass_oop->new_version()->klass_part()->is_redefining()) {
  7696. + obj = klass_oop->new_version()->java_mirror();
  7697. + } else if (klass_oop->klass_part()->is_redefining()) {
  7698. + obj = klass_oop->java_mirror();
  7699. + }
  7700. + oopDesc::encode_store_heap_oop_not_null(p, obj);
  7701. +
  7702. +
  7703. + // FIXME: DCEVM: better implementation?
  7704. + // Starting from JDK 7 java_mirror can be kept in the regular heap. Therefore, it is possible
  7705. + // that new java_mirror is in the young generation whereas p is in tenured generation. In that
  7706. + // case we need to run write barrier to make sure card table is properly updated. This will
  7707. + // allow JVM to detect reference in tenured generation properly during young generation GC.
  7708. + if (Universe::heap()->is_in_reserved(p)) {
  7709. + if (GenCollectedHeap::heap()->is_in_young(obj)) {
  7710. + GenRemSet* rs = GenCollectedHeap::heap()->rem_set();
  7711. + assert(rs->rs_kind() == GenRemSet::CardTable, "Wrong rem set kind.");
  7712. + CardTableRS* _rs = (CardTableRS*)rs;
  7713. + _rs->inline_write_ref_field_gc(p, obj);
  7714. + }
  7715. + }
  7716. + }
  7717. }
  7718. }
  7719. - assert(num_annotations == calc_num_annotations, "sanity check");
  7720. +}
  7721. - return true;
  7722. -} // end rewrite_cp_refs_in_annotations_typeArray()
  7723. +void VM_RedefineClasses::swap_marks(oop first, oop second) {
  7724. + markOop first_mark = first->mark();
  7725. + markOop second_mark = second->mark();
  7726. + first->set_mark(second_mark);
  7727. + second->set_mark(first_mark);
  7728. +}
  7729. +void VM_RedefineClasses::doit() {
  7730. + Thread *thread = Thread::current();
  7731. -// Rewrite constant pool references in the annotation struct portion of
  7732. -// an annotations_typeArray. This "structure" is from section 4.8.15 of
  7733. -// the 2nd-edition of the VM spec:
  7734. -//
  7735. -// struct annotation {
  7736. -// u2 type_index;
  7737. -// u2 num_element_value_pairs;
  7738. -// {
  7739. -// u2 element_name_index;
  7740. -// element_value value;
  7741. -// } element_value_pairs[num_element_value_pairs];
  7742. -// }
  7743. -//
  7744. -bool VM_RedefineClasses::rewrite_cp_refs_in_annotation_struct(
  7745. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  7746. - if ((byte_i_ref + 2 + 2) > annotations_typeArray->length()) {
  7747. - // not enough room for smallest annotation_struct
  7748. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7749. - ("length() is too small for annotation_struct"));
  7750. - return false;
  7751. - }
  7752. + RC_TRACE(0x00000001, ("Entering doit!"));
  7753. - u2 type_index = rewrite_cp_ref_in_annotation_data(annotations_typeArray,
  7754. - byte_i_ref, "mapped old type_index=%d", THREAD);
  7755. - u2 num_element_value_pairs = Bytes::get_Java_u2((address)
  7756. - annotations_typeArray->byte_at_addr(
  7757. - byte_i_ref));
  7758. - byte_i_ref += 2;
  7759. + if ((_max_redefinition_flags & Klass::RemoveSuperType) != 0) {
  7760. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7761. - ("type_index=%d num_element_value_pairs=%d", type_index,
  7762. - num_element_value_pairs));
  7763. + RC_TIMER_START(_timer_check_type);
  7764. - int calc_num_element_value_pairs = 0;
  7765. - for (; calc_num_element_value_pairs < num_element_value_pairs;
  7766. - calc_num_element_value_pairs++) {
  7767. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  7768. - // not enough room for another element_name_index, let alone
  7769. - // the rest of another component
  7770. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7771. - ("length() is too small for element_name_index"));
  7772. - return false;
  7773. + if (!check_type_consistency()) {
  7774. + // (tw) TODO: Rollback the class redefinition
  7775. + rollback();
  7776. + RC_TRACE(0x00000001, ("Detected type inconsistency!"));
  7777. + _result = JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  7778. + RC_TIMER_STOP(_timer_check_type);
  7779. + return;
  7780. }
  7781. - u2 element_name_index = rewrite_cp_ref_in_annotation_data(
  7782. - annotations_typeArray, byte_i_ref,
  7783. - "mapped old element_name_index=%d", THREAD);
  7784. + RC_TIMER_STOP(_timer_check_type);
  7785. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7786. - ("element_name_index=%d", element_name_index));
  7787. + } else {
  7788. + RC_TRACE(0x00000001, ("No type narrowing => skipping check for type inconsistency"));
  7789. + }
  7790. - if (!rewrite_cp_refs_in_element_value(annotations_typeArray,
  7791. - byte_i_ref, THREAD)) {
  7792. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7793. - ("bad element_value at %d", calc_num_element_value_pairs));
  7794. - // propagate failure back to caller
  7795. - return false;
  7796. + if (UseMethodForwardPoints) {
  7797. + RC_TRACE(0x00000001, ("Check stack for forwarding methods to new version"));
  7798. + method_forwarding();
  7799. + }
  7800. +
  7801. + if (UseSharedSpaces) {
  7802. + // Sharing is enabled so we remap the shared readonly space to
  7803. + // shared readwrite, private just in case we need to redefine
  7804. + // a shared class. We do the remap during the doit() phase of
  7805. + // the safepoint to be safer.
  7806. + if (!CompactingPermGenGen::remap_shared_readonly_as_readwrite()) {
  7807. + RC_TRACE(0x00000001, ("failed to remap shared readonly space to readwrite, private"));
  7808. + _result = JVMTI_ERROR_INTERNAL;
  7809. + return;
  7810. }
  7811. - } // end for each component
  7812. - assert(num_element_value_pairs == calc_num_element_value_pairs,
  7813. - "sanity check");
  7814. + }
  7815. - return true;
  7816. -} // end rewrite_cp_refs_in_annotation_struct()
  7817. -
  7818. -
  7819. -// Rewrite a constant pool reference at the current position in
  7820. -// annotations_typeArray if needed. Returns the original constant
  7821. -// pool reference if a rewrite was not needed or the new constant
  7822. -// pool reference if a rewrite was needed.
  7823. -u2 VM_RedefineClasses::rewrite_cp_ref_in_annotation_data(
  7824. - typeArrayHandle annotations_typeArray, int &byte_i_ref,
  7825. - const char * trace_mesg, TRAPS) {
  7826. -
  7827. - address cp_index_addr = (address)
  7828. - annotations_typeArray->byte_at_addr(byte_i_ref);
  7829. - u2 old_cp_index = Bytes::get_Java_u2(cp_index_addr);
  7830. - u2 new_cp_index = find_new_index(old_cp_index);
  7831. - if (new_cp_index != 0) {
  7832. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, (trace_mesg, old_cp_index));
  7833. - Bytes::put_Java_u2(cp_index_addr, new_cp_index);
  7834. - old_cp_index = new_cp_index;
  7835. - }
  7836. - byte_i_ref += 2;
  7837. - return old_cp_index;
  7838. -}
  7839. + RC_TIMER_START(_timer_prepare_redefinition);
  7840. + for (int i = 0; i < _new_classes->length(); i++) {
  7841. + redefine_single_class(_new_classes->at(i), thread);
  7842. + }
  7843. + // Deoptimize all compiled code that depends on this class
  7844. + flush_dependent_code(instanceKlassHandle(Thread::current(), (klassOop)NULL), Thread::current());
  7845. -// Rewrite constant pool references in the element_value portion of an
  7846. -// annotations_typeArray. This "structure" is from section 4.8.15.1 of
  7847. -// the 2nd-edition of the VM spec:
  7848. -//
  7849. -// struct element_value {
  7850. -// u1 tag;
  7851. -// union {
  7852. -// u2 const_value_index;
  7853. -// {
  7854. -// u2 type_name_index;
  7855. -// u2 const_name_index;
  7856. -// } enum_const_value;
  7857. -// u2 class_info_index;
  7858. -// annotation annotation_value;
  7859. -// struct {
  7860. -// u2 num_values;
  7861. -// element_value values[num_values];
  7862. -// } array_value;
  7863. -// } value;
  7864. -// }
  7865. -//
  7866. -bool VM_RedefineClasses::rewrite_cp_refs_in_element_value(
  7867. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  7868. + // Adjust constantpool caches and vtables for all classes
  7869. + // that reference methods of the evolved class.
  7870. + SystemDictionary::classes_do(adjust_cpool_cache, Thread::current());
  7871. - if ((byte_i_ref + 1) > annotations_typeArray->length()) {
  7872. - // not enough room for a tag let alone the rest of an element_value
  7873. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7874. - ("length() is too small for a tag"));
  7875. - return false;
  7876. - }
  7877. + RC_TIMER_STOP(_timer_prepare_redefinition);
  7878. + RC_TIMER_START(_timer_redefinition);
  7879. - u1 tag = annotations_typeArray->byte_at(byte_i_ref);
  7880. - byte_i_ref++;
  7881. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("tag='%c'", tag));
  7882. -
  7883. - switch (tag) {
  7884. - // These BaseType tag values are from Table 4.2 in VM spec:
  7885. - case 'B': // byte
  7886. - case 'C': // char
  7887. - case 'D': // double
  7888. - case 'F': // float
  7889. - case 'I': // int
  7890. - case 'J': // long
  7891. - case 'S': // short
  7892. - case 'Z': // boolean
  7893. -
  7894. - // The remaining tag values are from Table 4.8 in the 2nd-edition of
  7895. - // the VM spec:
  7896. - case 's':
  7897. - {
  7898. - // For the above tag values (including the BaseType values),
  7899. - // value.const_value_index is right union field.
  7900. + class ChangePointersOopClosure : public OopClosure {
  7901. + virtual void do_oop(oop* o) {
  7902. + do_oop_work(o);
  7903. + }
  7904. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  7905. - // not enough room for a const_value_index
  7906. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7907. - ("length() is too small for a const_value_index"));
  7908. - return false;
  7909. + virtual void do_oop(narrowOop* o) {
  7910. + do_oop_work(o);
  7911. }
  7912. + };
  7913. - u2 const_value_index = rewrite_cp_ref_in_annotation_data(
  7914. - annotations_typeArray, byte_i_ref,
  7915. - "mapped old const_value_index=%d", THREAD);
  7916. + class ChangePointersObjectClosure : public ObjectClosure {
  7917. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7918. - ("const_value_index=%d", const_value_index));
  7919. - } break;
  7920. + private:
  7921. - case 'e':
  7922. - {
  7923. - // for the above tag value, value.enum_const_value is right union field
  7924. + OopClosure *_closure;
  7925. + bool _needs_instance_update;
  7926. + GrowableArray<oop> *_updated_oops;
  7927. - if ((byte_i_ref + 4) > annotations_typeArray->length()) {
  7928. - // not enough room for a enum_const_value
  7929. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7930. - ("length() is too small for a enum_const_value"));
  7931. - return false;
  7932. - }
  7933. + public:
  7934. + ChangePointersObjectClosure(OopClosure *closure) : _closure(closure), _needs_instance_update(false), _updated_oops(NULL) {}
  7935. - u2 type_name_index = rewrite_cp_ref_in_annotation_data(
  7936. - annotations_typeArray, byte_i_ref,
  7937. - "mapped old type_name_index=%d", THREAD);
  7938. + bool needs_instance_update() {
  7939. + return _needs_instance_update;
  7940. + }
  7941. - u2 const_name_index = rewrite_cp_ref_in_annotation_data(
  7942. - annotations_typeArray, byte_i_ref,
  7943. - "mapped old const_name_index=%d", THREAD);
  7944. + GrowableArray<oop> *updated_oops() { return _updated_oops; }
  7945. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7946. - ("type_name_index=%d const_name_index=%d", type_name_index,
  7947. - const_name_index));
  7948. - } break;
  7949. + virtual void do_object(oop obj) {
  7950. + if (!obj->is_instanceKlass()) {
  7951. + obj->oop_iterate(_closure);
  7952. +
  7953. + if (obj->blueprint()->is_redefining()) {
  7954. - case 'c':
  7955. - {
  7956. - // for the above tag value, value.class_info_index is right union field
  7957. + if (obj->blueprint()->check_redefinition_flag(Klass::HasInstanceTransformer)) {
  7958. + if (_updated_oops == NULL) {
  7959. + _updated_oops = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<oop>(100, true);
  7960. + }
  7961. + _updated_oops->append(obj);
  7962. + }
  7963. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  7964. - // not enough room for a class_info_index
  7965. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7966. - ("length() is too small for a class_info_index"));
  7967. - return false;
  7968. - }
  7969. + if(obj->blueprint()->update_information() != NULL || obj->is_perm()) {
  7970. - u2 class_info_index = rewrite_cp_ref_in_annotation_data(
  7971. - annotations_typeArray, byte_i_ref,
  7972. - "mapped old class_info_index=%d", THREAD);
  7973. + assert(obj->blueprint()->old_version() != NULL, "must have old version");
  7974. + obj->set_klass_no_check(obj->blueprint()->old_version());
  7975. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7976. - ("class_info_index=%d", class_info_index));
  7977. - } break;
  7978. + if (obj->size() != obj->size_given_klass(obj->blueprint()->new_version()->klass_part()) || obj->is_perm()) {
  7979. + // We need an instance update => set back to old klass
  7980. + _needs_instance_update = true;
  7981. - case '@':
  7982. - // For the above tag value, value.attr_value is the right union
  7983. - // field. This is a nested annotation.
  7984. - if (!rewrite_cp_refs_in_annotation_struct(annotations_typeArray,
  7985. - byte_i_ref, THREAD)) {
  7986. - // propagate failure back to caller
  7987. - return false;
  7988. - }
  7989. - break;
  7990. + } else {
  7991. + MarkSweep::update_fields(obj, obj);
  7992. + assert(obj->blueprint()->is_redefining(), "update fields resets the klass");
  7993. + }
  7994. + }
  7995. + }
  7996. - case '[':
  7997. - {
  7998. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  7999. - // not enough room for a num_values field
  8000. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8001. - ("length() is too small for a num_values field"));
  8002. - return false;
  8003. - }
  8004. -
  8005. - // For the above tag value, value.array_value is the right union
  8006. - // field. This is an array of nested element_value.
  8007. - u2 num_values = Bytes::get_Java_u2((address)
  8008. - annotations_typeArray->byte_at_addr(byte_i_ref));
  8009. - byte_i_ref += 2;
  8010. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("num_values=%d", num_values));
  8011. -
  8012. - int calc_num_values = 0;
  8013. - for (; calc_num_values < num_values; calc_num_values++) {
  8014. - if (!rewrite_cp_refs_in_element_value(
  8015. - annotations_typeArray, byte_i_ref, THREAD)) {
  8016. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8017. - ("bad nested element_value at %d", calc_num_values));
  8018. - // propagate failure back to caller
  8019. - return false;
  8020. + } else {
  8021. + instanceKlass *klass = instanceKlass::cast((klassOop)obj);
  8022. + if (klass->is_redefining()) {
  8023. + // DCEVM: We need to restorte constants pool owner which was updated by do_oop_work
  8024. + instanceKlass* old_klass = instanceKlass::cast(klass->old_version());
  8025. + old_klass->constants()->set_pool_holder(klass->old_version());
  8026. +
  8027. + // Initialize the new class! Special static initialization that does not execute the
  8028. + // static constructor but copies static field values from the old class if name
  8029. + // and signature of a static field match.
  8030. + klass->initialize_redefined_class();
  8031. + }
  8032. + // idubrov: FIXME: we probably don't need that since oop's will be visited in a regular way...
  8033. + // idubrov: need to check if there is a test to verify that fields referencing class being updated
  8034. + // idubrov: will get new version of that class
  8035. + //klass->iterate_static_fields(_closure);
  8036. }
  8037. }
  8038. - assert(num_values == calc_num_values, "sanity check");
  8039. - } break;
  8040. + };
  8041. - default:
  8042. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("bad tag=0x%x", tag));
  8043. - return false;
  8044. - } // end decode tag field
  8045. + ChangePointersOopClosure oopClosure;
  8046. + ChangePointersObjectClosure objectClosure(&oopClosure);
  8047. - return true;
  8048. -} // end rewrite_cp_refs_in_element_value()
  8049. + {
  8050. + SharedHeap::heap()->gc_prologue(true);
  8051. + Universe::root_oops_do(&oopClosure);
  8052. + Universe::heap()->object_iterate(&objectClosure);
  8053. + SharedHeap::heap()->gc_epilogue(false);
  8054. + }
  8055. + // Swap marks to have same hashcodes
  8056. + for (int i=0; i<_new_classes->length(); i++) {
  8057. + swap_marks(_new_classes->at(i)(), _new_classes->at(i)->old_version());
  8058. + swap_marks(_new_classes->at(i)->java_mirror(), _new_classes->at(i)->old_version()->java_mirror());
  8059. + }
  8060. -// Rewrite constant pool references in a fields_annotations field.
  8061. -bool VM_RedefineClasses::rewrite_cp_refs_in_fields_annotations(
  8062. - instanceKlassHandle scratch_class, TRAPS) {
  8063. + _updated_oops = objectClosure.updated_oops();
  8064. - objArrayHandle fields_annotations(THREAD,
  8065. - scratch_class->fields_annotations());
  8066. + if (objectClosure.needs_instance_update()){
  8067. - if (fields_annotations.is_null() || fields_annotations->length() == 0) {
  8068. - // no fields_annotations so nothing to do
  8069. - return true;
  8070. + // Do a full garbage collection to update the instance sizes accordingly
  8071. + RC_TRACE(0x00000001, ("Before performing full GC!"));
  8072. + Universe::set_redefining_gc_run(true);
  8073. + JvmtiGCMarker jgcm;
  8074. + notify_gc_begin(true);
  8075. + Universe::heap()->collect_as_vm_thread(GCCause::_heap_inspection);
  8076. + notify_gc_end();
  8077. + Universe::set_redefining_gc_run(false);
  8078. + RC_TRACE(0x00000001, ("GC done!"));
  8079. }
  8080. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8081. - ("fields_annotations length=%d", fields_annotations->length()));
  8082. -
  8083. - for (int i = 0; i < fields_annotations->length(); i++) {
  8084. - typeArrayHandle field_annotations(THREAD,
  8085. - (typeArrayOop)fields_annotations->obj_at(i));
  8086. - if (field_annotations.is_null() || field_annotations->length() == 0) {
  8087. - // this field does not have any annotations so skip it
  8088. - continue;
  8089. - }
  8090. - int byte_i = 0; // byte index into field_annotations
  8091. - if (!rewrite_cp_refs_in_annotations_typeArray(field_annotations, byte_i,
  8092. - THREAD)) {
  8093. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8094. - ("bad field_annotations at %d", i));
  8095. - // propagate failure back to caller
  8096. - return false;
  8097. + if (RC_TRACE_ENABLED(0x00000001)) {
  8098. + if (_updated_oops != NULL) {
  8099. + RC_TRACE(0x00000001, ("%d object(s) updated!", _updated_oops->length()));
  8100. + } else {
  8101. + RC_TRACE(0x00000001, ("No objects updated!"));
  8102. }
  8103. }
  8104. - return true;
  8105. -} // end rewrite_cp_refs_in_fields_annotations()
  8106. -
  8107. + // Unmark klassOops as "redefining"
  8108. + for (int i=0; i<_new_classes->length(); i++) {
  8109. + klassOop cur = _new_classes->at(i)();
  8110. + _new_classes->at(i)->set_redefining(false);
  8111. + _new_classes->at(i)->clear_update_information();
  8112. + _new_classes->at(i)->update_supers_to_newest_version();
  8113. -// Rewrite constant pool references in a methods_annotations field.
  8114. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_annotations(
  8115. - instanceKlassHandle scratch_class, TRAPS) {
  8116. + if (((instanceKlass *)cur->klass_part()->old_version()->klass_part())->array_klasses() != NULL) {
  8117. + update_array_classes_to_newest_version(((instanceKlass *)cur->klass_part()->old_version()->klass_part())->array_klasses());
  8118. - objArrayHandle methods_annotations(THREAD,
  8119. - scratch_class->methods_annotations());
  8120. + // Transfer the array classes, otherwise we might get cast exceptions when casting array types.
  8121. + ((instanceKlass*)cur->klass_part())->set_array_klasses(((instanceKlass*)cur->klass_part()->old_version()->klass_part())->array_klasses());
  8122. - if (methods_annotations.is_null() || methods_annotations->length() == 0) {
  8123. - // no methods_annotations so nothing to do
  8124. - return true;
  8125. - }
  8126. -
  8127. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8128. - ("methods_annotations length=%d", methods_annotations->length()));
  8129. -
  8130. - for (int i = 0; i < methods_annotations->length(); i++) {
  8131. - typeArrayHandle method_annotations(THREAD,
  8132. - (typeArrayOop)methods_annotations->obj_at(i));
  8133. - if (method_annotations.is_null() || method_annotations->length() == 0) {
  8134. - // this method does not have any annotations so skip it
  8135. - continue;
  8136. + oop new_mirror = _new_classes->at(i)->java_mirror();
  8137. + oop old_mirror = _new_classes->at(i)->old_version()->java_mirror();
  8138. + java_lang_Class::set_array_klass(new_mirror, java_lang_Class::array_klass(old_mirror));
  8139. }
  8140. + }
  8141. - int byte_i = 0; // byte index into method_annotations
  8142. - if (!rewrite_cp_refs_in_annotations_typeArray(method_annotations, byte_i,
  8143. - THREAD)) {
  8144. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8145. - ("bad method_annotations at %d", i));
  8146. - // propagate failure back to caller
  8147. - return false;
  8148. - }
  8149. + for (int i=T_BOOLEAN; i<=T_LONG; i++) {
  8150. + update_array_classes_to_newest_version(Universe::typeArrayKlassObj((BasicType)i));
  8151. }
  8152. - return true;
  8153. -} // end rewrite_cp_refs_in_methods_annotations()
  8154. + // Disable any dependent concurrent compilations
  8155. + SystemDictionary::notice_modification();
  8156. +
  8157. + // Set flag indicating that some invariants are no longer true.
  8158. + // See jvmtiExport.hpp for detailed explanation.
  8159. + JvmtiExport::set_has_redefined_a_class();
  8160. + // Clean up caches in the compiler interface and compiler threads
  8161. + CompileBroker::cleanup_after_redefinition();
  8162. -// Rewrite constant pool references in a methods_parameter_annotations
  8163. -// field. This "structure" is adapted from the
  8164. -// RuntimeVisibleParameterAnnotations_attribute described in section
  8165. -// 4.8.17 of the 2nd-edition of the VM spec:
  8166. -//
  8167. -// methods_parameter_annotations_typeArray {
  8168. -// u1 num_parameters;
  8169. -// {
  8170. -// u2 num_annotations;
  8171. -// annotation annotations[num_annotations];
  8172. -// } parameter_annotations[num_parameters];
  8173. -// }
  8174. -//
  8175. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_parameter_annotations(
  8176. - instanceKlassHandle scratch_class, TRAPS) {
  8177. +#ifdef ASSERT
  8178. - objArrayHandle methods_parameter_annotations(THREAD,
  8179. - scratch_class->methods_parameter_annotations());
  8180. + // Universe::verify();
  8181. + // JNIHandles::verify();
  8182. - if (methods_parameter_annotations.is_null()
  8183. - || methods_parameter_annotations->length() == 0) {
  8184. - // no methods_parameter_annotations so nothing to do
  8185. - return true;
  8186. - }
  8187. + SystemDictionary::classes_do(check_class, thread);
  8188. +#endif
  8189. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8190. - ("methods_parameter_annotations length=%d",
  8191. - methods_parameter_annotations->length()));
  8192. + update_active_methods();
  8193. + RC_TIMER_STOP(_timer_redefinition);
  8194. - for (int i = 0; i < methods_parameter_annotations->length(); i++) {
  8195. - typeArrayHandle method_parameter_annotations(THREAD,
  8196. - (typeArrayOop)methods_parameter_annotations->obj_at(i));
  8197. - if (method_parameter_annotations.is_null()
  8198. - || method_parameter_annotations->length() == 0) {
  8199. - // this method does not have any parameter annotations so skip it
  8200. - continue;
  8201. - }
  8202. +}
  8203. - if (method_parameter_annotations->length() < 1) {
  8204. - // not enough room for a num_parameters field
  8205. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8206. - ("length() is too small for a num_parameters field at %d", i));
  8207. - return false;
  8208. - }
  8209. +void VM_RedefineClasses::update_array_classes_to_newest_version(klassOop smallest_dimension) {
  8210. - int byte_i = 0; // byte index into method_parameter_annotations
  8211. + arrayKlass *curArrayKlass = arrayKlass::cast(smallest_dimension);
  8212. + assert(curArrayKlass->lower_dimension() == NULL, "argument must be smallest dimension");
  8213. - u1 num_parameters = method_parameter_annotations->byte_at(byte_i);
  8214. - byte_i++;
  8215. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8216. - ("num_parameters=%d", num_parameters));
  8217. + while (curArrayKlass != NULL) {
  8218. + klassOop higher_dimension = curArrayKlass->higher_dimension();
  8219. + klassOop lower_dimension = curArrayKlass->lower_dimension();
  8220. + curArrayKlass->update_supers_to_newest_version();
  8221. - int calc_num_parameters = 0;
  8222. - for (; calc_num_parameters < num_parameters; calc_num_parameters++) {
  8223. - if (!rewrite_cp_refs_in_annotations_typeArray(
  8224. - method_parameter_annotations, byte_i, THREAD)) {
  8225. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8226. - ("bad method_parameter_annotations at %d", calc_num_parameters));
  8227. - // propagate failure back to caller
  8228. - return false;
  8229. - }
  8230. + curArrayKlass = NULL;
  8231. + if (higher_dimension != NULL) {
  8232. + curArrayKlass = arrayKlass::cast(higher_dimension);
  8233. }
  8234. - assert(num_parameters == calc_num_parameters, "sanity check");
  8235. }
  8236. - return true;
  8237. -} // end rewrite_cp_refs_in_methods_parameter_annotations()
  8238. +}
  8239. +void VM_RedefineClasses::doit_epilogue() {
  8240. -// Rewrite constant pool references in a methods_default_annotations
  8241. -// field. This "structure" is adapted from the AnnotationDefault_attribute
  8242. -// that is described in section 4.8.19 of the 2nd-edition of the VM spec:
  8243. -//
  8244. -// methods_default_annotations_typeArray {
  8245. -// element_value default_value;
  8246. -// }
  8247. -//
  8248. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_default_annotations(
  8249. - instanceKlassHandle scratch_class, TRAPS) {
  8250. + RC_TIMER_START(_timer_vm_op_epilogue);
  8251. - objArrayHandle methods_default_annotations(THREAD,
  8252. - scratch_class->methods_default_annotations());
  8253. + unlock_threads();
  8254. - if (methods_default_annotations.is_null()
  8255. - || methods_default_annotations->length() == 0) {
  8256. - // no methods_default_annotations so nothing to do
  8257. - return true;
  8258. - }
  8259. + ResourceMark mark;
  8260. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8261. - ("methods_default_annotations length=%d",
  8262. - methods_default_annotations->length()));
  8263. + VM_GC_Operation::doit_epilogue();
  8264. + RC_TRACE(0x00000001, ("GC Operation epilogue finished! "));
  8265. - for (int i = 0; i < methods_default_annotations->length(); i++) {
  8266. - typeArrayHandle method_default_annotations(THREAD,
  8267. - (typeArrayOop)methods_default_annotations->obj_at(i));
  8268. - if (method_default_annotations.is_null()
  8269. - || method_default_annotations->length() == 0) {
  8270. - // this method does not have any default annotations so skip it
  8271. - continue;
  8272. + GrowableArray<methodHandle> instanceTransformerMethods;
  8273. +
  8274. + // Call static transformers
  8275. + for (int i=0; i<_new_classes->length(); i++) {
  8276. +
  8277. + instanceKlassHandle klass = _new_classes->at(i);
  8278. +
  8279. + // Transfer init state
  8280. + if (klass->old_version() != NULL) {
  8281. + instanceKlass::ClassState state = instanceKlass::cast(klass->old_version())->init_state();
  8282. + if (state > instanceKlass::linked) {
  8283. + klass->initialize(Thread::current());
  8284. + }
  8285. }
  8286. +
  8287. + // Find instance transformer method
  8288. - int byte_i = 0; // byte index into method_default_annotations
  8289. + if (klass->check_redefinition_flag(Klass::HasInstanceTransformer)) {
  8290. - if (!rewrite_cp_refs_in_element_value(
  8291. - method_default_annotations, byte_i, THREAD)) {
  8292. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8293. - ("bad default element_value at %d", i));
  8294. - // propagate failure back to caller
  8295. - return false;
  8296. + RC_TRACE(0x00008000, ("Call instance transformer of %s instance", klass->name()->as_C_string()));
  8297. + klassOop cur_klass = klass();
  8298. + while (cur_klass != NULL) {
  8299. + methodOop method = ((instanceKlass*)cur_klass->klass_part())->find_method(vmSymbols::transformer_name(), vmSymbols::void_method_signature());
  8300. + if (method != NULL) {
  8301. + methodHandle instanceTransformerMethod(method);
  8302. + instanceTransformerMethods.append(instanceTransformerMethod);
  8303. + break;
  8304. + } else {
  8305. + cur_klass = cur_klass->klass_part()->super();
  8306. + }
  8307. + }
  8308. + assert(cur_klass != NULL, "must have instance transformer method");
  8309. + } else {
  8310. + instanceTransformerMethods.append(methodHandle(Thread::current(), NULL));
  8311. }
  8312. }
  8313. - return true;
  8314. -} // end rewrite_cp_refs_in_methods_default_annotations()
  8315. + // Call instance transformers
  8316. + if (_updated_oops != NULL) {
  8317. -// Rewrite constant pool references in the method's stackmap table.
  8318. -// These "structures" are adapted from the StackMapTable_attribute that
  8319. -// is described in section 4.8.4 of the 6.0 version of the VM spec
  8320. -// (dated 2005.10.26):
  8321. -// file:///net/quincunx.sfbay/export/gbracha/ClassFile-Java6.pdf
  8322. -//
  8323. -// stack_map {
  8324. -// u2 number_of_entries;
  8325. -// stack_map_frame entries[number_of_entries];
  8326. -// }
  8327. -//
  8328. -void VM_RedefineClasses::rewrite_cp_refs_in_stack_map_table(
  8329. - methodHandle method, TRAPS) {
  8330. -
  8331. - if (!method->has_stackmap_table()) {
  8332. - return;
  8333. - }
  8334. -
  8335. - typeArrayOop stackmap_data = method->stackmap_data();
  8336. - address stackmap_p = (address)stackmap_data->byte_at_addr(0);
  8337. - address stackmap_end = stackmap_p + stackmap_data->length();
  8338. -
  8339. - assert(stackmap_p + 2 <= stackmap_end, "no room for number_of_entries");
  8340. - u2 number_of_entries = Bytes::get_Java_u2(stackmap_p);
  8341. - stackmap_p += 2;
  8342. -
  8343. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  8344. - ("number_of_entries=%u", number_of_entries));
  8345. -
  8346. - // walk through each stack_map_frame
  8347. - u2 calc_number_of_entries = 0;
  8348. - for (; calc_number_of_entries < number_of_entries; calc_number_of_entries++) {
  8349. - // The stack_map_frame structure is a u1 frame_type followed by
  8350. - // 0 or more bytes of data:
  8351. - //
  8352. - // union stack_map_frame {
  8353. - // same_frame;
  8354. - // same_locals_1_stack_item_frame;
  8355. - // same_locals_1_stack_item_frame_extended;
  8356. - // chop_frame;
  8357. - // same_frame_extended;
  8358. - // append_frame;
  8359. - // full_frame;
  8360. - // }
  8361. -
  8362. - assert(stackmap_p + 1 <= stackmap_end, "no room for frame_type");
  8363. - // The Linux compiler does not like frame_type to be u1 or u2. It
  8364. - // issues the following warning for the first if-statement below:
  8365. - //
  8366. - // "warning: comparison is always true due to limited range of data type"
  8367. - //
  8368. - u4 frame_type = *stackmap_p;
  8369. - stackmap_p++;
  8370. -
  8371. - // same_frame {
  8372. - // u1 frame_type = SAME; /* 0-63 */
  8373. - // }
  8374. - if (frame_type >= 0 && frame_type <= 63) {
  8375. - // nothing more to do for same_frame
  8376. - }
  8377. -
  8378. - // same_locals_1_stack_item_frame {
  8379. - // u1 frame_type = SAME_LOCALS_1_STACK_ITEM; /* 64-127 */
  8380. - // verification_type_info stack[1];
  8381. - // }
  8382. - else if (frame_type >= 64 && frame_type <= 127) {
  8383. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8384. - calc_number_of_entries, frame_type, THREAD);
  8385. - }
  8386. -
  8387. - // reserved for future use
  8388. - else if (frame_type >= 128 && frame_type <= 246) {
  8389. - // nothing more to do for reserved frame_types
  8390. - }
  8391. -
  8392. - // same_locals_1_stack_item_frame_extended {
  8393. - // u1 frame_type = SAME_LOCALS_1_STACK_ITEM_EXTENDED; /* 247 */
  8394. - // u2 offset_delta;
  8395. - // verification_type_info stack[1];
  8396. - // }
  8397. - else if (frame_type == 247) {
  8398. - stackmap_p += 2;
  8399. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8400. - calc_number_of_entries, frame_type, THREAD);
  8401. - }
  8402. -
  8403. - // chop_frame {
  8404. - // u1 frame_type = CHOP; /* 248-250 */
  8405. - // u2 offset_delta;
  8406. - // }
  8407. - else if (frame_type >= 248 && frame_type <= 250) {
  8408. - stackmap_p += 2;
  8409. - }
  8410. -
  8411. - // same_frame_extended {
  8412. - // u1 frame_type = SAME_FRAME_EXTENDED; /* 251*/
  8413. - // u2 offset_delta;
  8414. - // }
  8415. - else if (frame_type == 251) {
  8416. - stackmap_p += 2;
  8417. - }
  8418. -
  8419. - // append_frame {
  8420. - // u1 frame_type = APPEND; /* 252-254 */
  8421. - // u2 offset_delta;
  8422. - // verification_type_info locals[frame_type - 251];
  8423. - // }
  8424. - else if (frame_type >= 252 && frame_type <= 254) {
  8425. - assert(stackmap_p + 2 <= stackmap_end,
  8426. - "no room for offset_delta");
  8427. - stackmap_p += 2;
  8428. - u1 len = frame_type - 251;
  8429. - for (u1 i = 0; i < len; i++) {
  8430. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8431. - calc_number_of_entries, frame_type, THREAD);
  8432. - }
  8433. - }
  8434. -
  8435. - // full_frame {
  8436. - // u1 frame_type = FULL_FRAME; /* 255 */
  8437. - // u2 offset_delta;
  8438. - // u2 number_of_locals;
  8439. - // verification_type_info locals[number_of_locals];
  8440. - // u2 number_of_stack_items;
  8441. - // verification_type_info stack[number_of_stack_items];
  8442. - // }
  8443. - else if (frame_type == 255) {
  8444. - assert(stackmap_p + 2 + 2 <= stackmap_end,
  8445. - "no room for smallest full_frame");
  8446. - stackmap_p += 2;
  8447. -
  8448. - u2 number_of_locals = Bytes::get_Java_u2(stackmap_p);
  8449. - stackmap_p += 2;
  8450. -
  8451. - for (u2 locals_i = 0; locals_i < number_of_locals; locals_i++) {
  8452. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8453. - calc_number_of_entries, frame_type, THREAD);
  8454. - }
  8455. -
  8456. - // Use the largest size for the number_of_stack_items, but only get
  8457. - // the right number of bytes.
  8458. - u2 number_of_stack_items = Bytes::get_Java_u2(stackmap_p);
  8459. - stackmap_p += 2;
  8460. -
  8461. - for (u2 stack_i = 0; stack_i < number_of_stack_items; stack_i++) {
  8462. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8463. - calc_number_of_entries, frame_type, THREAD);
  8464. - }
  8465. - }
  8466. - } // end while there is a stack_map_frame
  8467. - assert(number_of_entries == calc_number_of_entries, "sanity check");
  8468. -} // end rewrite_cp_refs_in_stack_map_table()
  8469. -
  8470. -
  8471. -// Rewrite constant pool references in the verification type info
  8472. -// portion of the method's stackmap table. These "structures" are
  8473. -// adapted from the StackMapTable_attribute that is described in
  8474. -// section 4.8.4 of the 6.0 version of the VM spec (dated 2005.10.26):
  8475. -// file:///net/quincunx.sfbay/export/gbracha/ClassFile-Java6.pdf
  8476. -//
  8477. -// The verification_type_info structure is a u1 tag followed by 0 or
  8478. -// more bytes of data:
  8479. -//
  8480. -// union verification_type_info {
  8481. -// Top_variable_info;
  8482. -// Integer_variable_info;
  8483. -// Float_variable_info;
  8484. -// Long_variable_info;
  8485. -// Double_variable_info;
  8486. -// Null_variable_info;
  8487. -// UninitializedThis_variable_info;
  8488. -// Object_variable_info;
  8489. -// Uninitialized_variable_info;
  8490. -// }
  8491. -//
  8492. -void VM_RedefineClasses::rewrite_cp_refs_in_verification_type_info(
  8493. - address& stackmap_p_ref, address stackmap_end, u2 frame_i,
  8494. - u1 frame_type, TRAPS) {
  8495. -
  8496. - assert(stackmap_p_ref + 1 <= stackmap_end, "no room for tag");
  8497. - u1 tag = *stackmap_p_ref;
  8498. - stackmap_p_ref++;
  8499. -
  8500. - switch (tag) {
  8501. - // Top_variable_info {
  8502. - // u1 tag = ITEM_Top; /* 0 */
  8503. - // }
  8504. - // verificationType.hpp has zero as ITEM_Bogus instead of ITEM_Top
  8505. - case 0: // fall through
  8506. -
  8507. - // Integer_variable_info {
  8508. - // u1 tag = ITEM_Integer; /* 1 */
  8509. - // }
  8510. - case ITEM_Integer: // fall through
  8511. -
  8512. - // Float_variable_info {
  8513. - // u1 tag = ITEM_Float; /* 2 */
  8514. - // }
  8515. - case ITEM_Float: // fall through
  8516. -
  8517. - // Double_variable_info {
  8518. - // u1 tag = ITEM_Double; /* 3 */
  8519. - // }
  8520. - case ITEM_Double: // fall through
  8521. -
  8522. - // Long_variable_info {
  8523. - // u1 tag = ITEM_Long; /* 4 */
  8524. - // }
  8525. - case ITEM_Long: // fall through
  8526. -
  8527. - // Null_variable_info {
  8528. - // u1 tag = ITEM_Null; /* 5 */
  8529. - // }
  8530. - case ITEM_Null: // fall through
  8531. -
  8532. - // UninitializedThis_variable_info {
  8533. - // u1 tag = ITEM_UninitializedThis; /* 6 */
  8534. - // }
  8535. - case ITEM_UninitializedThis:
  8536. - // nothing more to do for the above tag types
  8537. - break;
  8538. + for (int i=0; i<_updated_oops->length(); i++) {
  8539. + assert(_updated_oops->at(i) != NULL, "must not be null!");
  8540. + Handle cur(_updated_oops->at(i));
  8541. + instanceKlassHandle klass(cur->klass());
  8542. - // Object_variable_info {
  8543. - // u1 tag = ITEM_Object; /* 7 */
  8544. - // u2 cpool_index;
  8545. - // }
  8546. - case ITEM_Object:
  8547. - {
  8548. - assert(stackmap_p_ref + 2 <= stackmap_end, "no room for cpool_index");
  8549. - u2 cpool_index = Bytes::get_Java_u2(stackmap_p_ref);
  8550. - u2 new_cp_index = find_new_index(cpool_index);
  8551. - if (new_cp_index != 0) {
  8552. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  8553. - ("mapped old cpool_index=%d", cpool_index));
  8554. - Bytes::put_Java_u2(stackmap_p_ref, new_cp_index);
  8555. - cpool_index = new_cp_index;
  8556. - }
  8557. - stackmap_p_ref += 2;
  8558. -
  8559. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  8560. - ("frame_i=%u, frame_type=%u, cpool_index=%d", frame_i,
  8561. - frame_type, cpool_index));
  8562. - } break;
  8563. -
  8564. - // Uninitialized_variable_info {
  8565. - // u1 tag = ITEM_Uninitialized; /* 8 */
  8566. - // u2 offset;
  8567. - // }
  8568. - case ITEM_Uninitialized:
  8569. - assert(stackmap_p_ref + 2 <= stackmap_end, "no room for offset");
  8570. - stackmap_p_ref += 2;
  8571. - break;
  8572. + if (klass->check_redefinition_flag(Klass::HasInstanceTransformer)) {
  8573. - default:
  8574. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  8575. - ("frame_i=%u, frame_type=%u, bad tag=0x%x", frame_i, frame_type, tag));
  8576. - ShouldNotReachHere();
  8577. - break;
  8578. - } // end switch (tag)
  8579. -} // end rewrite_cp_refs_in_verification_type_info()
  8580. -
  8581. -
  8582. -// Change the constant pool associated with klass scratch_class to
  8583. -// scratch_cp. If shrink is true, then scratch_cp_length elements
  8584. -// are copied from scratch_cp to a smaller constant pool and the
  8585. -// smaller constant pool is associated with scratch_class.
  8586. -void VM_RedefineClasses::set_new_constant_pool(
  8587. - instanceKlassHandle scratch_class, constantPoolHandle scratch_cp,
  8588. - int scratch_cp_length, TRAPS) {
  8589. - assert(scratch_cp->length() >= scratch_cp_length, "sanity check");
  8590. -
  8591. - // scratch_cp is a merged constant pool and has enough space for a
  8592. - // worst case merge situation. We want to associate the minimum
  8593. - // sized constant pool with the klass to save space.
  8594. - constantPoolHandle smaller_cp(THREAD,
  8595. - oopFactory::new_constantPool(scratch_cp_length,
  8596. - oopDesc::IsUnsafeConc,
  8597. - THREAD));
  8598. - // preserve orig_length() value in the smaller copy
  8599. - int orig_length = scratch_cp->orig_length();
  8600. - assert(orig_length != 0, "sanity check");
  8601. - smaller_cp->set_orig_length(orig_length);
  8602. -
  8603. - // attach klass to new constant pool
  8604. - // reference to the cp holder is needed for copy_operands()
  8605. - smaller_cp->set_pool_holder(scratch_class());
  8606. -
  8607. - scratch_cp->copy_cp_to(1, scratch_cp_length - 1, smaller_cp, 1, THREAD);
  8608. - scratch_cp = smaller_cp;
  8609. - smaller_cp()->set_is_conc_safe(true);
  8610. -
  8611. - // attach new constant pool to klass
  8612. - scratch_class->set_constants(scratch_cp());
  8613. -
  8614. - int i; // for portability
  8615. -
  8616. - // update each field in klass to use new constant pool indices as needed
  8617. - for (JavaFieldStream fs(scratch_class); !fs.done(); fs.next()) {
  8618. - jshort cur_index = fs.name_index();
  8619. - jshort new_index = find_new_index(cur_index);
  8620. - if (new_index != 0) {
  8621. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8622. - ("field-name_index change: %d to %d", cur_index, new_index));
  8623. - fs.set_name_index(new_index);
  8624. - }
  8625. - cur_index = fs.signature_index();
  8626. - new_index = find_new_index(cur_index);
  8627. - if (new_index != 0) {
  8628. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8629. - ("field-signature_index change: %d to %d", cur_index, new_index));
  8630. - fs.set_signature_index(new_index);
  8631. - }
  8632. - cur_index = fs.initval_index();
  8633. - new_index = find_new_index(cur_index);
  8634. - if (new_index != 0) {
  8635. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8636. - ("field-initval_index change: %d to %d", cur_index, new_index));
  8637. - fs.set_initval_index(new_index);
  8638. - }
  8639. - cur_index = fs.generic_signature_index();
  8640. - new_index = find_new_index(cur_index);
  8641. - if (new_index != 0) {
  8642. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8643. - ("field-generic_signature change: %d to %d", cur_index, new_index));
  8644. - fs.set_generic_signature_index(new_index);
  8645. - }
  8646. - } // end for each field
  8647. -
  8648. - // Update constant pool indices in the inner classes info to use
  8649. - // new constant indices as needed. The inner classes info is a
  8650. - // quadruple:
  8651. - // (inner_class_info, outer_class_info, inner_name, inner_access_flags)
  8652. - InnerClassesIterator iter(scratch_class);
  8653. - for (; !iter.done(); iter.next()) {
  8654. - int cur_index = iter.inner_class_info_index();
  8655. - if (cur_index == 0) {
  8656. - continue; // JVM spec. allows null inner class refs so skip it
  8657. - }
  8658. - int new_index = find_new_index(cur_index);
  8659. - if (new_index != 0) {
  8660. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8661. - ("inner_class_info change: %d to %d", cur_index, new_index));
  8662. - iter.set_inner_class_info_index(new_index);
  8663. - }
  8664. - cur_index = iter.outer_class_info_index();
  8665. - new_index = find_new_index(cur_index);
  8666. - if (new_index != 0) {
  8667. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8668. - ("outer_class_info change: %d to %d", cur_index, new_index));
  8669. - iter.set_outer_class_info_index(new_index);
  8670. - }
  8671. - cur_index = iter.inner_name_index();
  8672. - new_index = find_new_index(cur_index);
  8673. - if (new_index != 0) {
  8674. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8675. - ("inner_name change: %d to %d", cur_index, new_index));
  8676. - iter.set_inner_name_index(new_index);
  8677. - }
  8678. - } // end for each inner class
  8679. -
  8680. - // Attach each method in klass to the new constant pool and update
  8681. - // to use new constant pool indices as needed:
  8682. - objArrayHandle methods(THREAD, scratch_class->methods());
  8683. - for (i = methods->length() - 1; i >= 0; i--) {
  8684. - methodHandle method(THREAD, (methodOop)methods->obj_at(i));
  8685. - method->set_constants(scratch_cp());
  8686. -
  8687. - int new_index = find_new_index(method->name_index());
  8688. - if (new_index != 0) {
  8689. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8690. - ("method-name_index change: %d to %d", method->name_index(),
  8691. - new_index));
  8692. - method->set_name_index(new_index);
  8693. - }
  8694. - new_index = find_new_index(method->signature_index());
  8695. - if (new_index != 0) {
  8696. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8697. - ("method-signature_index change: %d to %d",
  8698. - method->signature_index(), new_index));
  8699. - method->set_signature_index(new_index);
  8700. - }
  8701. - new_index = find_new_index(method->generic_signature_index());
  8702. - if (new_index != 0) {
  8703. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8704. - ("method-generic_signature_index change: %d to %d",
  8705. - method->generic_signature_index(), new_index));
  8706. - method->set_generic_signature_index(new_index);
  8707. - }
  8708. -
  8709. - // Update constant pool indices in the method's checked exception
  8710. - // table to use new constant indices as needed.
  8711. - int cext_length = method->checked_exceptions_length();
  8712. - if (cext_length > 0) {
  8713. - CheckedExceptionElement * cext_table =
  8714. - method->checked_exceptions_start();
  8715. - for (int j = 0; j < cext_length; j++) {
  8716. - int cur_index = cext_table[j].class_cp_index;
  8717. - int new_index = find_new_index(cur_index);
  8718. - if (new_index != 0) {
  8719. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8720. - ("cext-class_cp_index change: %d to %d", cur_index, new_index));
  8721. - cext_table[j].class_cp_index = (u2)new_index;
  8722. - }
  8723. - } // end for each checked exception table entry
  8724. - } // end if there are checked exception table entries
  8725. -
  8726. - // Update each catch type index in the method's exception table
  8727. - // to use new constant pool indices as needed. The exception table
  8728. - // holds quadruple entries of the form:
  8729. - // (beg_bci, end_bci, handler_bci, klass_index)
  8730. -
  8731. - ExceptionTable ex_table(method());
  8732. - int ext_length = ex_table.length();
  8733. -
  8734. - for (int j = 0; j < ext_length; j ++) {
  8735. - int cur_index = ex_table.catch_type_index(j);
  8736. - int new_index = find_new_index(cur_index);
  8737. - if (new_index != 0) {
  8738. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8739. - ("ext-klass_index change: %d to %d", cur_index, new_index));
  8740. - ex_table.set_catch_type_index(j, new_index);
  8741. - }
  8742. - } // end for each exception table entry
  8743. -
  8744. - // Update constant pool indices in the method's local variable
  8745. - // table to use new constant indices as needed. The local variable
  8746. - // table hold sextuple entries of the form:
  8747. - // (start_pc, length, name_index, descriptor_index, signature_index, slot)
  8748. - int lvt_length = method->localvariable_table_length();
  8749. - if (lvt_length > 0) {
  8750. - LocalVariableTableElement * lv_table =
  8751. - method->localvariable_table_start();
  8752. - for (int j = 0; j < lvt_length; j++) {
  8753. - int cur_index = lv_table[j].name_cp_index;
  8754. - int new_index = find_new_index(cur_index);
  8755. - if (new_index != 0) {
  8756. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8757. - ("lvt-name_cp_index change: %d to %d", cur_index, new_index));
  8758. - lv_table[j].name_cp_index = (u2)new_index;
  8759. - }
  8760. - cur_index = lv_table[j].descriptor_cp_index;
  8761. - new_index = find_new_index(cur_index);
  8762. - if (new_index != 0) {
  8763. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8764. - ("lvt-descriptor_cp_index change: %d to %d", cur_index,
  8765. - new_index));
  8766. - lv_table[j].descriptor_cp_index = (u2)new_index;
  8767. - }
  8768. - cur_index = lv_table[j].signature_cp_index;
  8769. - new_index = find_new_index(cur_index);
  8770. - if (new_index != 0) {
  8771. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8772. - ("lvt-signature_cp_index change: %d to %d", cur_index, new_index));
  8773. - lv_table[j].signature_cp_index = (u2)new_index;
  8774. - }
  8775. - } // end for each local variable table entry
  8776. - } // end if there are local variable table entries
  8777. + methodHandle method = instanceTransformerMethods.at(klass->redefinition_index());
  8778. - rewrite_cp_refs_in_stack_map_table(method, THREAD);
  8779. - } // end for each method
  8780. - assert(scratch_cp()->is_conc_safe(), "Just checking");
  8781. -} // end set_new_constant_pool()
  8782. + RC_TRACE(0x00008000, ("executing transformer method"));
  8783. +
  8784. + Thread *__the_thread__ = Thread::current();
  8785. + JavaValue result(T_VOID);
  8786. + JavaCallArguments args(cur);
  8787. + JavaCalls::call(&result,
  8788. + method,
  8789. + &args,
  8790. + THREAD);
  8791. + // TODO: What to do with an exception here?
  8792. + if (HAS_PENDING_EXCEPTION) {
  8793. + Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  8794. + RC_TRACE(0x00000002, ("exception when executing transformer: '%s'",
  8795. + ex_name->as_C_string()));
  8796. + CLEAR_PENDING_EXCEPTION;
  8797. + }
  8798. + }
  8799. + }
  8800. -// Unevolving classes may point to methods of the_class directly
  8801. -// from their constant pool caches, itables, and/or vtables. We
  8802. -// use the SystemDictionary::classes_do() facility and this helper
  8803. -// to fix up these pointers.
  8804. -//
  8805. -// Note: We currently don't support updating the vtable in
  8806. -// arrayKlassOops. See Open Issues in jvmtiRedefineClasses.hpp.
  8807. -void VM_RedefineClasses::adjust_cpool_cache_and_vtable(klassOop k_oop,
  8808. - oop initiating_loader, TRAPS) {
  8809. - Klass *k = k_oop->klass_part();
  8810. - if (k->oop_is_instance()) {
  8811. - HandleMark hm(THREAD);
  8812. - instanceKlass *ik = (instanceKlass *) k;
  8813. + delete _updated_oops;
  8814. + _updated_oops = NULL;
  8815. + }
  8816. - // HotSpot specific optimization! HotSpot does not currently
  8817. - // support delegation from the bootstrap class loader to a
  8818. - // user-defined class loader. This means that if the bootstrap
  8819. - // class loader is the initiating class loader, then it will also
  8820. - // be the defining class loader. This also means that classes
  8821. - // loaded by the bootstrap class loader cannot refer to classes
  8822. - // loaded by a user-defined class loader. Note: a user-defined
  8823. - // class loader can delegate to the bootstrap class loader.
  8824. - //
  8825. - // If the current class being redefined has a user-defined class
  8826. - // loader as its defining class loader, then we can skip all
  8827. - // classes loaded by the bootstrap class loader.
  8828. - bool is_user_defined =
  8829. - instanceKlass::cast(_the_class_oop)->class_loader() != NULL;
  8830. - if (is_user_defined && ik->class_loader() == NULL) {
  8831. - return;
  8832. - }
  8833. + // Free the array of scratch classes
  8834. + delete _new_classes;
  8835. + _new_classes = NULL;
  8836. + RC_TRACE(0x00000001, ("Redefinition finished!"));
  8837. - // This is a very busy routine. We don't want too much tracing
  8838. - // printed out.
  8839. - bool trace_name_printed = false;
  8840. -
  8841. - // Very noisy: only enable this call if you are trying to determine
  8842. - // that a specific class gets found by this routine.
  8843. - // RC_TRACE macro has an embedded ResourceMark
  8844. - // RC_TRACE_WITH_THREAD(0x00100000, THREAD,
  8845. - // ("adjust check: name=%s", ik->external_name()));
  8846. - // trace_name_printed = true;
  8847. -
  8848. - // Fix the vtable embedded in the_class and subclasses of the_class,
  8849. - // if one exists. We discard scratch_class and we don't keep an
  8850. - // instanceKlass around to hold obsolete methods so we don't have
  8851. - // any other instanceKlass embedded vtables to update. The vtable
  8852. - // holds the methodOops for virtual (but not final) methods.
  8853. - if (ik->vtable_length() > 0 && ik->is_subtype_of(_the_class_oop)) {
  8854. - // ik->vtable() creates a wrapper object; rm cleans it up
  8855. - ResourceMark rm(THREAD);
  8856. - ik->vtable()->adjust_method_entries(_matching_old_methods,
  8857. - _matching_new_methods,
  8858. - _matching_methods_length,
  8859. - &trace_name_printed);
  8860. - }
  8861. -
  8862. - // If the current class has an itable and we are either redefining an
  8863. - // interface or if the current class is a subclass of the_class, then
  8864. - // we potentially have to fix the itable. If we are redefining an
  8865. - // interface, then we have to call adjust_method_entries() for
  8866. - // every instanceKlass that has an itable since there isn't a
  8867. - // subclass relationship between an interface and an instanceKlass.
  8868. - if (ik->itable_length() > 0 && (Klass::cast(_the_class_oop)->is_interface()
  8869. - || ik->is_subclass_of(_the_class_oop))) {
  8870. - // ik->itable() creates a wrapper object; rm cleans it up
  8871. - ResourceMark rm(THREAD);
  8872. - ik->itable()->adjust_method_entries(_matching_old_methods,
  8873. - _matching_new_methods,
  8874. - _matching_methods_length,
  8875. - &trace_name_printed);
  8876. - }
  8877. -
  8878. - // The constant pools in other classes (other_cp) can refer to
  8879. - // methods in the_class. We have to update method information in
  8880. - // other_cp's cache. If other_cp has a previous version, then we
  8881. - // have to repeat the process for each previous version. The
  8882. - // constant pool cache holds the methodOops for non-virtual
  8883. - // methods and for virtual, final methods.
  8884. - //
  8885. - // Special case: if the current class is the_class, then new_cp
  8886. - // has already been attached to the_class and old_cp has already
  8887. - // been added as a previous version. The new_cp doesn't have any
  8888. - // cached references to old methods so it doesn't need to be
  8889. - // updated. We can simply start with the previous version(s) in
  8890. - // that case.
  8891. - constantPoolHandle other_cp;
  8892. - constantPoolCacheOop cp_cache;
  8893. -
  8894. - if (k_oop != _the_class_oop) {
  8895. - // this klass' constant pool cache may need adjustment
  8896. - other_cp = constantPoolHandle(ik->constants());
  8897. - cp_cache = other_cp->cache();
  8898. - if (cp_cache != NULL) {
  8899. - cp_cache->adjust_method_entries(_matching_old_methods,
  8900. - _matching_new_methods,
  8901. - _matching_methods_length,
  8902. - &trace_name_printed);
  8903. - }
  8904. - }
  8905. - {
  8906. - ResourceMark rm(THREAD);
  8907. - // PreviousVersionInfo objects returned via PreviousVersionWalker
  8908. - // contain a GrowableArray of handles. We have to clean up the
  8909. - // GrowableArray _after_ the PreviousVersionWalker destructor
  8910. - // has destroyed the handles.
  8911. - {
  8912. - // the previous versions' constant pool caches may need adjustment
  8913. - PreviousVersionWalker pvw(ik);
  8914. - for (PreviousVersionInfo * pv_info = pvw.next_previous_version();
  8915. - pv_info != NULL; pv_info = pvw.next_previous_version()) {
  8916. - other_cp = pv_info->prev_constant_pool_handle();
  8917. - cp_cache = other_cp->cache();
  8918. - if (cp_cache != NULL) {
  8919. - cp_cache->adjust_method_entries(_matching_old_methods,
  8920. - _matching_new_methods,
  8921. - _matching_methods_length,
  8922. - &trace_name_printed);
  8923. - }
  8924. - }
  8925. - } // pvw is cleaned up
  8926. - } // rm is cleaned up
  8927. + RC_TIMER_STOP(_timer_vm_op_epilogue);
  8928. +}
  8929. +
  8930. +bool VM_RedefineClasses::is_modifiable_class(oop klass_mirror) {
  8931. + // classes for primitives cannot be redefined
  8932. + if (java_lang_Class::is_primitive(klass_mirror)) {
  8933. + return false;
  8934. + }
  8935. + klassOop the_class_oop = java_lang_Class::as_klassOop(klass_mirror);
  8936. + // classes for arrays cannot be redefined
  8937. + if (the_class_oop == NULL || !Klass::cast(the_class_oop)->oop_is_instance()) {
  8938. + return false;
  8939. }
  8940. + return true;
  8941. }
  8942. -void VM_RedefineClasses::update_jmethod_ids() {
  8943. - for (int j = 0; j < _matching_methods_length; ++j) {
  8944. - methodOop old_method = _matching_old_methods[j];
  8945. - jmethodID jmid = old_method->find_jmethod_id_or_null();
  8946. - if (jmid != NULL) {
  8947. - // There is a jmethodID, change it to point to the new method
  8948. - methodHandle new_method_h(_matching_new_methods[j]);
  8949. - JNIHandles::change_method_associated_with_jmethod_id(jmid, new_method_h);
  8950. - assert(JNIHandles::resolve_jmethod_id(jmid) == _matching_new_methods[j],
  8951. - "should be replaced");
  8952. - }
  8953. +#ifdef ASSERT
  8954. +
  8955. +void VM_RedefineClasses::verify_classes(klassOop k_oop_latest, oop initiating_loader, TRAPS) {
  8956. + klassOop k_oop = k_oop_latest;
  8957. + while (k_oop != NULL) {
  8958. +
  8959. + instanceKlassHandle k_handle(THREAD, k_oop);
  8960. + Verifier::verify(k_handle, Verifier::ThrowException, true, true, THREAD);
  8961. + k_oop = k_oop->klass_part()->old_version();
  8962. }
  8963. }
  8964. -void VM_RedefineClasses::check_methods_and_mark_as_obsolete(
  8965. - BitMap *emcp_methods, int * emcp_method_count_p) {
  8966. - *emcp_method_count_p = 0;
  8967. - int obsolete_count = 0;
  8968. - int old_index = 0;
  8969. - for (int j = 0; j < _matching_methods_length; ++j, ++old_index) {
  8970. - methodOop old_method = _matching_old_methods[j];
  8971. - methodOop new_method = _matching_new_methods[j];
  8972. - methodOop old_array_method;
  8973. -
  8974. - // Maintain an old_index into the _old_methods array by skipping
  8975. - // deleted methods
  8976. - while ((old_array_method = (methodOop) _old_methods->obj_at(old_index))
  8977. - != old_method) {
  8978. - ++old_index;
  8979. - }
  8980. -
  8981. - if (MethodComparator::methods_EMCP(old_method, new_method)) {
  8982. - // The EMCP definition from JSR-163 requires the bytecodes to be
  8983. - // the same with the exception of constant pool indices which may
  8984. - // differ. However, the constants referred to by those indices
  8985. - // must be the same.
  8986. - //
  8987. - // We use methods_EMCP() for comparison since constant pool
  8988. - // merging can remove duplicate constant pool entries that were
  8989. - // present in the old method and removed from the rewritten new
  8990. - // method. A faster binary comparison function would consider the
  8991. - // old and new methods to be different when they are actually
  8992. - // EMCP.
  8993. - //
  8994. - // The old and new methods are EMCP and you would think that we
  8995. - // could get rid of one of them here and now and save some space.
  8996. - // However, the concept of EMCP only considers the bytecodes and
  8997. - // the constant pool entries in the comparison. Other things,
  8998. - // e.g., the line number table (LNT) or the local variable table
  8999. - // (LVT) don't count in the comparison. So the new (and EMCP)
  9000. - // method can have a new LNT that we need so we can't just
  9001. - // overwrite the new method with the old method.
  9002. - //
  9003. - // When this routine is called, we have already attached the new
  9004. - // methods to the_class so the old methods are effectively
  9005. - // overwritten. However, if an old method is still executing,
  9006. - // then the old method cannot be collected until sometime after
  9007. - // the old method call has returned. So the overwriting of old
  9008. - // methods by new methods will save us space except for those
  9009. - // (hopefully few) old methods that are still executing.
  9010. - //
  9011. - // A method refers to a constMethodOop and this presents another
  9012. - // possible avenue to space savings. The constMethodOop in the
  9013. - // new method contains possibly new attributes (LNT, LVT, etc).
  9014. - // At first glance, it seems possible to save space by replacing
  9015. - // the constMethodOop in the old method with the constMethodOop
  9016. - // from the new method. The old and new methods would share the
  9017. - // same constMethodOop and we would save the space occupied by
  9018. - // the old constMethodOop. However, the constMethodOop contains
  9019. - // a back reference to the containing method. Sharing the
  9020. - // constMethodOop between two methods could lead to confusion in
  9021. - // the code that uses the back reference. This would lead to
  9022. - // brittle code that could be broken in non-obvious ways now or
  9023. - // in the future.
  9024. - //
  9025. - // Another possibility is to copy the constMethodOop from the new
  9026. - // method to the old method and then overwrite the new method with
  9027. - // the old method. Since the constMethodOop contains the bytecodes
  9028. - // for the method embedded in the oop, this option would change
  9029. - // the bytecodes out from under any threads executing the old
  9030. - // method and make the thread's bcp invalid. Since EMCP requires
  9031. - // that the bytecodes be the same modulo constant pool indices, it
  9032. - // is straight forward to compute the correct new bcp in the new
  9033. - // constMethodOop from the old bcp in the old constMethodOop. The
  9034. - // time consuming part would be searching all the frames in all
  9035. - // of the threads to find all of the calls to the old method.
  9036. - //
  9037. - // It looks like we will have to live with the limited savings
  9038. - // that we get from effectively overwriting the old methods
  9039. - // when the new methods are attached to the_class.
  9040. -
  9041. - // track which methods are EMCP for add_previous_version() call
  9042. - emcp_methods->set_bit(old_index);
  9043. - (*emcp_method_count_p)++;
  9044. -
  9045. - // An EMCP method is _not_ obsolete. An obsolete method has a
  9046. - // different jmethodID than the current method. An EMCP method
  9047. - // has the same jmethodID as the current method. Having the
  9048. - // same jmethodID for all EMCP versions of a method allows for
  9049. - // a consistent view of the EMCP methods regardless of which
  9050. - // EMCP method you happen to have in hand. For example, a
  9051. - // breakpoint set in one EMCP method will work for all EMCP
  9052. - // versions of the method including the current one.
  9053. - } else {
  9054. - // mark obsolete methods as such
  9055. - old_method->set_is_obsolete();
  9056. - obsolete_count++;
  9057. +#endif
  9058. - // obsolete methods need a unique idnum
  9059. - u2 num = instanceKlass::cast(_the_class_oop)->next_method_idnum();
  9060. - if (num != constMethodOopDesc::UNSET_IDNUM) {
  9061. -// u2 old_num = old_method->method_idnum();
  9062. - old_method->set_method_idnum(num);
  9063. -// TO DO: attach obsolete annotations to obsolete method's new idnum
  9064. +// Rewrite faster byte-codes back to their slower equivalent. Undoes rewriting happening in templateTable_xxx.cpp
  9065. +// The reason is that once we zero cpool caches, we need to re-resolve all entries again. Faster bytecodes do not
  9066. +// do that, they assume that cache entry is resolved already.
  9067. +static void unpatch_bytecode(methodOop method) {
  9068. + RawBytecodeStream bcs(method);
  9069. + Bytecodes::Code code;
  9070. + Bytecodes::Code java_code;
  9071. + while (!bcs.is_last_bytecode()) {
  9072. + code = bcs.raw_next();
  9073. + address bcp = bcs.bcp();
  9074. +
  9075. + if (code == Bytecodes::_breakpoint) {
  9076. + int bci = method->bci_from(bcp);
  9077. + code = method->orig_bytecode_at(bci);
  9078. + java_code = Bytecodes::java_code(code);
  9079. + if (code != java_code &&
  9080. + (java_code == Bytecodes::_getfield ||
  9081. + java_code == Bytecodes::_putfield ||
  9082. + java_code == Bytecodes::_aload_0)) {
  9083. + // Let breakpoint table handling unpatch bytecode
  9084. + method->set_orig_bytecode_at(bci, java_code);
  9085. }
  9086. - // With tracing we try not to "yack" too much. The position of
  9087. - // this trace assumes there are fewer obsolete methods than
  9088. - // EMCP methods.
  9089. - RC_TRACE(0x00000100, ("mark %s(%s) as obsolete",
  9090. - old_method->name()->as_C_string(),
  9091. - old_method->signature()->as_C_string()));
  9092. + } else {
  9093. + java_code = Bytecodes::java_code(code);
  9094. + if (code != java_code &&
  9095. + (java_code == Bytecodes::_getfield ||
  9096. + java_code == Bytecodes::_putfield ||
  9097. + java_code == Bytecodes::_aload_0)) {
  9098. + *bcp = java_code;
  9099. + }
  9100. + }
  9101. +
  9102. + // Additionally, we need to unpatch bytecode at bcp+1 for fast_xaccess (which would be fast field access)
  9103. + if (code == Bytecodes::_fast_iaccess_0 || code == Bytecodes::_fast_aaccess_0 || code == Bytecodes::_fast_faccess_0) {
  9104. + Bytecodes::Code code2 = Bytecodes::code_or_bp_at(bcp + 1);
  9105. + assert(code2 == Bytecodes::_fast_igetfield ||
  9106. + code2 == Bytecodes::_fast_agetfield ||
  9107. + code2 == Bytecodes::_fast_fgetfield, "");
  9108. + *(bcp + 1) = Bytecodes::java_code(code2);
  9109. }
  9110. - old_method->set_is_old();
  9111. - }
  9112. - for (int i = 0; i < _deleted_methods_length; ++i) {
  9113. - methodOop old_method = _deleted_methods[i];
  9114. -
  9115. - assert(old_method->vtable_index() < 0,
  9116. - "cannot delete methods with vtable entries");;
  9117. -
  9118. - // Mark all deleted methods as old and obsolete
  9119. - old_method->set_is_old();
  9120. - old_method->set_is_obsolete();
  9121. - ++obsolete_count;
  9122. - // With tracing we try not to "yack" too much. The position of
  9123. - // this trace assumes there are fewer obsolete methods than
  9124. - // EMCP methods.
  9125. - RC_TRACE(0x00000100, ("mark deleted %s(%s) as obsolete",
  9126. - old_method->name()->as_C_string(),
  9127. - old_method->signature()->as_C_string()));
  9128. - }
  9129. - assert((*emcp_method_count_p + obsolete_count) == _old_methods->length(),
  9130. - "sanity check");
  9131. - RC_TRACE(0x00000100, ("EMCP_cnt=%d, obsolete_cnt=%d", *emcp_method_count_p,
  9132. - obsolete_count));
  9133. + }
  9134. }
  9135. -// This internal class transfers the native function registration from old methods
  9136. -// to new methods. It is designed to handle both the simple case of unchanged
  9137. -// native methods and the complex cases of native method prefixes being added and/or
  9138. -// removed.
  9139. -// It expects only to be used during the VM_RedefineClasses op (a safepoint).
  9140. -//
  9141. -// This class is used after the new methods have been installed in "the_class".
  9142. -//
  9143. -// So, for example, the following must be handled. Where 'm' is a method and
  9144. -// a number followed by an underscore is a prefix.
  9145. -//
  9146. -// Old Name New Name
  9147. -// Simple transfer to new method m -> m
  9148. -// Add prefix m -> 1_m
  9149. -// Remove prefix 1_m -> m
  9150. -// Simultaneous add of prefixes m -> 3_2_1_m
  9151. -// Simultaneous removal of prefixes 3_2_1_m -> m
  9152. -// Simultaneous add and remove 1_m -> 2_m
  9153. -// Same, caused by prefix removal only 3_2_1_m -> 3_2_m
  9154. +// Unevolving classes may point to old methods directly
  9155. +// from their constant pool caches, itables, and/or vtables. We
  9156. +// use the SystemDictionary::classes_do() facility and this helper
  9157. +// to fix up these pointers. Additional field offsets and vtable indices
  9158. +// in the constant pool cache entries are fixed.
  9159. //
  9160. -class TransferNativeFunctionRegistration {
  9161. - private:
  9162. - instanceKlassHandle the_class;
  9163. - int prefix_count;
  9164. - char** prefixes;
  9165. +// Note: We currently don't support updating the vtable in
  9166. +// arrayKlassOops. See Open Issues in jvmtiRedefineClasses.hpp.
  9167. +void VM_RedefineClasses::adjust_cpool_cache(klassOop k_oop_latest, oop initiating_loader, TRAPS) {
  9168. + klassOop k_oop = k_oop_latest;
  9169. + while (k_oop != NULL) {
  9170. + //tty->print_cr("name=%s", k_oop->klass_part()->name()->as_C_string());
  9171. +/*
  9172. + methodOop *matching_old_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  9173. + methodOop *matching_new_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  9174. - // Recursively search the binary tree of possibly prefixed method names.
  9175. - // Iteration could be used if all agents were well behaved. Full tree walk is
  9176. - // more resilent to agents not cleaning up intermediate methods.
  9177. - // Branch at each depth in the binary tree is:
  9178. - // (1) without the prefix.
  9179. - // (2) with the prefix.
  9180. - // where 'prefix' is the prefix at that 'depth' (first prefix, second prefix,...)
  9181. - methodOop search_prefix_name_space(int depth, char* name_str, size_t name_len,
  9182. - Symbol* signature) {
  9183. - TempNewSymbol name_symbol = SymbolTable::probe(name_str, (int)name_len);
  9184. - if (name_symbol != NULL) {
  9185. - methodOop method = Klass::cast(the_class())->lookup_method(name_symbol, signature);
  9186. - if (method != NULL) {
  9187. - // Even if prefixed, intermediate methods must exist.
  9188. - if (method->is_native()) {
  9189. - // Wahoo, we found a (possibly prefixed) version of the method, return it.
  9190. - return method;
  9191. - }
  9192. - if (depth < prefix_count) {
  9193. - // Try applying further prefixes (other than this one).
  9194. - method = search_prefix_name_space(depth+1, name_str, name_len, signature);
  9195. - if (method != NULL) {
  9196. - return method; // found
  9197. - }
  9198. + for (int i=0; i<_matching_methods_length; i++) {
  9199. + matching_old_methods[i] = (methodOop)_old_methods->obj_at(_matching_old_methods[i]);
  9200. + matching_new_methods[i] = (methodOop)_new_methods->obj_at(_matching_new_methods[i]);
  9201. + }*/
  9202. - // Try adding this prefix to the method name and see if it matches
  9203. - // another method name.
  9204. - char* prefix = prefixes[depth];
  9205. - size_t prefix_len = strlen(prefix);
  9206. - size_t trial_len = name_len + prefix_len;
  9207. - char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1);
  9208. - strcpy(trial_name_str, prefix);
  9209. - strcat(trial_name_str, name_str);
  9210. - method = search_prefix_name_space(depth+1, trial_name_str, trial_len,
  9211. - signature);
  9212. - if (method != NULL) {
  9213. - // If found along this branch, it was prefixed, mark as such
  9214. - method->set_is_prefixed_native();
  9215. - return method; // found
  9216. - }
  9217. - }
  9218. - }
  9219. - }
  9220. - return NULL; // This whole branch bore nothing
  9221. - }
  9222. + Klass *k = k_oop->klass_part();
  9223. + if (k->oop_is_instance()) {
  9224. + HandleMark hm(THREAD);
  9225. + instanceKlass *ik = (instanceKlass *) k;
  9226. - // Return the method name with old prefixes stripped away.
  9227. - char* method_name_without_prefixes(methodOop method) {
  9228. - Symbol* name = method->name();
  9229. - char* name_str = name->as_utf8();
  9230. + constantPoolHandle other_cp;
  9231. + constantPoolCacheOop cp_cache;
  9232. - // Old prefixing may be defunct, strip prefixes, if any.
  9233. - for (int i = prefix_count-1; i >= 0; i--) {
  9234. - char* prefix = prefixes[i];
  9235. - size_t prefix_len = strlen(prefix);
  9236. - if (strncmp(prefix, name_str, prefix_len) == 0) {
  9237. - name_str += prefix_len;
  9238. - }
  9239. - }
  9240. - return name_str;
  9241. - }
  9242. + other_cp = constantPoolHandle(ik->constants());
  9243. - // Strip any prefixes off the old native method, then try to find a
  9244. - // (possibly prefixed) new native that matches it.
  9245. - methodOop strip_and_search_for_new_native(methodOop method) {
  9246. - ResourceMark rm;
  9247. - char* name_str = method_name_without_prefixes(method);
  9248. - return search_prefix_name_space(0, name_str, strlen(name_str),
  9249. - method->signature());
  9250. - }
  9251. + for (int i=0; i<other_cp->length(); i++) {
  9252. + if (other_cp->tag_at(i).is_klass()) {
  9253. + klassOop klass = other_cp->klass_at(i, THREAD);
  9254. + if (klass->klass_part()->new_version() != NULL) {
  9255. - public:
  9256. + // (tw) TODO: check why/if this is necessary
  9257. + other_cp->klass_at_put(i, klass->klass_part()->new_version());
  9258. + }
  9259. + klass = other_cp->klass_at(i, THREAD);
  9260. + assert(klass->klass_part()->new_version() == NULL, "Must be new klass!");
  9261. + }
  9262. + }
  9263. - // Construct a native method transfer processor for this class.
  9264. - TransferNativeFunctionRegistration(instanceKlassHandle _the_class) {
  9265. - assert(SafepointSynchronize::is_at_safepoint(), "sanity check");
  9266. + cp_cache = other_cp->cache();
  9267. - the_class = _the_class;
  9268. - prefixes = JvmtiExport::get_all_native_method_prefixes(&prefix_count);
  9269. + if (cp_cache != NULL) {
  9270. + cp_cache->adjust_entries(NULL,
  9271. + NULL,
  9272. + 0);
  9273. + }
  9274. +
  9275. + // If bytecode rewriting is enabled, we also need to unpatch bytecode to force resolution of zeroied entries
  9276. + if (RewriteBytecodes) {
  9277. + ik->methods_do(unpatch_bytecode);
  9278. + }
  9279. + }
  9280. + k_oop = k_oop->klass_part()->old_version();
  9281. }
  9282. +}
  9283. - // Attempt to transfer any of the old or deleted methods that are native
  9284. - void transfer_registrations(methodOop* old_methods, int methods_length) {
  9285. - for (int j = 0; j < methods_length; j++) {
  9286. - methodOop old_method = old_methods[j];
  9287. +void VM_RedefineClasses::update_jmethod_ids() {
  9288. + for (int j = 0; j < _matching_methods_length; ++j) {
  9289. + methodOop old_method = (methodOop)_old_methods->obj_at(_matching_old_methods[j]);
  9290. + RC_TRACE(0x00008000, ("matching method %s", old_method->name_and_sig_as_C_string()));
  9291. +
  9292. + jmethodID jmid = old_method->find_jmethod_id_or_null();
  9293. + if (old_method->new_version() != NULL && jmid == NULL) {
  9294. + // (tw) Have to create jmethodID in this case
  9295. + jmid = old_method->jmethod_id();
  9296. + }
  9297. +
  9298. + if (jmid != NULL) {
  9299. + // There is a jmethodID, change it to point to the new method
  9300. + methodHandle new_method_h((methodOop)_new_methods->obj_at(_matching_new_methods[j]));
  9301. + if (old_method->new_version() == NULL) {
  9302. + methodHandle old_method_h((methodOop)_old_methods->obj_at(_matching_old_methods[j]));
  9303. + jmethodID new_jmethod_id = JNIHandles::make_jmethod_id(old_method_h);
  9304. + bool result = instanceKlass::cast(old_method_h->method_holder())->update_jmethod_id(old_method_h(), new_jmethod_id);
  9305. + //RC_TRACE(0x00008000, ("Changed jmethodID for old method assigned to %d / result=%d", new_jmethod_id, result);
  9306. + //RC_TRACE(0x00008000, ("jmethodID new method: %d jmethodID old method: %d", new_method_h->jmethod_id(), old_method->jmethod_id());
  9307. + } else {
  9308. + jmethodID mid = new_method_h->jmethod_id();
  9309. + bool result = instanceKlass::cast(new_method_h->method_holder())->update_jmethod_id(new_method_h(), jmid);
  9310. + //RC_TRACE(0x00008000, ("Changed jmethodID for new method assigned to %d / result=%d", jmid, result);
  9311. - if (old_method->is_native() && old_method->has_native_function()) {
  9312. - methodOop new_method = strip_and_search_for_new_native(old_method);
  9313. - if (new_method != NULL) {
  9314. - // Actually set the native function in the new method.
  9315. - // Redefine does not send events (except CFLH), certainly not this
  9316. - // behind the scenes re-registration.
  9317. - new_method->set_native_function(old_method->native_function(),
  9318. - !methodOopDesc::native_bind_event_is_interesting);
  9319. - }
  9320. }
  9321. + JNIHandles::change_method_associated_with_jmethod_id(jmid, new_method_h);
  9322. + //RC_TRACE(0x00008000, ("changing method associated with jmethod id %d to %s", (int)jmid, new_method_h->name()->as_C_string());
  9323. + assert(JNIHandles::resolve_jmethod_id(jmid) == (methodOop)_new_methods->obj_at(_matching_new_methods[j]), "should be replaced");
  9324. + jmethodID mid = ((methodOop)_new_methods->obj_at(_matching_new_methods[j]))->jmethod_id();
  9325. + assert(JNIHandles::resolve_non_null((jobject)mid) == new_method_h(), "must match!");
  9326. +
  9327. + //RC_TRACE(0x00008000, ("jmethodID new method: %d jmethodID old method: %d", new_method_h->jmethod_id(), old_method->jmethod_id());
  9328. }
  9329. }
  9330. -};
  9331. -
  9332. -// Don't lose the association between a native method and its JNI function.
  9333. -void VM_RedefineClasses::transfer_old_native_function_registrations(instanceKlassHandle the_class) {
  9334. - TransferNativeFunctionRegistration transfer(the_class);
  9335. - transfer.transfer_registrations(_deleted_methods, _deleted_methods_length);
  9336. - transfer.transfer_registrations(_matching_old_methods, _matching_methods_length);
  9337. }
  9338. +
  9339. // Deoptimize all compiled code that depends on this class.
  9340. //
  9341. // If the can_redefine_classes capability is obtained in the onload
  9342. @@ -3101,7 +2677,10 @@ void VM_RedefineClasses::flush_dependent_code(instanceKlassHandle k_h, TRAPS) {
  9343. // All dependencies have been recorded from startup or this is a second or
  9344. // subsequent use of RedefineClasses
  9345. - if (JvmtiExport::all_dependencies_are_recorded()) {
  9346. +
  9347. + // For now deopt all
  9348. + // (tw) TODO: Improve the dependency system such that we can safely deopt only a subset of the methods
  9349. + if (0 && JvmtiExport::all_dependencies_are_recorded()) {
  9350. Universe::flush_evol_dependents_on(k_h);
  9351. } else {
  9352. CodeCache::mark_all_nmethods_for_deoptimization();
  9353. @@ -3124,10 +2703,10 @@ void VM_RedefineClasses::compute_added_deleted_matching_methods() {
  9354. methodOop old_method;
  9355. methodOop new_method;
  9356. - _matching_old_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  9357. - _matching_new_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  9358. - _added_methods = NEW_RESOURCE_ARRAY(methodOop, _new_methods->length());
  9359. - _deleted_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  9360. + _matching_old_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  9361. + _matching_new_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  9362. + _added_methods = NEW_RESOURCE_ARRAY(int, _new_methods->length());
  9363. + _deleted_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  9364. _matching_methods_length = 0;
  9365. _deleted_methods_length = 0;
  9366. @@ -3142,36 +2721,36 @@ void VM_RedefineClasses::compute_added_deleted_matching_methods() {
  9367. }
  9368. // New method at the end
  9369. new_method = (methodOop) _new_methods->obj_at(nj);
  9370. - _added_methods[_added_methods_length++] = new_method;
  9371. + _added_methods[_added_methods_length++] = nj;
  9372. ++nj;
  9373. } else if (nj >= _new_methods->length()) {
  9374. // Old method, at the end, is deleted
  9375. old_method = (methodOop) _old_methods->obj_at(oj);
  9376. - _deleted_methods[_deleted_methods_length++] = old_method;
  9377. + _deleted_methods[_deleted_methods_length++] = oj;
  9378. ++oj;
  9379. } else {
  9380. old_method = (methodOop) _old_methods->obj_at(oj);
  9381. new_method = (methodOop) _new_methods->obj_at(nj);
  9382. if (old_method->name() == new_method->name()) {
  9383. if (old_method->signature() == new_method->signature()) {
  9384. - _matching_old_methods[_matching_methods_length ] = old_method;
  9385. - _matching_new_methods[_matching_methods_length++] = new_method;
  9386. + _matching_old_methods[_matching_methods_length ] = oj;//old_method;
  9387. + _matching_new_methods[_matching_methods_length++] = nj;//new_method;
  9388. ++nj;
  9389. ++oj;
  9390. } else {
  9391. // added overloaded have already been moved to the end,
  9392. // so this is a deleted overloaded method
  9393. - _deleted_methods[_deleted_methods_length++] = old_method;
  9394. + _deleted_methods[_deleted_methods_length++] = oj;//old_method;
  9395. ++oj;
  9396. }
  9397. } else { // names don't match
  9398. if (old_method->name()->fast_compare(new_method->name()) > 0) {
  9399. // new method
  9400. - _added_methods[_added_methods_length++] = new_method;
  9401. + _added_methods[_added_methods_length++] = nj;//new_method;
  9402. ++nj;
  9403. } else {
  9404. // deleted method
  9405. - _deleted_methods[_deleted_methods_length++] = old_method;
  9406. + _deleted_methods[_deleted_methods_length++] = oj;//old_method;
  9407. ++oj;
  9408. }
  9409. }
  9410. @@ -3179,6 +2758,8 @@ void VM_RedefineClasses::compute_added_deleted_matching_methods() {
  9411. }
  9412. assert(_matching_methods_length + _deleted_methods_length == _old_methods->length(), "sanity");
  9413. assert(_matching_methods_length + _added_methods_length == _new_methods->length(), "sanity");
  9414. + RC_TRACE(0x00008000, ("Matching methods = %d / deleted methods = %d / added methods = %d",
  9415. + _matching_methods_length, _deleted_methods_length, _added_methods_length));
  9416. }
  9417. @@ -3186,297 +2767,184 @@ void VM_RedefineClasses::compute_added_deleted_matching_methods() {
  9418. // Install the redefinition of a class:
  9419. // - house keeping (flushing breakpoints and caches, deoptimizing
  9420. // dependent compiled code)
  9421. -// - replacing parts in the_class with parts from scratch_class
  9422. -// - adding a weak reference to track the obsolete but interesting
  9423. -// parts of the_class
  9424. // - adjusting constant pool caches and vtables in other classes
  9425. -// that refer to methods in the_class. These adjustments use the
  9426. -// SystemDictionary::classes_do() facility which only allows
  9427. -// a helper method to be specified. The interesting parameters
  9428. -// that we would like to pass to the helper method are saved in
  9429. -// static global fields in the VM operation.
  9430. -void VM_RedefineClasses::redefine_single_class(jclass the_jclass,
  9431. - instanceKlassHandle scratch_class, TRAPS) {
  9432. +void VM_RedefineClasses::redefine_single_class(instanceKlassHandle the_new_class, TRAPS) {
  9433. +
  9434. + ResourceMark rm(THREAD);
  9435. - RC_TIMER_START(_timer_rsc_phase1);
  9436. + assert(the_new_class->old_version() != NULL, "Must not be null");
  9437. + assert(the_new_class->old_version()->klass_part()->new_version() == the_new_class(), "Must equal");
  9438. - oop the_class_mirror = JNIHandles::resolve_non_null(the_jclass);
  9439. - klassOop the_class_oop = java_lang_Class::as_klassOop(the_class_mirror);
  9440. - instanceKlassHandle the_class = instanceKlassHandle(THREAD, the_class_oop);
  9441. + instanceKlassHandle the_old_class = instanceKlassHandle(THREAD, the_new_class->old_version());
  9442. +#ifndef JVMTI_KERNEL
  9443. // Remove all breakpoints in methods of this class
  9444. JvmtiBreakpoints& jvmti_breakpoints = JvmtiCurrentBreakpoints::get_jvmti_breakpoints();
  9445. - jvmti_breakpoints.clearall_in_class_at_safepoint(the_class_oop);
  9446. + jvmti_breakpoints.clearall_in_class_at_safepoint(the_old_class());
  9447. +#endif // !JVMTI_KERNEL
  9448. - if (the_class_oop == Universe::reflect_invoke_cache()->klass()) {
  9449. + if (the_old_class() == Universe::reflect_invoke_cache()->klass()) {
  9450. // We are redefining java.lang.reflect.Method. Method.invoke() is
  9451. // cached and users of the cache care about each active version of
  9452. // the method so we have to track this previous version.
  9453. // Do this before methods get switched
  9454. Universe::reflect_invoke_cache()->add_previous_version(
  9455. - the_class->method_with_idnum(Universe::reflect_invoke_cache()->method_idnum()));
  9456. + the_old_class->method_with_idnum(Universe::reflect_invoke_cache()->method_idnum()));
  9457. }
  9458. - // Deoptimize all compiled code that depends on this class
  9459. - flush_dependent_code(the_class, THREAD);
  9460. -
  9461. - _old_methods = the_class->methods();
  9462. - _new_methods = scratch_class->methods();
  9463. - _the_class_oop = the_class_oop;
  9464. + _old_methods = the_old_class->methods();
  9465. + _new_methods = the_new_class->methods();
  9466. + _the_class_oop = the_old_class();
  9467. compute_added_deleted_matching_methods();
  9468. - update_jmethod_ids();
  9469. -
  9470. - // Attach new constant pool to the original klass. The original
  9471. - // klass still refers to the old constant pool (for now).
  9472. - scratch_class->constants()->set_pool_holder(the_class());
  9473. -
  9474. -#if 0
  9475. - // In theory, with constant pool merging in place we should be able
  9476. - // to save space by using the new, merged constant pool in place of
  9477. - // the old constant pool(s). By "pool(s)" I mean the constant pool in
  9478. - // the klass version we are replacing now and any constant pool(s) in
  9479. - // previous versions of klass. Nice theory, doesn't work in practice.
  9480. - // When this code is enabled, even simple programs throw NullPointer
  9481. - // exceptions. I'm guessing that this is caused by some constant pool
  9482. - // cache difference between the new, merged constant pool and the
  9483. - // constant pool that was just being used by the klass. I'm keeping
  9484. - // this code around to archive the idea, but the code has to remain
  9485. - // disabled for now.
  9486. -
  9487. - // Attach each old method to the new constant pool. This can be
  9488. - // done here since we are past the bytecode verification and
  9489. - // constant pool optimization phases.
  9490. - for (int i = _old_methods->length() - 1; i >= 0; i--) {
  9491. - methodOop method = (methodOop)_old_methods->obj_at(i);
  9492. - method->set_constants(scratch_class->constants());
  9493. - }
  9494. -
  9495. - {
  9496. - // walk all previous versions of the klass
  9497. - instanceKlass *ik = (instanceKlass *)the_class()->klass_part();
  9498. - PreviousVersionWalker pvw(ik);
  9499. - instanceKlassHandle ikh;
  9500. - do {
  9501. - ikh = pvw.next_previous_version();
  9502. - if (!ikh.is_null()) {
  9503. - ik = ikh();
  9504. -
  9505. - // attach previous version of klass to the new constant pool
  9506. - ik->set_constants(scratch_class->constants());
  9507. -
  9508. - // Attach each method in the previous version of klass to the
  9509. - // new constant pool
  9510. - objArrayOop prev_methods = ik->methods();
  9511. - for (int i = prev_methods->length() - 1; i >= 0; i--) {
  9512. - methodOop method = (methodOop)prev_methods->obj_at(i);
  9513. - method->set_constants(scratch_class->constants());
  9514. - }
  9515. - }
  9516. - } while (!ikh.is_null());
  9517. - }
  9518. -#endif
  9519. -
  9520. - // Replace methods and constantpool
  9521. - the_class->set_methods(_new_methods);
  9522. - scratch_class->set_methods(_old_methods); // To prevent potential GCing of the old methods,
  9523. - // and to be able to undo operation easily.
  9524. -
  9525. - constantPoolOop old_constants = the_class->constants();
  9526. - the_class->set_constants(scratch_class->constants());
  9527. - scratch_class->set_constants(old_constants); // See the previous comment.
  9528. -#if 0
  9529. - // We are swapping the guts of "the new class" with the guts of "the
  9530. - // class". Since the old constant pool has just been attached to "the
  9531. - // new class", it seems logical to set the pool holder in the old
  9532. - // constant pool also. However, doing this will change the observable
  9533. - // class hierarchy for any old methods that are still executing. A
  9534. - // method can query the identity of its "holder" and this query uses
  9535. - // the method's constant pool link to find the holder. The change in
  9536. - // holding class from "the class" to "the new class" can confuse
  9537. - // things.
  9538. - //
  9539. - // Setting the old constant pool's holder will also cause
  9540. - // verification done during vtable initialization below to fail.
  9541. - // During vtable initialization, the vtable's class is verified to be
  9542. - // a subtype of the method's holder. The vtable's class is "the
  9543. - // class" and the method's holder is gotten from the constant pool
  9544. - // link in the method itself. For "the class"'s directly implemented
  9545. - // methods, the method holder is "the class" itself (as gotten from
  9546. - // the new constant pool). The check works fine in this case. The
  9547. - // check also works fine for methods inherited from super classes.
  9548. - //
  9549. - // Miranda methods are a little more complicated. A miranda method is
  9550. - // provided by an interface when the class implementing the interface
  9551. - // does not provide its own method. These interfaces are implemented
  9552. - // internally as an instanceKlass. These special instanceKlasses
  9553. - // share the constant pool of the class that "implements" the
  9554. - // interface. By sharing the constant pool, the method holder of a
  9555. - // miranda method is the class that "implements" the interface. In a
  9556. - // non-redefine situation, the subtype check works fine. However, if
  9557. - // the old constant pool's pool holder is modified, then the check
  9558. - // fails because there is no class hierarchy relationship between the
  9559. - // vtable's class and "the new class".
  9560. -
  9561. - old_constants->set_pool_holder(scratch_class());
  9562. -#endif
  9563. // track which methods are EMCP for add_previous_version() call below
  9564. - BitMap emcp_methods(_old_methods->length());
  9565. +
  9566. + // (tw) TODO: Check if we need the concept of EMCP?
  9567. + BitMap emcp_methods(_old_methods->length());
  9568. int emcp_method_count = 0;
  9569. emcp_methods.clear(); // clears 0..(length() - 1)
  9570. +
  9571. + // We need to mark methods as old!!
  9572. check_methods_and_mark_as_obsolete(&emcp_methods, &emcp_method_count);
  9573. - transfer_old_native_function_registrations(the_class);
  9574. -
  9575. - // The class file bytes from before any retransformable agents mucked
  9576. - // with them was cached on the scratch class, move to the_class.
  9577. - // Note: we still want to do this if nothing needed caching since it
  9578. - // should get cleared in the_class too.
  9579. - if (the_class->get_cached_class_file_bytes() == 0) {
  9580. - // the_class doesn't have a cache yet so copy it
  9581. - the_class->set_cached_class_file(
  9582. - scratch_class->get_cached_class_file_bytes(),
  9583. - scratch_class->get_cached_class_file_len());
  9584. - }
  9585. -#ifndef PRODUCT
  9586. - else {
  9587. - assert(the_class->get_cached_class_file_bytes() ==
  9588. - scratch_class->get_cached_class_file_bytes(), "cache ptrs must match");
  9589. - assert(the_class->get_cached_class_file_len() ==
  9590. - scratch_class->get_cached_class_file_len(), "cache lens must match");
  9591. - }
  9592. -#endif
  9593. -
  9594. - // Replace inner_classes
  9595. - typeArrayOop old_inner_classes = the_class->inner_classes();
  9596. - the_class->set_inner_classes(scratch_class->inner_classes());
  9597. - scratch_class->set_inner_classes(old_inner_classes);
  9598. -
  9599. - // Initialize the vtable and interface table after
  9600. - // methods have been rewritten
  9601. - {
  9602. - ResourceMark rm(THREAD);
  9603. - // no exception should happen here since we explicitly
  9604. - // do not check loader constraints.
  9605. - // compare_and_normalize_class_versions has already checked:
  9606. - // - classloaders unchanged, signatures unchanged
  9607. - // - all instanceKlasses for redefined classes reused & contents updated
  9608. - the_class->vtable()->initialize_vtable(false, THREAD);
  9609. - the_class->itable()->initialize_itable(false, THREAD);
  9610. - assert(!HAS_PENDING_EXCEPTION || (THREAD->pending_exception()->is_a(SystemDictionary::ThreadDeath_klass())), "redefine exception");
  9611. - }
  9612. -
  9613. - // Leave arrays of jmethodIDs and itable index cache unchanged
  9614. -
  9615. - // Copy the "source file name" attribute from new class version
  9616. - the_class->set_source_file_name(scratch_class->source_file_name());
  9617. -
  9618. - // Copy the "source debug extension" attribute from new class version
  9619. - the_class->set_source_debug_extension(
  9620. - scratch_class->source_debug_extension(),
  9621. - scratch_class->source_debug_extension() == NULL ? 0 :
  9622. - (int)strlen(scratch_class->source_debug_extension()));
  9623. -
  9624. - // Use of javac -g could be different in the old and the new
  9625. - if (scratch_class->access_flags().has_localvariable_table() !=
  9626. - the_class->access_flags().has_localvariable_table()) {
  9627. -
  9628. - AccessFlags flags = the_class->access_flags();
  9629. - if (scratch_class->access_flags().has_localvariable_table()) {
  9630. - flags.set_has_localvariable_table();
  9631. - } else {
  9632. - flags.clear_has_localvariable_table();
  9633. - }
  9634. - the_class->set_access_flags(flags);
  9635. - }
  9636. -
  9637. - // Replace class annotation fields values
  9638. - typeArrayOop old_class_annotations = the_class->class_annotations();
  9639. - the_class->set_class_annotations(scratch_class->class_annotations());
  9640. - scratch_class->set_class_annotations(old_class_annotations);
  9641. -
  9642. - // Replace fields annotation fields values
  9643. - objArrayOop old_fields_annotations = the_class->fields_annotations();
  9644. - the_class->set_fields_annotations(scratch_class->fields_annotations());
  9645. - scratch_class->set_fields_annotations(old_fields_annotations);
  9646. -
  9647. - // Replace methods annotation fields values
  9648. - objArrayOop old_methods_annotations = the_class->methods_annotations();
  9649. - the_class->set_methods_annotations(scratch_class->methods_annotations());
  9650. - scratch_class->set_methods_annotations(old_methods_annotations);
  9651. -
  9652. - // Replace methods parameter annotation fields values
  9653. - objArrayOop old_methods_parameter_annotations =
  9654. - the_class->methods_parameter_annotations();
  9655. - the_class->set_methods_parameter_annotations(
  9656. - scratch_class->methods_parameter_annotations());
  9657. - scratch_class->set_methods_parameter_annotations(old_methods_parameter_annotations);
  9658. -
  9659. - // Replace methods default annotation fields values
  9660. - objArrayOop old_methods_default_annotations =
  9661. - the_class->methods_default_annotations();
  9662. - the_class->set_methods_default_annotations(
  9663. - scratch_class->methods_default_annotations());
  9664. - scratch_class->set_methods_default_annotations(old_methods_default_annotations);
  9665. -
  9666. - // Replace minor version number of class file
  9667. - u2 old_minor_version = the_class->minor_version();
  9668. - the_class->set_minor_version(scratch_class->minor_version());
  9669. - scratch_class->set_minor_version(old_minor_version);
  9670. -
  9671. - // Replace major version number of class file
  9672. - u2 old_major_version = the_class->major_version();
  9673. - the_class->set_major_version(scratch_class->major_version());
  9674. - scratch_class->set_major_version(old_major_version);
  9675. -
  9676. - // Replace CP indexes for class and name+type of enclosing method
  9677. - u2 old_class_idx = the_class->enclosing_method_class_index();
  9678. - u2 old_method_idx = the_class->enclosing_method_method_index();
  9679. - the_class->set_enclosing_method_indices(
  9680. - scratch_class->enclosing_method_class_index(),
  9681. - scratch_class->enclosing_method_method_index());
  9682. - scratch_class->set_enclosing_method_indices(old_class_idx, old_method_idx);
  9683. + update_jmethod_ids();
  9684. // keep track of previous versions of this class
  9685. - the_class->add_previous_version(scratch_class, &emcp_methods,
  9686. + the_new_class->add_previous_version(the_old_class, &emcp_methods,
  9687. emcp_method_count);
  9688. - RC_TIMER_STOP(_timer_rsc_phase1);
  9689. - RC_TIMER_START(_timer_rsc_phase2);
  9690. + // TODO:
  9691. + transfer_old_native_function_registrations(the_old_class);
  9692. - // Adjust constantpool caches and vtables for all classes
  9693. - // that reference methods of the evolved class.
  9694. - SystemDictionary::classes_do(adjust_cpool_cache_and_vtable, THREAD);
  9695. - // JSR-292 support
  9696. - MemberNameTable* mnt = the_class->member_names();
  9697. - if (mnt != NULL) {
  9698. - bool trace_name_printed = false;
  9699. - mnt->adjust_method_entries(_matching_old_methods,
  9700. - _matching_new_methods,
  9701. - _matching_methods_length,
  9702. - &trace_name_printed);
  9703. - }
  9704. +#ifdef ASSERT
  9705. +
  9706. +// klassOop systemLookup1 = SystemDictionary::resolve_or_null(the_old_class->name(), the_old_class->class_loader(), the_old_class->protection_domain(), THREAD);
  9707. +// assert(systemLookup1 == the_new_class(), "New class must be in system dictionary!");
  9708. +
  9709. + //JNIHandles::verify();
  9710. - if (the_class->oop_map_cache() != NULL) {
  9711. - // Flush references to any obsolete methods from the oop map cache
  9712. - // so that obsolete methods are not pinned.
  9713. - the_class->oop_map_cache()->flush_obsolete_entries();
  9714. +// klassOop systemLookup = SystemDictionary::resolve_or_null(the_old_class->name(), the_old_class->class_loader(), the_old_class->protection_domain(), THREAD);
  9715. +
  9716. +// assert(systemLookup == the_new_class(), "New class must be in system dictionary!");
  9717. + assert(the_new_class->old_version() != NULL, "Must not be null");
  9718. + assert(the_new_class->old_version()->klass_part()->new_version() == the_new_class(), "Must equal");
  9719. +
  9720. + for (int i=0; i<the_new_class->methods()->length(); i++) {
  9721. + assert(((methodOop)the_new_class->methods()->obj_at(i))->method_holder() == the_new_class(), "method holder must match!");
  9722. }
  9723. + _old_methods->verify();
  9724. + _new_methods->verify();
  9725. +
  9726. + the_new_class->vtable()->verify(tty);
  9727. + the_old_class->vtable()->verify(tty);
  9728. +
  9729. +#endif
  9730. +
  9731. // increment the classRedefinedCount field in the_class and in any
  9732. // direct and indirect subclasses of the_class
  9733. - increment_class_counter((instanceKlass *)the_class()->klass_part(), THREAD);
  9734. + increment_class_counter((instanceKlass *)the_old_class()->klass_part(), THREAD);
  9735. +
  9736. +}
  9737. +
  9738. +
  9739. +void VM_RedefineClasses::check_methods_and_mark_as_obsolete(BitMap *emcp_methods, int * emcp_method_count_p) {
  9740. + RC_TRACE(0x00008000, ("Checking matching methods for EMCP"));
  9741. + *emcp_method_count_p = 0;
  9742. + int obsolete_count = 0;
  9743. + int old_index = 0;
  9744. + for (int j = 0; j < _matching_methods_length; ++j, ++old_index) {
  9745. + methodOop old_method = (methodOop)_old_methods->obj_at(_matching_old_methods[j]);
  9746. + methodOop new_method = (methodOop)_new_methods->obj_at(_matching_new_methods[j]);
  9747. + methodOop old_array_method;
  9748. +
  9749. + // Maintain an old_index into the _old_methods array by skipping
  9750. + // deleted methods
  9751. + while ((old_array_method = (methodOop) _old_methods->obj_at(old_index))
  9752. + != old_method) {
  9753. + ++old_index;
  9754. + }
  9755. +
  9756. + if (MethodComparator::methods_EMCP(old_method, new_method)) {
  9757. + // The EMCP definition from JSR-163 requires the bytecodes to be
  9758. + // the same with the exception of constant pool indices which may
  9759. + // differ. However, the constants referred to by those indices
  9760. + // must be the same.
  9761. + //
  9762. + // We use methods_EMCP() for comparison since constant pool
  9763. + // merging can remove duplicate constant pool entries that were
  9764. + // present in the old method and removed from the rewritten new
  9765. + // method. A faster binary comparison function would consider the
  9766. + // old and new methods to be different when they are actually
  9767. + // EMCP.
  9768. +
  9769. + // track which methods are EMCP for add_previous_version() call
  9770. + emcp_methods->set_bit(old_index);
  9771. + (*emcp_method_count_p)++;
  9772. +
  9773. + // An EMCP method is _not_ obsolete. An obsolete method has a
  9774. + // different jmethodID than the current method. An EMCP method
  9775. + // has the same jmethodID as the current method. Having the
  9776. + // same jmethodID for all EMCP versions of a method allows for
  9777. + // a consistent view of the EMCP methods regardless of which
  9778. + // EMCP method you happen to have in hand. For example, a
  9779. + // breakpoint set in one EMCP method will work for all EMCP
  9780. + // versions of the method including the current one.
  9781. +
  9782. + old_method->set_new_version(new_method);
  9783. + new_method->set_old_version(old_method);
  9784. +
  9785. + RC_TRACE(0x00008000, ("Found EMCP method %s", old_method->name_and_sig_as_C_string()));
  9786. +
  9787. + // Transfer breakpoints
  9788. + instanceKlass *ik = instanceKlass::cast(old_method->method_holder());
  9789. + for (BreakpointInfo* bp = ik->breakpoints(); bp != NULL; bp = bp->next()) {
  9790. + RC_TRACE(0x00000002, ("Checking breakpoint"));
  9791. + RC_TRACE(0x00000002, ("%d / %d",
  9792. + bp->match(old_method), bp->match(new_method)));
  9793. + if (bp->match(old_method)) {
  9794. + assert(bp->match(new_method), "if old method is method, then new method must match too");
  9795. + RC_TRACE(0x00000002, ("Found a breakpoint in an old EMCP method"));
  9796. + new_method->set_breakpoint(bp->bci());
  9797. + }
  9798. + }
  9799. +
  9800. +
  9801. - // RC_TRACE macro has an embedded ResourceMark
  9802. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  9803. - ("redefined name=%s, count=%d (avail_mem=" UINT64_FORMAT "K)",
  9804. - the_class->external_name(),
  9805. - java_lang_Class::classRedefinedCount(the_class_mirror),
  9806. - os::available_memory() >> 10));
  9807. + } else {
  9808. + // mark obsolete methods as such
  9809. + old_method->set_is_obsolete();
  9810. + obsolete_count++;
  9811. +
  9812. + // With tracing we try not to "yack" too much. The position of
  9813. + // this trace assumes there are fewer obsolete methods than
  9814. + // EMCP methods.
  9815. + RC_TRACE(0x00008000, ("mark %s(%s) as obsolete",
  9816. + old_method->name()->as_C_string(),
  9817. + old_method->signature()->as_C_string()));
  9818. + }
  9819. + old_method->set_is_old();
  9820. + }
  9821. + for (int i = 0; i < _deleted_methods_length; ++i) {
  9822. + methodOop old_method = (methodOop)_old_methods->obj_at(_deleted_methods[i]);
  9823. - RC_TIMER_STOP(_timer_rsc_phase2);
  9824. -} // end redefine_single_class()
  9825. + //assert(old_method->vtable_index() < 0,
  9826. + // "cannot delete methods with vtable entries");;
  9827. + // Mark all deleted methods as old and obsolete
  9828. + old_method->set_is_old();
  9829. + old_method->set_is_obsolete();
  9830. + ++obsolete_count;
  9831. + // With tracing we try not to "yack" too much. The position of
  9832. + // this trace assumes there are fewer obsolete methods than
  9833. + // EMCP methods.
  9834. + RC_TRACE(0x00008000, ("mark deleted %s(%s) as obsolete",
  9835. + old_method->name()->as_C_string(),
  9836. + old_method->signature()->as_C_string()));
  9837. + }
  9838. + //assert((*emcp_method_count_p + obsolete_count) == _old_methods->length(), "sanity check");
  9839. + RC_TRACE(0x00008000, ("EMCP_cnt=%d, obsolete_cnt=%d !", *emcp_method_count_p, obsolete_count));
  9840. +}
  9841. // Increment the classRedefinedCount field in the specific instanceKlass
  9842. // and in all direct and indirect subclasses.
  9843. @@ -3485,134 +2953,324 @@ void VM_RedefineClasses::increment_class_counter(instanceKlass *ik, TRAPS) {
  9844. klassOop class_oop = java_lang_Class::as_klassOop(class_mirror);
  9845. int new_count = java_lang_Class::classRedefinedCount(class_mirror) + 1;
  9846. java_lang_Class::set_classRedefinedCount(class_mirror, new_count);
  9847. + RC_TRACE(0x00008000, ("updated count for class=%s to %d", ik->external_name(), new_count));
  9848. +}
  9849. +
  9850. +#ifndef PRODUCT
  9851. +void VM_RedefineClasses::check_class(klassOop k_oop, TRAPS) {
  9852. + Klass *k = k_oop->klass_part();
  9853. + if (k->oop_is_instance()) {
  9854. + HandleMark hm(THREAD);
  9855. + instanceKlass *ik = (instanceKlass *) k;
  9856. + assert(ik->is_newest_version(), "must be latest version in system dictionary");
  9857. +
  9858. + if (ik->vtable_length() > 0) {
  9859. + ResourceMark rm(THREAD);
  9860. + if (!ik->vtable()->check_no_old_entries()) {
  9861. + RC_TRACE(0x00000001, ("size of class: %d\n",
  9862. + k_oop->size()));
  9863. + RC_TRACE(0x00000001, ("klassVtable::check_no_old_entries failure -- OLD method found -- class: %s",
  9864. + ik->signature_name()));
  9865. + assert(false, "OLD method found");
  9866. + }
  9867. - if (class_oop != _the_class_oop) {
  9868. - // _the_class_oop count is printed at end of redefine_single_class()
  9869. - RC_TRACE_WITH_THREAD(0x00000008, THREAD,
  9870. - ("updated count in subclass=%s to %d", ik->external_name(), new_count));
  9871. + ik->vtable()->verify(tty, true);
  9872. + }
  9873. }
  9874. +}
  9875. +
  9876. +#endif
  9877. +
  9878. +VM_RedefineClasses::FindAffectedKlassesClosure::FindAffectedKlassesClosure( GrowableArray<instanceKlassHandle> *original_klasses, GrowableArray<instanceKlassHandle> *result )
  9879. +{
  9880. + assert(original_klasses != NULL && result != NULL, "");
  9881. + this->_original_klasses = original_klasses;
  9882. + this->_result = result;
  9883. + SystemDictionary::classes_do(this);
  9884. +}
  9885. - for (Klass *subk = ik->subklass(); subk != NULL;
  9886. - subk = subk->next_sibling()) {
  9887. - if (subk->oop_is_instance()) {
  9888. - // Only update instanceKlasses
  9889. - instanceKlass *subik = (instanceKlass*)subk;
  9890. - // recursively do subclasses of the current subclass
  9891. - increment_class_counter(subik, THREAD);
  9892. +void VM_RedefineClasses::FindAffectedKlassesClosure::do_object( oop obj )
  9893. +{
  9894. + klassOop klass = (klassOop)obj;
  9895. + assert(!_result->contains(klass), "must not occur more than once!");
  9896. + assert(klass->klass_part()->new_version() == NULL, "Only last version is valid entry in system dictionary");
  9897. +
  9898. + for(int i=0; i<_original_klasses->length(); i++) {
  9899. + instanceKlassHandle cur = _original_klasses->at(i);
  9900. + if (cur() != klass && klass->klass_part()->is_subtype_of(cur()) && !_original_klasses->contains(klass)) {
  9901. + RC_TRACE(0x00008000, ("Found affected class: %s", klass->klass_part()->name()->as_C_string()));
  9902. + _result->append(klass);
  9903. + break;
  9904. }
  9905. }
  9906. }
  9907. -void VM_RedefineClasses::check_class(klassOop k_oop,
  9908. - oop initiating_loader, TRAPS) {
  9909. - Klass *k = k_oop->klass_part();
  9910. - if (k->oop_is_instance()) {
  9911. - HandleMark hm(THREAD);
  9912. - instanceKlass *ik = (instanceKlass *) k;
  9913. - bool no_old_methods = true; // be optimistic
  9914. - ResourceMark rm(THREAD);
  9915. +jvmtiError VM_RedefineClasses::do_topological_class_sorting( const jvmtiClassDefinition *class_defs, int class_count, GrowableArray<instanceKlassHandle> *affected, GrowableArray<instanceKlassHandle> *arr, TRAPS)
  9916. +{
  9917. + GrowableArray< Pair<klassOop, klassOop> > *links = new GrowableArray< Pair<klassOop, klassOop> >();
  9918. - // a vtable should never contain old or obsolete methods
  9919. - if (ik->vtable_length() > 0 &&
  9920. - !ik->vtable()->check_no_old_or_obsolete_entries()) {
  9921. - if (RC_TRACE_ENABLED(0x00004000)) {
  9922. - RC_TRACE_WITH_THREAD(0x00004000, THREAD,
  9923. - ("klassVtable::check_no_old_or_obsolete_entries failure"
  9924. - " -- OLD or OBSOLETE method found -- class: %s",
  9925. - ik->signature_name()));
  9926. - ik->vtable()->dump_vtable();
  9927. - }
  9928. - no_old_methods = false;
  9929. - }
  9930. -
  9931. - // an itable should never contain old or obsolete methods
  9932. - if (ik->itable_length() > 0 &&
  9933. - !ik->itable()->check_no_old_or_obsolete_entries()) {
  9934. - if (RC_TRACE_ENABLED(0x00004000)) {
  9935. - RC_TRACE_WITH_THREAD(0x00004000, THREAD,
  9936. - ("klassItable::check_no_old_or_obsolete_entries failure"
  9937. - " -- OLD or OBSOLETE method found -- class: %s",
  9938. - ik->signature_name()));
  9939. - ik->itable()->dump_itable();
  9940. - }
  9941. - no_old_methods = false;
  9942. - }
  9943. -
  9944. - // the constant pool cache should never contain old or obsolete methods
  9945. - if (ik->constants() != NULL &&
  9946. - ik->constants()->cache() != NULL &&
  9947. - !ik->constants()->cache()->check_no_old_or_obsolete_entries()) {
  9948. - if (RC_TRACE_ENABLED(0x00004000)) {
  9949. - RC_TRACE_WITH_THREAD(0x00004000, THREAD,
  9950. - ("cp-cache::check_no_old_or_obsolete_entries failure"
  9951. - " -- OLD or OBSOLETE method found -- class: %s",
  9952. - ik->signature_name()));
  9953. - ik->constants()->cache()->dump_cache();
  9954. - }
  9955. - no_old_methods = false;
  9956. - }
  9957. -
  9958. - if (!no_old_methods) {
  9959. - if (RC_TRACE_ENABLED(0x00004000)) {
  9960. - dump_methods();
  9961. - } else {
  9962. - tty->print_cr("INFO: use the '-XX:TraceRedefineClasses=16384' option "
  9963. - "to see more info about the following guarantee() failure.");
  9964. + for (int i=0; i<class_count; i++) {
  9965. +
  9966. + oop mirror = JNIHandles::resolve_non_null(class_defs[i].klass);
  9967. + klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
  9968. + instanceKlassHandle the_class(THREAD, the_class_oop);
  9969. + Handle the_class_loader(THREAD, the_class->class_loader());
  9970. + Handle protection_domain(THREAD, the_class->protection_domain());
  9971. +
  9972. + ClassFileStream st((u1*) class_defs[i].class_bytes,
  9973. + class_defs[i].class_byte_count, (char *)"__VM_RedefineClasses__");
  9974. + ClassFileParser cfp(&st);
  9975. +
  9976. + GrowableArray<Symbol*> symbolArr;
  9977. + RC_TRACE(0x00000002, ("Before find super symbols of class %s",
  9978. + the_class->name()->as_C_string()));
  9979. + cfp.findSuperSymbols(the_class->name(), the_class_loader, protection_domain, the_class, symbolArr, THREAD);
  9980. +
  9981. + for (int j=0; j<symbolArr.length(); j++) {
  9982. + Symbol* sym = symbolArr.at(j);
  9983. +
  9984. + RC_TRACE(0x00008000, ("Before adding link to super class %s", sym->as_C_string()));
  9985. +
  9986. + for (int k=0; k<arr->length(); k++) {
  9987. + klassOop curOop = arr->at(k)();
  9988. + // (tw) TODO: Check if we get aliasing problems with different class loaders?
  9989. + if (curOop->klass_part()->name() == sym /*&& curOop->klass_part()->class_loader() == the_class_loader()*/) {
  9990. + RC_TRACE(0x00000002, ("Found class to link"));
  9991. + links->append(Pair<klassOop, klassOop>(curOop, the_class()));
  9992. + break;
  9993. + }
  9994. + }
  9995. + }
  9996. + }
  9997. +
  9998. +
  9999. + RC_TRACE(0x00000001, ("Identified links between classes! "));
  10000. +
  10001. + for (int i=0; i<affected->length(); i++) {
  10002. +
  10003. + instanceKlassHandle klass = affected->at(i);
  10004. +
  10005. + klassOop superKlass = klass->super();
  10006. + if (affected->contains(superKlass)) {
  10007. + links->append(Pair<klassOop, klassOop>(superKlass, klass()));
  10008. + }
  10009. +
  10010. + objArrayOop superInterfaces = klass->local_interfaces();
  10011. + for (int j=0; j<superInterfaces->length(); j++) {
  10012. + klassOop interfaceKlass = (klassOop)superInterfaces->obj_at(j);
  10013. + if (arr->contains(interfaceKlass)) {
  10014. + links->append(Pair<klassOop, klassOop>(interfaceKlass, klass()));
  10015. + }
  10016. + }
  10017. + }
  10018. +
  10019. + if (RC_TRACE_ENABLED(0x00000002)) {
  10020. + RC_TRACE(0x00000002, ("Identified links: "));
  10021. + for (int i=0; i<links->length(); i++) {
  10022. + RC_TRACE(0x00000002, ("%s to %s",
  10023. + links->at(i).left()->klass_part()->name()->as_C_string(),
  10024. + links->at(i).right()->klass_part()->name()->as_C_string()));
  10025. + }
  10026. + }
  10027. +
  10028. + for (int i=0; i<arr->length(); i++) {
  10029. +
  10030. + int j;
  10031. + for (j=i; j<arr->length(); j++) {
  10032. +
  10033. + int k;
  10034. + for (k=0; k<links->length(); k++) {
  10035. +
  10036. + klassOop k1 = links->adr_at(k)->right();
  10037. + klassOop k2 = arr->at(j)();
  10038. + if (k1 == k2) {
  10039. + break;
  10040. + }
  10041. + }
  10042. +
  10043. + if (k == links->length()) {
  10044. + break;
  10045. }
  10046. - guarantee(false, "OLD and/or OBSOLETE method(s) found");
  10047. + }
  10048. +
  10049. + if (j == arr->length()) {
  10050. + // circle detected
  10051. + return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  10052. + }
  10053. +
  10054. + for (int k=0; k<links->length(); k++) {
  10055. + if (links->adr_at(k)->left() == arr->at(j)()) {
  10056. + links->at_put(k, links->at(links->length() - 1));
  10057. + links->remove_at(links->length() - 1);
  10058. + k--;
  10059. + }
  10060. + }
  10061. +
  10062. + instanceKlassHandle tmp = arr->at(j);
  10063. + arr->at_put(j, arr->at(i));
  10064. + arr->at_put(i, tmp);
  10065. + }
  10066. +
  10067. + return JVMTI_ERROR_NONE;
  10068. +}
  10069. +
  10070. +void VM_RedefineClasses::oops_do(OopClosure *closure) {
  10071. +
  10072. + if (_updated_oops != NULL) {
  10073. + for (int i=0; i<_updated_oops->length(); i++) {
  10074. + closure->do_oop(_updated_oops->adr_at(i));
  10075. }
  10076. }
  10077. }
  10078. -void VM_RedefineClasses::dump_methods() {
  10079. - int j;
  10080. - RC_TRACE(0x00004000, ("_old_methods --"));
  10081. - for (j = 0; j < _old_methods->length(); ++j) {
  10082. - methodOop m = (methodOop) _old_methods->obj_at(j);
  10083. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  10084. - m->access_flags().print_on(tty);
  10085. - tty->print(" -- ");
  10086. - m->print_name(tty);
  10087. - tty->cr();
  10088. - }
  10089. - RC_TRACE(0x00004000, ("_new_methods --"));
  10090. - for (j = 0; j < _new_methods->length(); ++j) {
  10091. - methodOop m = (methodOop) _new_methods->obj_at(j);
  10092. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  10093. - m->access_flags().print_on(tty);
  10094. - tty->print(" -- ");
  10095. - m->print_name(tty);
  10096. - tty->cr();
  10097. - }
  10098. - RC_TRACE(0x00004000, ("_matching_(old/new)_methods --"));
  10099. - for (j = 0; j < _matching_methods_length; ++j) {
  10100. - methodOop m = _matching_old_methods[j];
  10101. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  10102. - m->access_flags().print_on(tty);
  10103. - tty->print(" -- ");
  10104. - m->print_name(tty);
  10105. - tty->cr();
  10106. - m = _matching_new_methods[j];
  10107. - RC_TRACE_NO_CR(0x00004000, (" (%5d) ", m->vtable_index()));
  10108. - m->access_flags().print_on(tty);
  10109. - tty->cr();
  10110. - }
  10111. - RC_TRACE(0x00004000, ("_deleted_methods --"));
  10112. - for (j = 0; j < _deleted_methods_length; ++j) {
  10113. - methodOop m = _deleted_methods[j];
  10114. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  10115. - m->access_flags().print_on(tty);
  10116. - tty->print(" -- ");
  10117. - m->print_name(tty);
  10118. - tty->cr();
  10119. - }
  10120. - RC_TRACE(0x00004000, ("_added_methods --"));
  10121. - for (j = 0; j < _added_methods_length; ++j) {
  10122. - methodOop m = _added_methods[j];
  10123. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  10124. - m->access_flags().print_on(tty);
  10125. - tty->print(" -- ");
  10126. - m->print_name(tty);
  10127. - tty->cr();
  10128. +void VM_RedefineClasses::transfer_special_access_flags(fieldDescriptor *from, fieldDescriptor *to) {
  10129. + to->set_is_field_modification_watched(from->is_field_modification_watched());
  10130. + to->set_is_field_access_watched(from->is_field_access_watched());
  10131. + if (from->is_field_modification_watched() || from->is_field_access_watched()) {
  10132. + RC_TRACE(0x00000002, ("Transferred watch for field %s",
  10133. + from->name()->as_C_string()));
  10134. + }
  10135. + update_klass_field_access_flag(to);
  10136. +}
  10137. +
  10138. +void VM_RedefineClasses::update_klass_field_access_flag(fieldDescriptor *fd) {
  10139. + instanceKlass* ik = instanceKlass::cast(fd->field_holder());
  10140. + FieldInfo* fi = FieldInfo::from_field_array(ik->fields(), fd->index());
  10141. + fi->set_access_flags(fd->access_flags().as_short());
  10142. +}
  10143. +
  10144. +
  10145. +// This internal class transfers the native function registration from old methods
  10146. +// to new methods. It is designed to handle both the simple case of unchanged
  10147. +// native methods and the complex cases of native method prefixes being added and/or
  10148. +// removed.
  10149. +// It expects only to be used during the VM_RedefineClasses op (a safepoint).
  10150. +//
  10151. +// This class is used after the new methods have been installed in "the_class".
  10152. +//
  10153. +// So, for example, the following must be handled. Where 'm' is a method and
  10154. +// a number followed by an underscore is a prefix.
  10155. +//
  10156. +// Old Name New Name
  10157. +// Simple transfer to new method m -> m
  10158. +// Add prefix m -> 1_m
  10159. +// Remove prefix 1_m -> m
  10160. +// Simultaneous add of prefixes m -> 3_2_1_m
  10161. +// Simultaneous removal of prefixes 3_2_1_m -> m
  10162. +// Simultaneous add and remove 1_m -> 2_m
  10163. +// Same, caused by prefix removal only 3_2_1_m -> 3_2_m
  10164. +//
  10165. +class TransferNativeFunctionRegistration {
  10166. +private:
  10167. + instanceKlassHandle the_class;
  10168. + int prefix_count;
  10169. + char** prefixes;
  10170. +
  10171. + // Recursively search the binary tree of possibly prefixed method names.
  10172. + // Iteration could be used if all agents were well behaved. Full tree walk is
  10173. + // more resilent to agents not cleaning up intermediate methods.
  10174. + // Branch at each depth in the binary tree is:
  10175. + // (1) without the prefix.
  10176. + // (2) with the prefix.
  10177. + // where 'prefix' is the prefix at that 'depth' (first prefix, second prefix,...)
  10178. + methodOop search_prefix_name_space(int depth, char* name_str, size_t name_len,
  10179. + Symbol* signature) {
  10180. + Symbol* name_symbol = SymbolTable::probe(name_str, (int)name_len);
  10181. + if (name_symbol != NULL) {
  10182. + methodOop method = Klass::cast(the_class()->klass_part()->new_version())->lookup_method(name_symbol, signature);
  10183. + if (method != NULL) {
  10184. + // Even if prefixed, intermediate methods must exist.
  10185. + if (method->is_native()) {
  10186. + // Wahoo, we found a (possibly prefixed) version of the method, return it.
  10187. + return method;
  10188. + }
  10189. + if (depth < prefix_count) {
  10190. + // Try applying further prefixes (other than this one).
  10191. + method = search_prefix_name_space(depth+1, name_str, name_len, signature);
  10192. + if (method != NULL) {
  10193. + return method; // found
  10194. + }
  10195. +
  10196. + // Try adding this prefix to the method name and see if it matches
  10197. + // another method name.
  10198. + char* prefix = prefixes[depth];
  10199. + size_t prefix_len = strlen(prefix);
  10200. + size_t trial_len = name_len + prefix_len;
  10201. + char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1);
  10202. + strcpy(trial_name_str, prefix);
  10203. + strcat(trial_name_str, name_str);
  10204. + method = search_prefix_name_space(depth+1, trial_name_str, trial_len,
  10205. + signature);
  10206. + if (method != NULL) {
  10207. + // If found along this branch, it was prefixed, mark as such
  10208. + method->set_is_prefixed_native();
  10209. + return method; // found
  10210. + }
  10211. + }
  10212. + }
  10213. + }
  10214. + return NULL; // This whole branch bore nothing
  10215. + }
  10216. +
  10217. + // Return the method name with old prefixes stripped away.
  10218. + char* method_name_without_prefixes(methodOop method) {
  10219. + Symbol* name = method->name();
  10220. + char* name_str = name->as_utf8();
  10221. +
  10222. + // Old prefixing may be defunct, strip prefixes, if any.
  10223. + for (int i = prefix_count-1; i >= 0; i--) {
  10224. + char* prefix = prefixes[i];
  10225. + size_t prefix_len = strlen(prefix);
  10226. + if (strncmp(prefix, name_str, prefix_len) == 0) {
  10227. + name_str += prefix_len;
  10228. + }
  10229. + }
  10230. + return name_str;
  10231. + }
  10232. +
  10233. + // Strip any prefixes off the old native method, then try to find a
  10234. + // (possibly prefixed) new native that matches it.
  10235. + methodOop strip_and_search_for_new_native(methodOop method) {
  10236. + ResourceMark rm;
  10237. + char* name_str = method_name_without_prefixes(method);
  10238. + return search_prefix_name_space(0, name_str, strlen(name_str),
  10239. + method->signature());
  10240. + }
  10241. +
  10242. +public:
  10243. +
  10244. + // Construct a native method transfer processor for this class.
  10245. + TransferNativeFunctionRegistration(instanceKlassHandle _the_class) {
  10246. + assert(SafepointSynchronize::is_at_safepoint(), "sanity check");
  10247. +
  10248. + the_class = _the_class;
  10249. + prefixes = JvmtiExport::get_all_native_method_prefixes(&prefix_count);
  10250. + }
  10251. +
  10252. + // Attempt to transfer any of the old or deleted methods that are native
  10253. + void transfer_registrations(instanceKlassHandle old_klass, int* old_methods, int methods_length) {
  10254. + for (int j = 0; j < methods_length; j++) {
  10255. + methodOop old_method = (methodOop)old_klass->methods()->obj_at(old_methods[j]);
  10256. +
  10257. + if (old_method->is_native() && old_method->has_native_function()) {
  10258. + methodOop new_method = strip_and_search_for_new_native(old_method);
  10259. + if (new_method != NULL) {
  10260. + // Actually set the native function in the new method.
  10261. + // Redefine does not send events (except CFLH), certainly not this
  10262. + // behind the scenes re-registration.
  10263. + new_method->set_native_function(old_method->native_function(),
  10264. + !methodOopDesc::native_bind_event_is_interesting);
  10265. +
  10266. + RC_TRACE(0x00008000, ("Transferring native function for method %s", old_method->name()->as_C_string()));
  10267. + }
  10268. + }
  10269. + }
  10270. }
  10271. +};
  10272. +
  10273. +// Don't lose the association between a native method and its JNI function.
  10274. +void VM_RedefineClasses::transfer_old_native_function_registrations(instanceKlassHandle old_klass) {
  10275. + TransferNativeFunctionRegistration transfer(old_klass);
  10276. + transfer.transfer_registrations(old_klass, _deleted_methods, _deleted_methods_length);
  10277. + transfer.transfer_registrations(old_klass, _matching_old_methods, _matching_methods_length);
  10278. }
  10279. diff --git a/src/share/vm/prims/jvmtiRedefineClasses.hpp b/src/share/vm/prims/jvmtiRedefineClasses.hpp
  10280. index bfac62c..d7ba79f 100644
  10281. --- a/src/share/vm/prims/jvmtiRedefineClasses.hpp
  10282. +++ b/src/share/vm/prims/jvmtiRedefineClasses.hpp
  10283. @@ -1,26 +1,29 @@
  10284. /*
  10285. - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
  10286. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  10287. - *
  10288. - * This code is free software; you can redistribute it and/or modify it
  10289. - * under the terms of the GNU General Public License version 2 only, as
  10290. - * published by the Free Software Foundation.
  10291. - *
  10292. - * This code is distributed in the hope that it will be useful, but WITHOUT
  10293. - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10294. - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  10295. - * version 2 for more details (a copy is included in the LICENSE file that
  10296. - * accompanied this code).
  10297. - *
  10298. - * You should have received a copy of the GNU General Public License version
  10299. - * 2 along with this work; if not, write to the Free Software Foundation,
  10300. - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  10301. - *
  10302. - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  10303. - * or visit www.oracle.com if you need additional information or have any
  10304. - * questions.
  10305. - *
  10306. - */
  10307. +* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  10308. +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  10309. +*
  10310. +* This code is free software; you can redistribute it and/or modify it
  10311. +* under the terms of the GNU General Public License version 2 only, as
  10312. +* published by the Free Software Foundation.
  10313. +*
  10314. +* This code is distributed in the hope that it will be useful, but WITHOUT
  10315. +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10316. +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  10317. +* version 2 for more details (a copy is included in the LICENSE file that
  10318. +* accompanied this code).
  10319. +*
  10320. +* You should have received a copy of the GNU General Public License version
  10321. +* 2 along with this work; if not, write to the Free Software Foundation,
  10322. +* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  10323. +*
  10324. +* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  10325. +* or visit www.oracle.com if you need additional information or have any
  10326. +* questions.
  10327. +*
  10328. +*/
  10329. +
  10330. +// New version that allows arbitrary changes to already loaded classes.
  10331. +// Modifications done by: Thomas Wuerthinger <thomas.wuerthinger@gmail.com>
  10332. #ifndef SHARE_VM_PRIMS_JVMTIREDEFINECLASSES_HPP
  10333. #define SHARE_VM_PRIMS_JVMTIREDEFINECLASSES_HPP
  10334. @@ -32,331 +35,28 @@
  10335. #include "oops/objArrayOop.hpp"
  10336. #include "prims/jvmtiRedefineClassesTrace.hpp"
  10337. #include "runtime/vm_operations.hpp"
  10338. +#include "gc_implementation/shared/vmGCOperations.hpp"
  10339. -// Introduction:
  10340. -//
  10341. -// The RedefineClasses() API is used to change the definition of one or
  10342. -// more classes. While the API supports redefining more than one class
  10343. -// in a single call, in general, the API is discussed in the context of
  10344. -// changing the definition of a single current class to a single new
  10345. -// class. For clarity, the current class is will always be called
  10346. -// "the_class" and the new class will always be called "scratch_class".
  10347. -//
  10348. -// The name "the_class" is used because there is only one structure
  10349. -// that represents a specific class; redefinition does not replace the
  10350. -// structure, but instead replaces parts of the structure. The name
  10351. -// "scratch_class" is used because the structure that represents the
  10352. -// new definition of a specific class is simply used to carry around
  10353. -// the parts of the new definition until they are used to replace the
  10354. -// appropriate parts in the_class. Once redefinition of a class is
  10355. -// complete, scratch_class is thrown away.
  10356. -//
  10357. -//
  10358. -// Implementation Overview:
  10359. -//
  10360. -// The RedefineClasses() API is mostly a wrapper around the VM op that
  10361. -// does the real work. The work is split in varying degrees between
  10362. -// doit_prologue(), doit() and doit_epilogue().
  10363. -//
  10364. -// 1) doit_prologue() is called by the JavaThread on the way to a
  10365. -// safepoint. It does parameter verification and loads scratch_class
  10366. -// which involves:
  10367. -// - parsing the incoming class definition using the_class' class
  10368. -// loader and security context
  10369. -// - linking scratch_class
  10370. -// - merging constant pools and rewriting bytecodes as needed
  10371. -// for the merged constant pool
  10372. -// - verifying the bytecodes in scratch_class
  10373. -// - setting up the constant pool cache and rewriting bytecodes
  10374. -// as needed to use the cache
  10375. -// - finally, scratch_class is compared to the_class to verify
  10376. -// that it is a valid replacement class
  10377. -// - if everything is good, then scratch_class is saved in an
  10378. -// instance field in the VM operation for the doit() call
  10379. -//
  10380. -// Note: A JavaThread must do the above work.
  10381. -//
  10382. -// 2) doit() is called by the VMThread during a safepoint. It installs
  10383. -// the new class definition(s) which involves:
  10384. -// - retrieving the scratch_class from the instance field in the
  10385. -// VM operation
  10386. -// - house keeping (flushing breakpoints and caches, deoptimizing
  10387. -// dependent compiled code)
  10388. -// - replacing parts in the_class with parts from scratch_class
  10389. -// - adding weak reference(s) to track the obsolete but interesting
  10390. -// parts of the_class
  10391. -// - adjusting constant pool caches and vtables in other classes
  10392. -// that refer to methods in the_class. These adjustments use the
  10393. -// SystemDictionary::classes_do() facility which only allows
  10394. -// a helper method to be specified. The interesting parameters
  10395. -// that we would like to pass to the helper method are saved in
  10396. -// static global fields in the VM operation.
  10397. -// - telling the SystemDictionary to notice our changes
  10398. -//
  10399. -// Note: the above work must be done by the VMThread to be safe.
  10400. -//
  10401. -// 3) doit_epilogue() is called by the JavaThread after the VM op
  10402. -// is finished and the safepoint is done. It simply cleans up
  10403. -// memory allocated in doit_prologue() and used in doit().
  10404. -//
  10405. -//
  10406. -// Constant Pool Details:
  10407. -//
  10408. -// When the_class is redefined, we cannot just replace the constant
  10409. -// pool in the_class with the constant pool from scratch_class because
  10410. -// that could confuse obsolete methods that may still be running.
  10411. -// Instead, the constant pool from the_class, old_cp, is merged with
  10412. -// the constant pool from scratch_class, scratch_cp. The resulting
  10413. -// constant pool, merge_cp, replaces old_cp in the_class.
  10414. -//
  10415. -// The key part of any merging algorithm is the entry comparison
  10416. -// function so we have to know the types of entries in a constant pool
  10417. -// in order to merge two of them together. Constant pools can contain
  10418. -// up to 12 different kinds of entries; the JVM_CONSTANT_Unicode entry
  10419. -// is not presently used so we only have to worry about the other 11
  10420. -// entry types. For the purposes of constant pool merging, it is
  10421. -// helpful to know that the 11 entry types fall into 3 different
  10422. -// subtypes: "direct", "indirect" and "double-indirect".
  10423. -//
  10424. -// Direct CP entries contain data and do not contain references to
  10425. -// other CP entries. The following are direct CP entries:
  10426. -// JVM_CONSTANT_{Double,Float,Integer,Long,Utf8}
  10427. -//
  10428. -// Indirect CP entries contain 1 or 2 references to a direct CP entry
  10429. -// and no other data. The following are indirect CP entries:
  10430. -// JVM_CONSTANT_{Class,NameAndType,String}
  10431. -//
  10432. -// Double-indirect CP entries contain two references to indirect CP
  10433. -// entries and no other data. The following are double-indirect CP
  10434. -// entries:
  10435. -// JVM_CONSTANT_{Fieldref,InterfaceMethodref,Methodref}
  10436. -//
  10437. -// When comparing entries between two constant pools, the entry types
  10438. -// are compared first and if they match, then further comparisons are
  10439. -// made depending on the entry subtype. Comparing direct CP entries is
  10440. -// simply a matter of comparing the data associated with each entry.
  10441. -// Comparing both indirect and double-indirect CP entries requires
  10442. -// recursion.
  10443. -//
  10444. -// Fortunately, the recursive combinations are limited because indirect
  10445. -// CP entries can only refer to direct CP entries and double-indirect
  10446. -// CP entries can only refer to indirect CP entries. The following is
  10447. -// an example illustration of the deepest set of indirections needed to
  10448. -// access the data associated with a JVM_CONSTANT_Fieldref entry:
  10449. -//
  10450. -// JVM_CONSTANT_Fieldref {
  10451. -// class_index => JVM_CONSTANT_Class {
  10452. -// name_index => JVM_CONSTANT_Utf8 {
  10453. -// <data-1>
  10454. -// }
  10455. -// }
  10456. -// name_and_type_index => JVM_CONSTANT_NameAndType {
  10457. -// name_index => JVM_CONSTANT_Utf8 {
  10458. -// <data-2>
  10459. -// }
  10460. -// descriptor_index => JVM_CONSTANT_Utf8 {
  10461. -// <data-3>
  10462. -// }
  10463. -// }
  10464. -// }
  10465. -//
  10466. -// The above illustration is not a data structure definition for any
  10467. -// computer language. The curly braces ('{' and '}') are meant to
  10468. -// delimit the context of the "fields" in the CP entry types shown.
  10469. -// Each indirection from the JVM_CONSTANT_Fieldref entry is shown via
  10470. -// "=>", e.g., the class_index is used to indirectly reference a
  10471. -// JVM_CONSTANT_Class entry where the name_index is used to indirectly
  10472. -// reference a JVM_CONSTANT_Utf8 entry which contains the interesting
  10473. -// <data-1>. In order to understand a JVM_CONSTANT_Fieldref entry, we
  10474. -// have to do a total of 5 indirections just to get to the CP entries
  10475. -// that contain the interesting pieces of data and then we have to
  10476. -// fetch the three pieces of data. This means we have to do a total of
  10477. -// (5 + 3) * 2 == 16 dereferences to compare two JVM_CONSTANT_Fieldref
  10478. -// entries.
  10479. -//
  10480. -// Here is the indirection, data and dereference count for each entry
  10481. -// type:
  10482. -//
  10483. -// JVM_CONSTANT_Class 1 indir, 1 data, 2 derefs
  10484. -// JVM_CONSTANT_Double 0 indir, 1 data, 1 deref
  10485. -// JVM_CONSTANT_Fieldref 2 indir, 3 data, 8 derefs
  10486. -// JVM_CONSTANT_Float 0 indir, 1 data, 1 deref
  10487. -// JVM_CONSTANT_Integer 0 indir, 1 data, 1 deref
  10488. -// JVM_CONSTANT_InterfaceMethodref 2 indir, 3 data, 8 derefs
  10489. -// JVM_CONSTANT_Long 0 indir, 1 data, 1 deref
  10490. -// JVM_CONSTANT_Methodref 2 indir, 3 data, 8 derefs
  10491. -// JVM_CONSTANT_NameAndType 1 indir, 2 data, 4 derefs
  10492. -// JVM_CONSTANT_String 1 indir, 1 data, 2 derefs
  10493. -// JVM_CONSTANT_Utf8 0 indir, 1 data, 1 deref
  10494. -//
  10495. -// So different subtypes of CP entries require different amounts of
  10496. -// work for a proper comparison.
  10497. -//
  10498. -// Now that we've talked about the different entry types and how to
  10499. -// compare them we need to get back to merging. This is not a merge in
  10500. -// the "sort -u" sense or even in the "sort" sense. When we merge two
  10501. -// constant pools, we copy all the entries from old_cp to merge_cp,
  10502. -// preserving entry order. Next we append all the unique entries from
  10503. -// scratch_cp to merge_cp and we track the index changes from the
  10504. -// location in scratch_cp to the possibly new location in merge_cp.
  10505. -// When we are done, any obsolete code that is still running that
  10506. -// uses old_cp should not be able to observe any difference if it
  10507. -// were to use merge_cp. As for the new code in scratch_class, it is
  10508. -// modified to use the appropriate index values in merge_cp before it
  10509. -// is used to replace the code in the_class.
  10510. -//
  10511. -// There is one small complication in copying the entries from old_cp
  10512. -// to merge_cp. Two of the CP entry types are special in that they are
  10513. -// lazily resolved. Before explaining the copying complication, we need
  10514. -// to digress into CP entry resolution.
  10515. -//
  10516. -// JVM_CONSTANT_Class and JVM_CONSTANT_String entries are present in
  10517. -// the class file, but are not stored in memory as such until they are
  10518. -// resolved. The entries are not resolved unless they are used because
  10519. -// resolution is expensive. During class file parsing the entries are
  10520. -// initially stored in memory as JVM_CONSTANT_ClassIndex and
  10521. -// JVM_CONSTANT_StringIndex entries. These special CP entry types
  10522. -// indicate that the JVM_CONSTANT_Class and JVM_CONSTANT_String entries
  10523. -// have been parsed, but the index values in the entries have not been
  10524. -// validated. After the entire constant pool has been parsed, the index
  10525. -// values can be validated and then the entries are converted into
  10526. -// JVM_CONSTANT_UnresolvedClass and JVM_CONSTANT_UnresolvedString
  10527. -// entries. During this conversion process, the UTF8 values that are
  10528. -// indirectly referenced by the JVM_CONSTANT_ClassIndex and
  10529. -// JVM_CONSTANT_StringIndex entries are changed into Symbol*s and the
  10530. -// entries are modified to refer to the Symbol*s. This optimization
  10531. -// eliminates one level of indirection for those two CP entry types and
  10532. -// gets the entries ready for verification. During class file parsing
  10533. -// it is also possible for JVM_CONSTANT_UnresolvedString entries to be
  10534. -// resolved into JVM_CONSTANT_String entries. Verification expects to
  10535. -// find JVM_CONSTANT_UnresolvedClass and either JVM_CONSTANT_String or
  10536. -// JVM_CONSTANT_UnresolvedString entries and not JVM_CONSTANT_Class
  10537. -// entries.
  10538. -//
  10539. -// Now we can get back to the copying complication. When we copy
  10540. -// entries from old_cp to merge_cp, we have to revert any
  10541. -// JVM_CONSTANT_Class entries to JVM_CONSTANT_UnresolvedClass entries
  10542. -// or verification will fail.
  10543. -//
  10544. -// It is important to explicitly state that the merging algorithm
  10545. -// effectively unresolves JVM_CONSTANT_Class entries that were in the
  10546. -// old_cp when they are changed into JVM_CONSTANT_UnresolvedClass
  10547. -// entries in the merge_cp. This is done both to make verification
  10548. -// happy and to avoid adding more brittleness between RedefineClasses
  10549. -// and the constant pool cache. By allowing the constant pool cache
  10550. -// implementation to (re)resolve JVM_CONSTANT_UnresolvedClass entries
  10551. -// into JVM_CONSTANT_Class entries, we avoid having to embed knowledge
  10552. -// about those algorithms in RedefineClasses.
  10553. -//
  10554. -// Appending unique entries from scratch_cp to merge_cp is straight
  10555. -// forward for direct CP entries and most indirect CP entries. For the
  10556. -// indirect CP entry type JVM_CONSTANT_NameAndType and for the double-
  10557. -// indirect CP entry types, the presence of more than one piece of
  10558. -// interesting data makes appending the entries more complicated.
  10559. -//
  10560. -// For the JVM_CONSTANT_{Double,Float,Integer,Long,Utf8} entry types,
  10561. -// the entry is simply copied from scratch_cp to the end of merge_cp.
  10562. -// If the index in scratch_cp is different than the destination index
  10563. -// in merge_cp, then the change in index value is tracked.
  10564. -//
  10565. -// Note: the above discussion for the direct CP entries also applies
  10566. -// to the JVM_CONSTANT_Unresolved{Class,String} entry types.
  10567. -//
  10568. -// For the JVM_CONSTANT_{Class,String} entry types, since there is only
  10569. -// one data element at the end of the recursion, we know that we have
  10570. -// either one or two unique entries. If the JVM_CONSTANT_Utf8 entry is
  10571. -// unique then it is appended to merge_cp before the current entry.
  10572. -// If the JVM_CONSTANT_Utf8 entry is not unique, then the current entry
  10573. -// is updated to refer to the duplicate entry in merge_cp before it is
  10574. -// appended to merge_cp. Again, any changes in index values are tracked
  10575. -// as needed.
  10576. -//
  10577. -// Note: the above discussion for JVM_CONSTANT_{Class,String} entry
  10578. -// types is theoretical. Since those entry types have already been
  10579. -// optimized into JVM_CONSTANT_Unresolved{Class,String} entry types,
  10580. -// they are handled as direct CP entries.
  10581. -//
  10582. -// For the JVM_CONSTANT_NameAndType entry type, since there are two
  10583. -// data elements at the end of the recursions, we know that we have
  10584. -// between one and three unique entries. Any unique JVM_CONSTANT_Utf8
  10585. -// entries are appended to merge_cp before the current entry. For any
  10586. -// JVM_CONSTANT_Utf8 entries that are not unique, the current entry is
  10587. -// updated to refer to the duplicate entry in merge_cp before it is
  10588. -// appended to merge_cp. Again, any changes in index values are tracked
  10589. -// as needed.
  10590. -//
  10591. -// For the JVM_CONSTANT_{Fieldref,InterfaceMethodref,Methodref} entry
  10592. -// types, since there are two indirect CP entries and three data
  10593. -// elements at the end of the recursions, we know that we have between
  10594. -// one and six unique entries. See the JVM_CONSTANT_Fieldref diagram
  10595. -// above for an example of all six entries. The uniqueness algorithm
  10596. -// for the JVM_CONSTANT_Class and JVM_CONSTANT_NameAndType entries is
  10597. -// covered above. Any unique entries are appended to merge_cp before
  10598. -// the current entry. For any entries that are not unique, the current
  10599. -// entry is updated to refer to the duplicate entry in merge_cp before
  10600. -// it is appended to merge_cp. Again, any changes in index values are
  10601. -// tracked as needed.
  10602. -//
  10603. -//
  10604. -// Other Details:
  10605. -//
  10606. -// Details for other parts of RedefineClasses need to be written.
  10607. -// This is a placeholder section.
  10608. -//
  10609. -//
  10610. -// Open Issues (in no particular order):
  10611. -//
  10612. -// - How do we serialize the RedefineClasses() API without deadlocking?
  10613. -//
  10614. -// - SystemDictionary::parse_stream() was called with a NULL protection
  10615. -// domain since the initial version. This has been changed to pass
  10616. -// the_class->protection_domain(). This change has been tested with
  10617. -// all NSK tests and nothing broke, but what will adding it now break
  10618. -// in ways that we don't test?
  10619. -//
  10620. -// - GenerateOopMap::rewrite_load_or_store() has a comment in its
  10621. -// (indirect) use of the Relocator class that the max instruction
  10622. -// size is 4 bytes. goto_w and jsr_w are 5 bytes and wide/iinc is
  10623. -// 6 bytes. Perhaps Relocator only needs a 4 byte buffer to do
  10624. -// what it does to the bytecodes. More investigation is needed.
  10625. -//
  10626. -// - java.lang.Object methods can be called on arrays. This is
  10627. -// implemented via the arrayKlassOop vtable which we don't
  10628. -// update. For example, if we redefine java.lang.Object.toString(),
  10629. -// then the new version of the method will not be called for array
  10630. -// objects.
  10631. -//
  10632. -// - How do we know if redefine_single_class() and the guts of
  10633. -// instanceKlass are out of sync? I don't think this can be
  10634. -// automated, but we should probably order the work in
  10635. -// redefine_single_class() to match the order of field
  10636. -// definitions in instanceKlass. We also need to add some
  10637. -// comments about keeping things in sync.
  10638. -//
  10639. -// - set_new_constant_pool() is huge and we should consider refactoring
  10640. -// it into smaller chunks of work.
  10641. -//
  10642. -// - The exception table update code in set_new_constant_pool() defines
  10643. -// const values that are also defined in a local context elsewhere.
  10644. -// The same literal values are also used in elsewhere. We need to
  10645. -// coordinate a cleanup of these constants with Runtime.
  10646. -//
  10647. -
  10648. -class VM_RedefineClasses: public VM_Operation {
  10649. +#define RC_ABORT(error) { _result = error; return false; }
  10650. +
  10651. +class VM_RedefineClasses: public VM_GC_Operation {
  10652. private:
  10653. +
  10654. // These static fields are needed by SystemDictionary::classes_do()
  10655. // facility and the adjust_cpool_cache_and_vtable() helper:
  10656. static objArrayOop _old_methods;
  10657. static objArrayOop _new_methods;
  10658. - static methodOop* _matching_old_methods;
  10659. - static methodOop* _matching_new_methods;
  10660. - static methodOop* _deleted_methods;
  10661. - static methodOop* _added_methods;
  10662. + static int* _matching_old_methods;
  10663. + static int* _matching_new_methods;
  10664. + static int* _deleted_methods;
  10665. + static int* _added_methods;
  10666. static int _matching_methods_length;
  10667. static int _deleted_methods_length;
  10668. static int _added_methods_length;
  10669. static klassOop _the_class_oop;
  10670. + static int _revision_number;
  10671. +
  10672. // The instance fields are used to pass information from
  10673. // doit_prologue() to doit() and doit_epilogue().
  10674. jint _class_count;
  10675. @@ -370,43 +70,29 @@ class VM_RedefineClasses: public VM_Operation {
  10676. // _index_map_p contains any entries.
  10677. int _index_map_count;
  10678. intArray * _index_map_p;
  10679. -
  10680. - // _operands_index_map_count is just an optimization for knowing if
  10681. - // _operands_index_map_p contains any entries.
  10682. - int _operands_cur_length;
  10683. - int _operands_index_map_count;
  10684. - intArray * _operands_index_map_p;
  10685. -
  10686. - // ptr to _class_count scratch_classes
  10687. - instanceKlassHandle * _scratch_classes;
  10688. - jvmtiError _res;
  10689. + GrowableArray<instanceKlassHandle>* _new_classes;
  10690. + GrowableArray<oop>* _updated_oops;
  10691. + jvmtiError _result;
  10692. + int _max_redefinition_flags;
  10693. // Performance measurement support. These timers do not cover all
  10694. // the work done for JVM/TI RedefineClasses() but they do cover
  10695. // the heavy lifting.
  10696. - elapsedTimer _timer_rsc_phase1;
  10697. - elapsedTimer _timer_rsc_phase2;
  10698. - elapsedTimer _timer_vm_op_prologue;
  10699. -
  10700. - // These routines are roughly in call order unless otherwise noted.
  10701. -
  10702. - // Load the caller's new class definition(s) into _scratch_classes.
  10703. - // Constant pool merging work is done here as needed. Also calls
  10704. - // compare_and_normalize_class_versions() to verify the class
  10705. - // definition(s).
  10706. + elapsedTimer _timer_total;
  10707. + elapsedTimer _timer_prologue;
  10708. + elapsedTimer _timer_class_linking;
  10709. + elapsedTimer _timer_class_loading;
  10710. + elapsedTimer _timer_check_type;
  10711. + elapsedTimer _timer_prepare_redefinition;
  10712. + elapsedTimer _timer_wait_for_locks;
  10713. + elapsedTimer _timer_redefinition;
  10714. + elapsedTimer _timer_vm_op_epilogue;
  10715. +
  10716. + jvmtiError check_redefinition_allowed(instanceKlassHandle new_class);
  10717. + jvmtiError find_sorted_affected_classes(GrowableArray<instanceKlassHandle> *all_affected_klasses);
  10718. + jvmtiError find_class_bytes(instanceKlassHandle the_class, const unsigned char **class_bytes, jint *class_byte_count, jboolean *not_changed);
  10719. jvmtiError load_new_class_versions(TRAPS);
  10720. - // Verify that the caller provided class definition(s) that meet
  10721. - // the restrictions of RedefineClasses. Normalize the order of
  10722. - // overloaded methods as needed.
  10723. - jvmtiError compare_and_normalize_class_versions(
  10724. - instanceKlassHandle the_class, instanceKlassHandle scratch_class);
  10725. -
  10726. - // Swap annotations[i] with annotations[j]
  10727. - // Used by compare_and_normalize_class_versions() when normalizing
  10728. - // overloaded methods or changing idnum as when adding or deleting methods.
  10729. - void swap_all_method_annotations(int i, int j, instanceKlassHandle scratch_class);
  10730. -
  10731. // Figure out which new methods match old methods in name and signature,
  10732. // which methods have been added, and which are no longer present
  10733. void compute_added_deleted_matching_methods();
  10734. @@ -414,103 +100,99 @@ class VM_RedefineClasses: public VM_Operation {
  10735. // Change jmethodIDs to point to the new methods
  10736. void update_jmethod_ids();
  10737. - // In addition to marking methods as obsolete, this routine
  10738. - // records which methods are EMCP (Equivalent Module Constant
  10739. - // Pool) in the emcp_methods BitMap and returns the number of
  10740. - // EMCP methods via emcp_method_count_p. This information is
  10741. - // used when information about the previous version of the_class
  10742. - // is squirreled away.
  10743. - void check_methods_and_mark_as_obsolete(BitMap *emcp_methods,
  10744. - int * emcp_method_count_p);
  10745. - void transfer_old_native_function_registrations(instanceKlassHandle the_class);
  10746. + class FindAffectedKlassesClosure : public ObjectClosure {
  10747. +
  10748. + private:
  10749. + GrowableArray<instanceKlassHandle> *_original_klasses;
  10750. + GrowableArray<instanceKlassHandle> *_result;
  10751. +
  10752. + public:
  10753. + FindAffectedKlassesClosure(GrowableArray<instanceKlassHandle> *original_klasses, GrowableArray<instanceKlassHandle> *result);
  10754. +
  10755. + virtual void do_object(oop obj);
  10756. + };
  10757. - // Unevolving classes may point to methods of the_class directly
  10758. - // from their constant pool caches, itables, and/or vtables. We
  10759. - // use the SystemDictionary::classes_do() facility and this helper
  10760. - // to fix up these pointers.
  10761. - static void adjust_cpool_cache_and_vtable(klassOop k_oop, oop loader, TRAPS);
  10762. +
  10763. + static jvmtiError do_topological_class_sorting(const jvmtiClassDefinition *class_definitions, int class_count, GrowableArray<instanceKlassHandle> *affected, GrowableArray<instanceKlassHandle> *arr, TRAPS);
  10764. // Install the redefinition of a class
  10765. - void redefine_single_class(jclass the_jclass,
  10766. - instanceKlassHandle scratch_class, TRAPS);
  10767. + void redefine_single_class(instanceKlassHandle the_new_class, TRAPS);
  10768. // Increment the classRedefinedCount field in the specific instanceKlass
  10769. // and in all direct and indirect subclasses.
  10770. void increment_class_counter(instanceKlass *ik, TRAPS);
  10771. - // Support for constant pool merging (these routines are in alpha order):
  10772. - void append_entry(constantPoolHandle scratch_cp, int scratch_i,
  10773. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS);
  10774. - void append_operand(constantPoolHandle scratch_cp, int scratch_bootstrap_spec_index,
  10775. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS);
  10776. - void finalize_operands_merge(constantPoolHandle merge_cp, TRAPS);
  10777. - int find_or_append_indirect_entry(constantPoolHandle scratch_cp, int scratch_i,
  10778. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS);
  10779. - int find_or_append_operand(constantPoolHandle scratch_cp, int scratch_bootstrap_spec_index,
  10780. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS);
  10781. - int find_new_index(int old_index);
  10782. - int find_new_operand_index(int old_bootstrap_spec_index);
  10783. - bool is_unresolved_class_mismatch(constantPoolHandle cp1, int index1,
  10784. - constantPoolHandle cp2, int index2);
  10785. - bool is_unresolved_string_mismatch(constantPoolHandle cp1, int index1,
  10786. - constantPoolHandle cp2, int index2);
  10787. - void map_index(constantPoolHandle scratch_cp, int old_index, int new_index);
  10788. - void map_operand_index(int old_bootstrap_spec_index, int new_bootstrap_spec_index);
  10789. - bool merge_constant_pools(constantPoolHandle old_cp,
  10790. - constantPoolHandle scratch_cp, constantPoolHandle *merge_cp_p,
  10791. - int *merge_cp_length_p, TRAPS);
  10792. - jvmtiError merge_cp_and_rewrite(instanceKlassHandle the_class,
  10793. - instanceKlassHandle scratch_class, TRAPS);
  10794. - u2 rewrite_cp_ref_in_annotation_data(
  10795. - typeArrayHandle annotations_typeArray, int &byte_i_ref,
  10796. - const char * trace_mesg, TRAPS);
  10797. - bool rewrite_cp_refs(instanceKlassHandle scratch_class, TRAPS);
  10798. - bool rewrite_cp_refs_in_annotation_struct(
  10799. - typeArrayHandle class_annotations, int &byte_i_ref, TRAPS);
  10800. - bool rewrite_cp_refs_in_annotations_typeArray(
  10801. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS);
  10802. - bool rewrite_cp_refs_in_class_annotations(
  10803. - instanceKlassHandle scratch_class, TRAPS);
  10804. - bool rewrite_cp_refs_in_element_value(
  10805. - typeArrayHandle class_annotations, int &byte_i_ref, TRAPS);
  10806. - bool rewrite_cp_refs_in_fields_annotations(
  10807. - instanceKlassHandle scratch_class, TRAPS);
  10808. - void rewrite_cp_refs_in_method(methodHandle method,
  10809. - methodHandle * new_method_p, TRAPS);
  10810. - bool rewrite_cp_refs_in_methods(instanceKlassHandle scratch_class, TRAPS);
  10811. - bool rewrite_cp_refs_in_methods_annotations(
  10812. - instanceKlassHandle scratch_class, TRAPS);
  10813. - bool rewrite_cp_refs_in_methods_default_annotations(
  10814. - instanceKlassHandle scratch_class, TRAPS);
  10815. - bool rewrite_cp_refs_in_methods_parameter_annotations(
  10816. - instanceKlassHandle scratch_class, TRAPS);
  10817. - void rewrite_cp_refs_in_stack_map_table(methodHandle method, TRAPS);
  10818. - void rewrite_cp_refs_in_verification_type_info(
  10819. - address& stackmap_addr_ref, address stackmap_end, u2 frame_i,
  10820. - u1 frame_size, TRAPS);
  10821. - void set_new_constant_pool(instanceKlassHandle scratch_class,
  10822. - constantPoolHandle scratch_cp, int scratch_cp_length, TRAPS);
  10823. void flush_dependent_code(instanceKlassHandle k_h, TRAPS);
  10824. - static void check_class(klassOop k_oop, oop initiating_loader, TRAPS);
  10825. - static void dump_methods();
  10826. + static void check_class(klassOop k_oop,/* oop initiating_loader,*/ TRAPS) PRODUCT_RETURN;
  10827. +
  10828. + static void adjust_cpool_cache(klassOop k_oop, oop initiating_loader, TRAPS);
  10829. +
  10830. +#ifdef ASSERT
  10831. + static void verify_classes(klassOop k_oop, oop initiating_loader, TRAPS);
  10832. +#endif
  10833. +
  10834. + int calculate_redefinition_flags(instanceKlassHandle new_version);
  10835. + void calculate_instance_update_information(klassOop new_version);
  10836. + void check_methods_and_mark_as_obsolete(BitMap *emcp_methods, int * emcp_method_count_p);
  10837. +
  10838. + static void calculate_type_check_information(klassOop k);
  10839. + static void clear_type_check_information(klassOop k);
  10840. public:
  10841. - VM_RedefineClasses(jint class_count,
  10842. - const jvmtiClassDefinition *class_defs,
  10843. - JvmtiClassLoadKind class_load_kind);
  10844. - VMOp_Type type() const { return VMOp_RedefineClasses; }
  10845. + VM_RedefineClasses(jint class_count, const jvmtiClassDefinition *class_defs, JvmtiClassLoadKind class_load_kind);
  10846. + virtual ~VM_RedefineClasses();
  10847. +
  10848. + bool check_arguments();
  10849. bool doit_prologue();
  10850. void doit();
  10851. void doit_epilogue();
  10852. + void rollback();
  10853. +
  10854. + jvmtiError check_exception() const;
  10855. + VMOp_Type type() const { return VMOp_RedefineClasses; }
  10856. + bool skip_operation() const { return false; }
  10857. + bool allow_nested_vm_operations() const { return true; }
  10858. + jvmtiError check_error() { return _result; }
  10859. +
  10860. + void update_active_methods();
  10861. - bool allow_nested_vm_operations() const { return true; }
  10862. - jvmtiError check_error() { return _res; }
  10863. + // Checks for type consistency after hierarchy change
  10864. + bool check_type_consistency();
  10865. + void calculate_type_check_information();
  10866. + bool check_field_value_types();
  10867. + void clear_type_check_information();
  10868. + bool check_method_stacks();
  10869. + bool check_loaded_methods();
  10870. + bool check_method(methodOop method);
  10871. + static Symbol* signature_to_class_name(Symbol* signature);
  10872. +
  10873. + void method_forwarding();
  10874. +
  10875. + void update_array_classes_to_newest_version(klassOop smallest_dimension);
  10876. // Modifiable test must be shared between IsModifiableClass query
  10877. // and redefine implementation
  10878. static bool is_modifiable_class(oop klass_mirror);
  10879. +
  10880. + // Method used during garbage collection, the VM operation must iterate over all oops.
  10881. + void oops_do(OopClosure* f);
  10882. +
  10883. + // Utility methods for transferring field access flags
  10884. +
  10885. + static void transfer_special_access_flags(fieldDescriptor *from, fieldDescriptor *to);
  10886. + static void update_klass_field_access_flag(fieldDescriptor *fd);
  10887. +
  10888. + void transfer_old_native_function_registrations(instanceKlassHandle the_class);
  10889. +
  10890. + void lock_threads();
  10891. + void unlock_threads();
  10892. +
  10893. + template <class T> static void do_oop_work(T* p);
  10894. +
  10895. + static void swap_marks(oop first, oop second);
  10896. +
  10897. };
  10898. #endif // SHARE_VM_PRIMS_JVMTIREDEFINECLASSES_HPP
  10899. diff --git a/src/share/vm/prims/methodComparator.cpp b/src/share/vm/prims/methodComparator.cpp
  10900. index 60eaf97..07bb6e3 100644
  10901. --- a/src/share/vm/prims/methodComparator.cpp
  10902. +++ b/src/share/vm/prims/methodComparator.cpp
  10903. @@ -65,6 +65,7 @@ bool MethodComparator::methods_EMCP(methodOop old_method, methodOop new_method)
  10904. if (! args_same(c_old, c_new))
  10905. return false;
  10906. }
  10907. +
  10908. return true;
  10909. }
  10910. diff --git a/src/share/vm/prims/nativeLookup.cpp b/src/share/vm/prims/nativeLookup.cpp
  10911. index 41fc42d..53b3e0c 100644
  10912. --- a/src/share/vm/prims/nativeLookup.cpp
  10913. +++ b/src/share/vm/prims/nativeLookup.cpp
  10914. @@ -35,6 +35,7 @@
  10915. #include "oops/symbol.hpp"
  10916. #include "prims/jvm_misc.hpp"
  10917. #include "prims/nativeLookup.hpp"
  10918. +#include "prims/jvmtiRedefineClasses.hpp"
  10919. #include "runtime/arguments.hpp"
  10920. #include "runtime/handles.inline.hpp"
  10921. #include "runtime/javaCalls.hpp"
  10922. @@ -53,7 +54,6 @@
  10923. # include "os_bsd.inline.hpp"
  10924. #endif
  10925. -
  10926. static void mangle_name_on(outputStream* st, Symbol* name, int begin, int end) {
  10927. char* bytes = (char*)name->bytes() + begin;
  10928. char* end_bytes = (char*)name->bytes() + end;
  10929. @@ -138,6 +138,40 @@ static JNINativeMethod lookup_special_native_methods[] = {
  10930. { CC"Java_sun_hotspot_WhiteBox_registerNatives", NULL, FN_PTR(JVM_RegisterWhiteBoxMethods) },
  10931. };
  10932. +// Helper function to call redefineClasses from Java Code
  10933. +JVM_ENTRY(int, JVM_RedefineClassesHelper(JNIEnv *env, jclass cb, jclass target, jbyteArray bytes))
  10934. + ResourceMark rm(THREAD);
  10935. +
  10936. + JavaThread* current_thread = JavaThread::current();
  10937. + jbyte* bytecodes = NULL;
  10938. + const int class_count = 1;
  10939. + jvmtiClassDefinition* class_definitions = NEW_RESOURCE_ARRAY(jvmtiClassDefinition, class_count);
  10940. +
  10941. + {
  10942. + ThreadToNativeFromVM ttnfv(thread);
  10943. + jboolean is_copy = JNI_FALSE;
  10944. + bytecodes = env->GetByteArrayElements(bytes, &is_copy);
  10945. + class_definitions[0].klass = target;
  10946. + class_definitions[0].class_byte_count = env->GetArrayLength(bytes);
  10947. + class_definitions[0].class_bytes = (unsigned char*)bytecodes;
  10948. + }
  10949. +
  10950. + VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_retransform);
  10951. + VMThread::execute(&op);
  10952. + int result = op.check_error();
  10953. +
  10954. + {
  10955. + ThreadToNativeFromVM ttnfv(thread);
  10956. + if (env->ExceptionOccurred()) {
  10957. + return -1;
  10958. + }
  10959. + env->ReleaseByteArrayElements(bytes, bytecodes, 0);
  10960. + }
  10961. +
  10962. + return result;
  10963. +JVM_END
  10964. +
  10965. +
  10966. static address lookup_special_native(char* jni_name) {
  10967. int i = !JDK_Version::is_gte_jdk14x_version() ? 0 : 2; // see comment in lookup_special_native_methods
  10968. int count = sizeof(lookup_special_native_methods) / sizeof(JNINativeMethod);
  10969. @@ -177,6 +211,9 @@ address NativeLookup::lookup_style(methodHandle method, char* pure_name, const c
  10970. return entry;
  10971. }
  10972. }
  10973. + if(strstr(jni_name, "Java_at_ssw_hotswap_ClassRedefinition_redefineClasses") != NULL) {
  10974. + return CAST_FROM_FN_PTR(address, JVM_RedefineClassesHelper);
  10975. + }
  10976. // Otherwise call static method findNative in ClassLoader
  10977. KlassHandle klass (THREAD, SystemDictionary::ClassLoader_klass());
  10978. diff --git a/src/share/vm/runtime/arguments.cpp b/src/share/vm/runtime/arguments.cpp
  10979. index ec79354..541bf0f 100644
  10980. --- a/src/share/vm/runtime/arguments.cpp
  10981. +++ b/src/share/vm/runtime/arguments.cpp
  10982. @@ -1831,6 +1831,15 @@ bool Arguments::check_gc_consistency() {
  10983. status = false;
  10984. }
  10985. + // (tw) Must use serial GC
  10986. + if (!UseSerialGC && i >= 1) {
  10987. + jio_fprintf(defaultStream::error_stream(),
  10988. + "Must use the serial GC in the Dynamic Code Evolution VM\n");
  10989. + status = false;
  10990. + } else {
  10991. + UseSerialGC = true;
  10992. + }
  10993. +
  10994. return status;
  10995. }
  10996. diff --git a/src/share/vm/runtime/deoptimization.cpp b/src/share/vm/runtime/deoptimization.cpp
  10997. index 2b767d4..e9b6f47 100644
  10998. --- a/src/share/vm/runtime/deoptimization.cpp
  10999. +++ b/src/share/vm/runtime/deoptimization.cpp
  11000. @@ -599,6 +599,38 @@ JRT_LEAF(BasicType, Deoptimization::unpack_frames(JavaThread* thread, int exec_m
  11001. // Cleanup thread deopt data
  11002. cleanup_deopt_info(thread, array);
  11003. + // (tw) Redefinition support: Check if we need to transfer method execution points to new versions
  11004. + {
  11005. + ResourceMark res_mark;
  11006. +
  11007. + // Verify that the just-unpacked frames match the interpreter's
  11008. + // notions of expression stack and locals
  11009. + vframeArray* cur_array = thread->vframe_array_last();
  11010. + RegisterMap rm(thread, false);
  11011. + rm.set_include_argument_oops(false);
  11012. + for (int i = 0; i < cur_array->frames(); i++) {
  11013. + vframeArrayElement* el = cur_array->element(i);
  11014. + frame* frame = el->iframe();
  11015. + guarantee(frame->is_interpreted_frame(), "Wrong frame type");
  11016. + RegisterMap reg_map(thread);
  11017. + vframe* vf = vframe::new_vframe(frame, &reg_map, thread);
  11018. + interpretedVFrame *iframe = (interpretedVFrame *)vf;
  11019. + methodOop method = iframe->method();
  11020. + int bci = iframe->bci();
  11021. + method = method->newest_version();
  11022. + iframe->set_method(method, bci);
  11023. +
  11024. + methodOop forward_method = method->forward_method();
  11025. + if (forward_method != NULL && method->is_in_code_section(bci)) {
  11026. + int new_bci = method->calculate_forward_bci(bci, forward_method);
  11027. + if (TraceRedefineClasses >= 2) {
  11028. + 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);
  11029. + }
  11030. + iframe->set_method(forward_method, new_bci);
  11031. + }
  11032. + }
  11033. + }
  11034. +
  11035. #ifndef PRODUCT
  11036. if (VerifyStack) {
  11037. ResourceMark res_mark;
  11038. diff --git a/src/share/vm/runtime/frame.cpp b/src/share/vm/runtime/frame.cpp
  11039. index aacd835..3772b3f 100644
  11040. --- a/src/share/vm/runtime/frame.cpp
  11041. +++ b/src/share/vm/runtime/frame.cpp
  11042. @@ -408,6 +408,12 @@ void frame::interpreter_frame_set_method(methodOop method) {
  11043. *interpreter_frame_method_addr() = method;
  11044. }
  11045. +// (tw) Sets constant pool cache oop
  11046. +void frame::interpreter_frame_set_cache(constantPoolCacheOop cp) {
  11047. + assert(is_interpreted_frame(), "interpreted frame expected");
  11048. + *interpreter_frame_cache_addr() = cp;
  11049. +}
  11050. +
  11051. void frame::interpreter_frame_set_bcx(intptr_t bcx) {
  11052. assert(is_interpreted_frame(), "Not an interpreted frame");
  11053. if (ProfileInterpreter) {
  11054. @@ -423,19 +429,27 @@ void frame::interpreter_frame_set_bcx(intptr_t bcx) {
  11055. // The bcx was just converted from bci to bcp.
  11056. // Convert the mdx in parallel.
  11057. methodDataOop mdo = interpreter_frame_method()->method_data();
  11058. - assert(mdo != NULL, "");
  11059. - int mdi = mdx - 1; // We distinguish valid mdi from zero by adding one.
  11060. - address mdp = mdo->di_to_dp(mdi);
  11061. - interpreter_frame_set_mdx((intptr_t)mdp);
  11062. + if (mdo == NULL) {
  11063. + interpreter_frame_set_mdx(0);
  11064. + } else {
  11065. + assert(mdo != NULL, "");
  11066. + int mdi = mdx - 1; // We distinguish valid mdi from zero by adding one.
  11067. + address mdp = mdo->di_to_dp(mdi);
  11068. + interpreter_frame_set_mdx((intptr_t)mdp);
  11069. + }
  11070. }
  11071. } else {
  11072. if (is_now_bci) {
  11073. // The bcx was just converted from bcp to bci.
  11074. // Convert the mdx in parallel.
  11075. methodDataOop mdo = interpreter_frame_method()->method_data();
  11076. - assert(mdo != NULL, "");
  11077. - int mdi = mdo->dp_to_di((address)mdx);
  11078. - interpreter_frame_set_mdx((intptr_t)mdi + 1); // distinguish valid from 0.
  11079. + if (mdo == NULL) {
  11080. + interpreter_frame_set_mdx(0);
  11081. + } else {
  11082. + assert(mdo != NULL, "");
  11083. + int mdi = mdo->dp_to_di((address)mdx);
  11084. + interpreter_frame_set_mdx((intptr_t)mdi + 1); // distinguish valid from 0.
  11085. + }
  11086. }
  11087. }
  11088. }
  11089. diff --git a/src/share/vm/runtime/frame.hpp b/src/share/vm/runtime/frame.hpp
  11090. index 9c7bb72..04a6595 100644
  11091. --- a/src/share/vm/runtime/frame.hpp
  11092. +++ b/src/share/vm/runtime/frame.hpp
  11093. @@ -346,6 +346,7 @@ class frame VALUE_OBJ_CLASS_SPEC {
  11094. // Method & constant pool cache
  11095. methodOop interpreter_frame_method() const;
  11096. void interpreter_frame_set_method(methodOop method);
  11097. + void interpreter_frame_set_cache(constantPoolCacheOop method);
  11098. methodOop* interpreter_frame_method_addr() const;
  11099. constantPoolCacheOop* interpreter_frame_cache_addr() const;
  11100. #ifdef PPC
  11101. diff --git a/src/share/vm/runtime/globals.hpp b/src/share/vm/runtime/globals.hpp
  11102. index b0179c2..a4e9bd9 100644
  11103. --- a/src/share/vm/runtime/globals.hpp
  11104. +++ b/src/share/vm/runtime/globals.hpp
  11105. @@ -1229,9 +1229,23 @@ class CommandLineFlags {
  11106. product(bool, StressLdcRewrite, false, \
  11107. "Force ldc -> ldc_w rewrite during RedefineClasses") \
  11108. \
  11109. + product(bool, UseMethodForwardPoints, false, \
  11110. + "Use method forward points") \
  11111. + \
  11112. + product(intx, MethodForwardPointsMaxLocals, 300, \
  11113. + "Maximum number of locals in forwarding method") \
  11114. + \
  11115. + product(intx, MethodForwardPointsMaxStack, 300, \
  11116. + "Maximum number of stack slots in forwarding method") \
  11117. + \
  11118. product(intx, TraceRedefineClasses, 0, \
  11119. "Trace level for JVMTI RedefineClasses") \
  11120. \
  11121. + product(bool, TimeRedefineClasses, false, \
  11122. + "Measure timing for JVMTI RedefineClasses") \
  11123. + \
  11124. + product(bool, AllowAdvancedClassRedefinition, true, \
  11125. + "Allow advanced class redefinition beyond swapping method bodies")\
  11126. develop(bool, StressMethodComparator, false, \
  11127. "run the MethodComparator on all loaded methods") \
  11128. \
  11129. diff --git a/src/share/vm/runtime/interfaceSupport.hpp b/src/share/vm/runtime/interfaceSupport.hpp
  11130. index 2875ee0..61fd8fe 100644
  11131. --- a/src/share/vm/runtime/interfaceSupport.hpp
  11132. +++ b/src/share/vm/runtime/interfaceSupport.hpp
  11133. @@ -296,7 +296,7 @@ class ThreadToNativeFromVM : public ThreadStateTransition {
  11134. ThreadToNativeFromVM(JavaThread *thread) : ThreadStateTransition(thread) {
  11135. // We are leaving the VM at this point and going directly to native code.
  11136. // Block, if we are in the middle of a safepoint synchronization.
  11137. - assert(!thread->owns_locks(), "must release all locks when leaving VM");
  11138. + assert(!thread->owns_locks_but_redefine_classes_lock(), "must release all locks when leaving VM");
  11139. thread->frame_anchor()->make_walkable(thread);
  11140. trans_and_fence(_thread_in_vm, _thread_in_native);
  11141. // Check for pending. async. exceptions or suspends.
  11142. diff --git a/src/share/vm/runtime/javaCalls.cpp b/src/share/vm/runtime/javaCalls.cpp
  11143. index edbba98..4a27925 100644
  11144. --- a/src/share/vm/runtime/javaCalls.cpp
  11145. +++ b/src/share/vm/runtime/javaCalls.cpp
  11146. @@ -60,7 +60,7 @@ JavaCallWrapper::JavaCallWrapper(methodHandle callee_method, Handle receiver, Ja
  11147. bool clear_pending_exception = true;
  11148. guarantee(thread->is_Java_thread(), "crucial check - the VM thread cannot and must not escape to Java code");
  11149. - assert(!thread->owns_locks(), "must release all locks when leaving VM");
  11150. + assert(!thread->owns_locks_but_redefine_classes_lock(), "must release all locks when leaving VM");
  11151. guarantee(!thread->is_Compiler_thread(), "cannot make java calls from the compiler");
  11152. _result = result;
  11153. diff --git a/src/share/vm/runtime/jniHandles.cpp b/src/share/vm/runtime/jniHandles.cpp
  11154. index 3cbcaca..30839d7 100644
  11155. --- a/src/share/vm/runtime/jniHandles.cpp
  11156. +++ b/src/share/vm/runtime/jniHandles.cpp
  11157. @@ -112,6 +112,10 @@ jobject JNIHandles::make_weak_global(Handle obj) {
  11158. }
  11159. jmethodID JNIHandles::make_jmethod_id(methodHandle mh) {
  11160. + if (mh->newest_version() != mh()) {
  11161. + methodHandle mh_new(Thread::current(), mh()->newest_version());
  11162. + return (jmethodID) make_weak_global(mh_new);
  11163. + }
  11164. return (jmethodID) make_weak_global(mh);
  11165. }
  11166. diff --git a/src/share/vm/runtime/mutex.cpp b/src/share/vm/runtime/mutex.cpp
  11167. index 2095237..c541434 100644
  11168. --- a/src/share/vm/runtime/mutex.cpp
  11169. +++ b/src/share/vm/runtime/mutex.cpp
  11170. @@ -1227,7 +1227,7 @@ Monitor * Monitor::get_least_ranked_lock(Monitor * locks) {
  11171. // in increasing rank order (modulo any native ranks)
  11172. for (tmp = locks; tmp != NULL; tmp = tmp->next()) {
  11173. if (tmp->next() != NULL) {
  11174. - assert(tmp->rank() == Mutex::native ||
  11175. + assert(tmp->rank() == Mutex::native || tmp->rank() == Mutex::redefine_classes ||
  11176. tmp->rank() <= tmp->next()->rank(), "mutex rank anomaly?");
  11177. }
  11178. }
  11179. @@ -1247,7 +1247,7 @@ Monitor* Monitor::get_least_ranked_lock_besides_this(Monitor* locks) {
  11180. // in increasing rank order (modulo any native ranks)
  11181. for (tmp = locks; tmp != NULL; tmp = tmp->next()) {
  11182. if (tmp->next() != NULL) {
  11183. - assert(tmp->rank() == Mutex::native ||
  11184. + assert(tmp->rank() == Mutex::native || tmp->rank() == Mutex::redefine_classes ||
  11185. tmp->rank() <= tmp->next()->rank(), "mutex rank anomaly?");
  11186. }
  11187. }
  11188. @@ -1310,6 +1310,7 @@ void Monitor::set_owner_implementation(Thread *new_owner) {
  11189. // already hold Terminator_lock - may happen because of periodic safepoints
  11190. if (this->rank() != Mutex::native &&
  11191. this->rank() != Mutex::suspend_resume &&
  11192. + this->rank() != Mutex::redefine_classes &&
  11193. locks != NULL && locks->rank() <= this->rank() &&
  11194. !SafepointSynchronize::is_at_safepoint() &&
  11195. this != Interrupt_lock &&
  11196. diff --git a/src/share/vm/runtime/mutex.hpp b/src/share/vm/runtime/mutex.hpp
  11197. index 7d2cd82..11eb32e 100644
  11198. --- a/src/share/vm/runtime/mutex.hpp
  11199. +++ b/src/share/vm/runtime/mutex.hpp
  11200. @@ -109,7 +109,8 @@ class Monitor : public CHeapObj<mtInternal> {
  11201. barrier = safepoint + 1,
  11202. nonleaf = barrier + 1,
  11203. max_nonleaf = nonleaf + 900,
  11204. - native = max_nonleaf + 1
  11205. + native = max_nonleaf + 1,
  11206. + redefine_classes = native + 1
  11207. };
  11208. // The WaitSet and EntryList linked lists are composed of ParkEvents.
  11209. diff --git a/src/share/vm/runtime/mutexLocker.cpp b/src/share/vm/runtime/mutexLocker.cpp
  11210. index 77fddef..9d453d4 100644
  11211. --- a/src/share/vm/runtime/mutexLocker.cpp
  11212. +++ b/src/share/vm/runtime/mutexLocker.cpp
  11213. @@ -49,6 +49,7 @@
  11214. // Consider using GCC's __read_mostly.
  11215. Mutex* Patching_lock = NULL;
  11216. +Mutex* RedefineClasses_lock = NULL;
  11217. Monitor* SystemDictionary_lock = NULL;
  11218. Mutex* PackageTable_lock = NULL;
  11219. Mutex* CompiledIC_lock = NULL;
  11220. @@ -91,6 +92,7 @@ Mutex* Shared_SATB_Q_lock = NULL;
  11221. Mutex* DirtyCardQ_FL_lock = NULL;
  11222. Monitor* DirtyCardQ_CBL_mon = NULL;
  11223. Mutex* Shared_DirtyCardQ_lock = NULL;
  11224. +Monitor* RedefinitionSync_lock = NULL;
  11225. Mutex* ParGCRareEvent_lock = NULL;
  11226. Mutex* EvacFailureStack_lock = NULL;
  11227. Mutex* DerivedPointerTableGC_lock = NULL;
  11228. @@ -208,6 +210,7 @@ void mutex_init() {
  11229. def(HotCardCache_lock , Mutex , special , true );
  11230. def(EvacFailureStack_lock , Mutex , nonleaf , true );
  11231. }
  11232. + def(RedefinitionSync_lock , Monitor , leaf , false );
  11233. def(ParGCRareEvent_lock , Mutex , leaf , true );
  11234. def(DerivedPointerTableGC_lock , Mutex, leaf, true );
  11235. def(CodeCache_lock , Mutex , special, true );
  11236. @@ -283,6 +286,7 @@ void mutex_init() {
  11237. def(Debug3_lock , Mutex , nonleaf+4, true );
  11238. def(CompileThread_lock , Monitor, nonleaf+5, false);
  11239. def(PeriodicTask_lock , Monitor, nonleaf+5, true);
  11240. + def(RedefineClasses_lock , Mutex , nonleaf+7, false ); // for ensuring that class redefinition is not done in parallel
  11241. #ifdef INCLUDE_TRACE
  11242. def(JfrMsg_lock , Monitor, leaf, true);
  11243. diff --git a/src/share/vm/runtime/mutexLocker.hpp b/src/share/vm/runtime/mutexLocker.hpp
  11244. index a6549b1..089ed11 100644
  11245. --- a/src/share/vm/runtime/mutexLocker.hpp
  11246. +++ b/src/share/vm/runtime/mutexLocker.hpp
  11247. @@ -43,6 +43,8 @@
  11248. // Mutexes used in the VM.
  11249. extern Mutex* Patching_lock; // a lock used to guard code patching of compiled code
  11250. +extern Monitor* RedefinitionSync_lock; // a lock on synchronized class redefinition
  11251. +extern Mutex* RedefineClasses_lock; // a lock on class redefinition
  11252. extern Monitor* SystemDictionary_lock; // a lock on the system dictonary
  11253. extern Mutex* PackageTable_lock; // a lock on the class loader package table
  11254. extern Mutex* CompiledIC_lock; // a lock used to guard compiled IC patching and access
  11255. diff --git a/src/share/vm/runtime/reflection.cpp b/src/share/vm/runtime/reflection.cpp
  11256. index 1665d93..6baabba 100644
  11257. --- a/src/share/vm/runtime/reflection.cpp
  11258. +++ b/src/share/vm/runtime/reflection.cpp
  11259. @@ -468,7 +468,8 @@ bool Reflection::verify_class_access(klassOop current_class, klassOop new_class,
  11260. // sun/reflect/MagicAccessorImpl subclasses to succeed trivially.
  11261. if ( JDK_Version::is_gte_jdk14x_version()
  11262. && UseNewReflection
  11263. - && Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass())) {
  11264. + && (Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()) ||
  11265. + Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()->klass_part()->newest_version()))) {
  11266. return true;
  11267. }
  11268. @@ -519,6 +520,12 @@ bool Reflection::verify_field_access(klassOop current_class,
  11269. AccessFlags access,
  11270. bool classloader_only,
  11271. bool protected_restriction) {
  11272. +
  11273. + // (tw) Decide accessibility based on active version
  11274. + if (current_class != NULL) {
  11275. + current_class = current_class->klass_part()->active_version();
  11276. + }
  11277. +
  11278. // Verify that current_class can access a field of field_class, where that
  11279. // field's access bits are "access". We assume that we've already verified
  11280. // that current_class can access field_class.
  11281. @@ -560,7 +567,8 @@ bool Reflection::verify_field_access(klassOop current_class,
  11282. // sun/reflect/MagicAccessorImpl subclasses to succeed trivially.
  11283. if ( JDK_Version::is_gte_jdk14x_version()
  11284. && UseNewReflection
  11285. - && Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass())) {
  11286. + && (Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()) ||
  11287. + Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()->klass_part()->newest_version()))) {
  11288. return true;
  11289. }
  11290. diff --git a/src/share/vm/runtime/sharedRuntime.cpp b/src/share/vm/runtime/sharedRuntime.cpp
  11291. index 709d783..e0e19b1 100644
  11292. --- a/src/share/vm/runtime/sharedRuntime.cpp
  11293. +++ b/src/share/vm/runtime/sharedRuntime.cpp
  11294. @@ -1137,7 +1137,20 @@ methodHandle SharedRuntime::resolve_helper(JavaThread *thread,
  11295. if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
  11296. int retry_count = 0;
  11297. while (!HAS_PENDING_EXCEPTION && callee_method->is_old() &&
  11298. - callee_method->method_holder() != SystemDictionary::Object_klass()) {
  11299. + callee_method->method_holder()->klass_part()->newest_version() != SystemDictionary::Object_klass()->klass_part()->newest_version()) {
  11300. +
  11301. + // DCEVM: If we are executing an old method, this is OK!
  11302. + {
  11303. + ResourceMark rm(thread);
  11304. + RegisterMap cbl_map(thread, false);
  11305. + frame caller_frame = thread->last_frame().sender(&cbl_map);
  11306. +
  11307. + CodeBlob* caller_cb = caller_frame.cb();
  11308. + guarantee(caller_cb != NULL && caller_cb->is_nmethod(), "must be called from nmethod");
  11309. + nmethod* caller_nm = caller_cb->as_nmethod_or_null();
  11310. + if (caller_nm->method()->is_old()) break;
  11311. + }
  11312. +
  11313. // If has a pending exception then there is no need to re-try to
  11314. // resolve this method.
  11315. // If the method has been redefined, we need to try again.
  11316. diff --git a/src/share/vm/runtime/thread.cpp b/src/share/vm/runtime/thread.cpp
  11317. index f3acf4d..ea61cae 100644
  11318. --- a/src/share/vm/runtime/thread.cpp
  11319. +++ b/src/share/vm/runtime/thread.cpp
  11320. @@ -216,6 +216,8 @@ Thread::Thread() {
  11321. set_self_raw_id(0);
  11322. set_lgrp_id(-1);
  11323. + _redefine_classes_mutex = new Mutex(Mutex::redefine_classes, "redefine classes lock", false);
  11324. +
  11325. // allocated data structures
  11326. set_osthread(NULL);
  11327. set_resource_area(new (mtThread)ResourceArea());
  11328. @@ -249,6 +251,7 @@ Thread::Thread() {
  11329. omFreeProvision = 32 ;
  11330. omInUseList = NULL ;
  11331. omInUseCount = 0 ;
  11332. + _pretend_new_universe = false;
  11333. #ifdef ASSERT
  11334. _visited_for_critical_count = false;
  11335. @@ -884,6 +887,15 @@ bool Thread::owns_locks_but_compiled_lock() const {
  11336. return false;
  11337. }
  11338. +bool Thread::owns_locks_but_redefine_classes_lock() const {
  11339. + for(Monitor *cur = _owned_locks; cur; cur = cur->next()) {
  11340. + if (cur != RedefineClasses_lock && cur->rank() != Mutex::redefine_classes) {
  11341. + return true;
  11342. + }
  11343. + }
  11344. + return false;
  11345. +}
  11346. +
  11347. #endif
  11348. @@ -1637,7 +1649,7 @@ void JavaThread::run() {
  11349. ThreadStateTransition::transition_and_fence(this, _thread_new, _thread_in_vm);
  11350. assert(JavaThread::current() == this, "sanity check");
  11351. - assert(!Thread::current()->owns_locks(), "sanity check");
  11352. + assert(!Thread::current()->owns_locks_but_redefine_classes_lock(), "sanity check");
  11353. DTRACE_THREAD_PROBE(start, this);
  11354. @@ -3193,7 +3205,7 @@ static void compiler_thread_entry(JavaThread* thread, TRAPS) {
  11355. // Create a CompilerThread
  11356. CompilerThread::CompilerThread(CompileQueue* queue, CompilerCounters* counters)
  11357. -: JavaThread(&compiler_thread_entry) {
  11358. +: JavaThread(&compiler_thread_entry), _should_bailout(false) {
  11359. _env = NULL;
  11360. _log = NULL;
  11361. _task = NULL;
  11362. @@ -3201,6 +3213,7 @@ CompilerThread::CompilerThread(CompileQueue* queue, CompilerCounters* counters)
  11363. _counters = counters;
  11364. _buffer_blob = NULL;
  11365. _scanned_nmethod = NULL;
  11366. + _compilation_mutex = new Mutex(Mutex::redefine_classes, "compilationMutex", false);
  11367. #ifndef PRODUCT
  11368. _ideal_graph_printer = NULL;
  11369. @@ -3230,6 +3243,7 @@ int Threads::_number_of_threads = 0;
  11370. int Threads::_number_of_non_daemon_threads = 0;
  11371. int Threads::_return_code = 0;
  11372. size_t JavaThread::_stack_size_at_create = 0;
  11373. +bool Threads::_wait_at_instrumentation_entry = false;
  11374. // All JavaThreads
  11375. #define ALL_JAVA_THREADS(X) for (JavaThread* X = _thread_list; X; X = X->next())
  11376. diff --git a/src/share/vm/runtime/thread.hpp b/src/share/vm/runtime/thread.hpp
  11377. index 774bd27..4ca4502 100644
  11378. --- a/src/share/vm/runtime/thread.hpp
  11379. +++ b/src/share/vm/runtime/thread.hpp
  11380. @@ -203,11 +203,14 @@ class Thread: public ThreadShadow {
  11381. void enter_signal_handler() { _num_nested_signal++; }
  11382. void leave_signal_handler() { _num_nested_signal--; }
  11383. bool is_inside_signal_handler() const { return _num_nested_signal > 0; }
  11384. + Mutex* redefine_classes_mutex() { return _redefine_classes_mutex; }
  11385. private:
  11386. // Debug tracing
  11387. static void trace(const char* msg, const Thread* const thread) PRODUCT_RETURN;
  11388. + Mutex* _redefine_classes_mutex;
  11389. +
  11390. // Active_handles points to a block of handles
  11391. JNIHandleBlock* _active_handles;
  11392. @@ -530,10 +533,15 @@ public:
  11393. uintptr_t _self_raw_id; // used by get_thread (mutable)
  11394. int _lgrp_id;
  11395. +
  11396. + bool _pretend_new_universe;
  11397. +
  11398. public:
  11399. // Stack overflow support
  11400. address stack_base() const { assert(_stack_base != NULL,"Sanity check"); return _stack_base; }
  11401. + 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; } }
  11402. + bool pretend_new_universe() { return _pretend_new_universe; }
  11403. void set_stack_base(address base) { _stack_base = base; }
  11404. size_t stack_size() const { return _stack_size; }
  11405. void set_stack_size(size_t size) { _stack_size = size; }
  11406. @@ -570,6 +578,7 @@ public:
  11407. void print_owned_locks() const { print_owned_locks_on(tty); }
  11408. Monitor* owned_locks() const { return _owned_locks; }
  11409. bool owns_locks() const { return owned_locks() != NULL; }
  11410. + bool owns_locks_but_redefine_classes_lock() const;
  11411. bool owns_locks_but_compiled_lock() const;
  11412. // Deadlock detection
  11413. @@ -1793,6 +1802,8 @@ class CompilerThread : public JavaThread {
  11414. CompileTask* _task;
  11415. CompileQueue* _queue;
  11416. BufferBlob* _buffer_blob;
  11417. + bool _should_bailout;
  11418. + Mutex* _compilation_mutex;
  11419. nmethod* _scanned_nmethod; // nmethod being scanned by the sweeper
  11420. @@ -1802,12 +1813,16 @@ class CompilerThread : public JavaThread {
  11421. CompilerThread(CompileQueue* queue, CompilerCounters* counters);
  11422. + bool should_bailout() const { return _should_bailout; }
  11423. + void set_should_bailout(bool b) { _should_bailout = false; }
  11424. +
  11425. bool is_Compiler_thread() const { return true; }
  11426. // Hide this compiler thread from external view.
  11427. bool is_hidden_from_external_view() const { return true; }
  11428. CompileQueue* queue() { return _queue; }
  11429. CompilerCounters* counters() { return _counters; }
  11430. + Mutex *compilation_mutex() { return _compilation_mutex; }
  11431. // Get/set the thread's compilation environment.
  11432. ciEnv* env() { return _env; }
  11433. @@ -1862,6 +1877,7 @@ class Threads: AllStatic {
  11434. static int _number_of_threads;
  11435. static int _number_of_non_daemon_threads;
  11436. static int _return_code;
  11437. + static bool _wait_at_instrumentation_entry;
  11438. public:
  11439. // Thread management
  11440. @@ -1873,6 +1889,9 @@ class Threads: AllStatic {
  11441. static JavaThread* first() { return _thread_list; }
  11442. static void threads_do(ThreadClosure* tc);
  11443. + static bool wait_at_instrumentation_entry() { return _wait_at_instrumentation_entry; }
  11444. + static void set_wait_at_instrumentation_entry(bool b) { _wait_at_instrumentation_entry = b; }
  11445. +
  11446. // Initializes the vm and creates the vm thread
  11447. static jint create_vm(JavaVMInitArgs* args, bool* canTryAgain);
  11448. static void convert_vm_init_libraries_to_agents();
  11449. diff --git a/src/share/vm/runtime/vframe.cpp b/src/share/vm/runtime/vframe.cpp
  11450. index 09e324f..d47ffef 100644
  11451. --- a/src/share/vm/runtime/vframe.cpp
  11452. +++ b/src/share/vm/runtime/vframe.cpp
  11453. @@ -253,6 +253,46 @@ methodOop interpretedVFrame::method() const {
  11454. return fr().interpreter_frame_method();
  11455. }
  11456. +// (tw) Sets interpreter frame method.
  11457. +void interpretedVFrame::set_method(methodOop new_method, int new_bci) {
  11458. + methodOop old_method = fr().interpreter_frame_method();
  11459. + int old_stack_size = fr().interpreter_frame_expression_stack_size();
  11460. + if (old_method == new_method) return;
  11461. + u_char *old_bcp = bcp();
  11462. + int old_bci = bci();
  11463. + fr().interpreter_frame_set_method(new_method);
  11464. + fr().interpreter_frame_set_cache(new_method->constants()->cache());
  11465. + u_char *new_bcp = new_method->code_base() + new_bci;
  11466. + assert(new_method->bcp_from(new_bci) == new_bcp, "");
  11467. +
  11468. + set_bcp(new_bcp);
  11469. +
  11470. + Bytecodes::Code code = Bytecodes::java_code_at(old_method, old_bcp);
  11471. + assert(Bytecodes::java_code_at(new_method, new_bcp) == code, "must have same bytecode at this position");
  11472. +
  11473. + switch (code) {
  11474. + case Bytecodes::_invokevirtual :
  11475. + case Bytecodes::_invokespecial :
  11476. + case Bytecodes::_invokestatic :
  11477. + case Bytecodes::_invokeinterface: {
  11478. + int old_index = Bytes::get_native_u2(old_bcp+1);
  11479. + int new_index = Bytes::get_native_u2(new_bcp+1);
  11480. + new_method->constants()->cache()->entry_at(new_index)->copy_from(old_method->constants()->cache()->entry_at(old_index));
  11481. + break;
  11482. + }
  11483. +
  11484. + case Bytecodes::_invokedynamic: {
  11485. + int old_index = Bytes::get_native_u4(old_bcp+1);
  11486. + int new_index = Bytes::get_native_u4(new_bcp+1);
  11487. + new_method->constants()->cache()->secondary_entry_at(new_index)->copy_from(old_method->constants()->cache()->secondary_entry_at(old_index));
  11488. + break;
  11489. + }
  11490. + }
  11491. +
  11492. + int new_stack_size = fr().interpreter_frame_expression_stack_size();
  11493. + assert(new_method->validate_bci_from_bcx((intptr_t)new_bcp) == new_bci, "");
  11494. +}
  11495. +
  11496. StackValueCollection* interpretedVFrame::locals() const {
  11497. int length = method()->max_locals();
  11498. diff --git a/src/share/vm/runtime/vframe.hpp b/src/share/vm/runtime/vframe.hpp
  11499. index badfea5..edbc5c7 100644
  11500. --- a/src/share/vm/runtime/vframe.hpp
  11501. +++ b/src/share/vm/runtime/vframe.hpp
  11502. @@ -163,6 +163,7 @@ class interpretedVFrame: public javaVFrame {
  11503. StackValueCollection* locals() const;
  11504. StackValueCollection* expressions() const;
  11505. GrowableArray<MonitorInfo*>* monitors() const;
  11506. + void set_method(methodOop method, int new_bci);
  11507. void set_locals(StackValueCollection* values) const;
  11508. diff --git a/src/share/vm/runtime/vmThread.cpp b/src/share/vm/runtime/vmThread.cpp
  11509. index 5ddcf26..213e678 100644
  11510. --- a/src/share/vm/runtime/vmThread.cpp
  11511. +++ b/src/share/vm/runtime/vmThread.cpp
  11512. @@ -691,6 +691,10 @@ void VMThread::execute(VM_Operation* op) {
  11513. void VMThread::oops_do(OopClosure* f, CodeBlobClosure* cf) {
  11514. Thread::oops_do(f, cf);
  11515. _vm_queue->oops_do(f);
  11516. + // (DCEVM) need to update oops in VM_RedefineClasses!
  11517. + if (_cur_vm_operation != NULL) {
  11518. + _cur_vm_operation->oops_do(f);
  11519. + }
  11520. }
  11521. //------------------------------------------------------------------------------------------------------------------
  11522. diff --git a/src/share/vm/utilities/exceptions.cpp b/src/share/vm/utilities/exceptions.cpp
  11523. index 03f254d..c9e0efc 100644
  11524. --- a/src/share/vm/utilities/exceptions.cpp
  11525. +++ b/src/share/vm/utilities/exceptions.cpp
  11526. @@ -254,6 +254,8 @@ Handle Exceptions::new_exception(Thread *thread, Symbol* name,
  11527. assert(thread->is_Java_thread(), "can only be called by a Java thread");
  11528. assert(!thread->has_pending_exception(), "already has exception");
  11529. + bool old_pretend_value = Thread::current()->pretend_new_universe();
  11530. + Thread::current()->set_pretend_new_universe(false);
  11531. Handle h_exception;
  11532. // Resolve exception klass
  11533. @@ -285,6 +287,7 @@ Handle Exceptions::new_exception(Thread *thread, Symbol* name,
  11534. h_exception = Handle(thread, thread->pending_exception());
  11535. thread->clear_pending_exception();
  11536. }
  11537. + Thread::current()->set_pretend_new_universe(old_pretend_value);
  11538. return h_exception;
  11539. }
  11540. @@ -295,6 +298,8 @@ Handle Exceptions::new_exception(Thread *thread, Symbol* name,
  11541. Symbol* signature, JavaCallArguments *args,
  11542. Handle h_cause,
  11543. Handle h_loader, Handle h_protection_domain) {
  11544. + bool old_pretend_value = Thread::current()->pretend_new_universe();
  11545. + Thread::current()->set_pretend_new_universe(false);
  11546. Handle h_exception = new_exception(thread, name, signature, args, h_loader, h_protection_domain);
  11547. // Future: object initializer should take a cause argument
  11548. @@ -317,6 +322,8 @@ Handle Exceptions::new_exception(Thread *thread, Symbol* name,
  11549. h_exception = Handle(thread, thread->pending_exception());
  11550. thread->clear_pending_exception();
  11551. }
  11552. +
  11553. + Thread::current()->set_pretend_new_universe(old_pretend_value);
  11554. return h_exception;
  11555. }
  11556. diff --git a/src/share/vm/utilities/growableArray.hpp b/src/share/vm/utilities/growableArray.hpp
  11557. index ea92a80..05e940e 100644
  11558. --- a/src/share/vm/utilities/growableArray.hpp
  11559. +++ b/src/share/vm/utilities/growableArray.hpp
  11560. @@ -145,6 +145,33 @@ class GenericGrowableArray : public ResourceObj {
  11561. assert(on_stack(), "fast ResourceObj path only");
  11562. return (void*)resource_allocate_bytes(thread, elementSize * _max);
  11563. }
  11564. +
  11565. +};
  11566. +
  11567. +template<class E, class F> class Pair : public StackObj
  11568. +{
  11569. +private:
  11570. + E _left;
  11571. + F _right;
  11572. +
  11573. +public:
  11574. +
  11575. + Pair() {
  11576. +
  11577. + }
  11578. +
  11579. + Pair(E left, F right) {
  11580. + this->_left = left;
  11581. + this->_right = right;
  11582. + }
  11583. +
  11584. + E left() {
  11585. + return _left;
  11586. + }
  11587. +
  11588. + F right() {
  11589. + return _right;
  11590. + }
  11591. };
  11592. template<class E> class GrowableArray : public GenericGrowableArray {