Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

full-jdk7u79-b02.patch 504KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374
  1. diff --git a/make/bsd/makefiles/gcc.make b/make/bsd/makefiles/gcc.make
  2. index 3de1dea..8bf7f94 100644
  3. --- a/make/bsd/makefiles/gcc.make
  4. +++ b/make/bsd/makefiles/gcc.make
  5. @@ -117,7 +117,10 @@
  6. CFLAGS += -fno-rtti
  7. CFLAGS += -fno-exceptions
  8. CFLAGS += -pthread
  9. -CFLAGS += -fcheck-new
  10. +## well, strictly speaking we should check for clang not Darwin
  11. +ifneq ($(OS_VENDOR), Darwin)
  12. + CFLAGS += -fcheck-new
  13. +endif
  14. # version 4 and above support fvisibility=hidden (matches jni_x86.h file)
  15. # except 4.1.2 gives pointless warnings that can't be disabled (afaik)
  16. ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0"
  17. diff --git a/src/cpu/x86/vm/templateTable_x86_32.cpp b/src/cpu/x86/vm/templateTable_x86_32.cpp
  18. index fc19edc..d2cddd3 100644
  19. --- a/src/cpu/x86/vm/templateTable_x86_32.cpp
  20. +++ b/src/cpu/x86/vm/templateTable_x86_32.cpp
  21. @@ -2109,6 +2109,22 @@
  22. // resolve first time through
  23. address entry;
  24. switch (bytecode()) {
  25. + case Bytecodes::_fast_agetfield : // fall through
  26. + case Bytecodes::_fast_bgetfield : // fall through
  27. + case Bytecodes::_fast_cgetfield : // fall through
  28. + case Bytecodes::_fast_dgetfield : // fall through
  29. + case Bytecodes::_fast_fgetfield : // fall through
  30. + case Bytecodes::_fast_igetfield : // fall through
  31. + case Bytecodes::_fast_lgetfield : // fall through
  32. + case Bytecodes::_fast_sgetfield : // fall through
  33. + case Bytecodes::_fast_aputfield : // fall through
  34. + case Bytecodes::_fast_bputfield : // fall through
  35. + case Bytecodes::_fast_cputfield : // fall through
  36. + case Bytecodes::_fast_dputfield : // fall through
  37. + case Bytecodes::_fast_fputfield : // fall through
  38. + case Bytecodes::_fast_iputfield : // fall through
  39. + case Bytecodes::_fast_lputfield : // fall through
  40. + case Bytecodes::_fast_sputfield : // fall through
  41. case Bytecodes::_getstatic : // fall through
  42. case Bytecodes::_putstatic : // fall through
  43. case Bytecodes::_getfield : // fall through
  44. @@ -2211,6 +2227,7 @@
  45. // Correct values of the cache and index registers are preserved.
  46. void TemplateTable::jvmti_post_field_access(Register cache,
  47. Register index,
  48. + int byte_no,
  49. bool is_static,
  50. bool has_tos) {
  51. if (JvmtiExport::can_post_field_access()) {
  52. @@ -2237,7 +2254,11 @@
  53. // cache: cache entry pointer
  54. __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access),
  55. rax, cache);
  56. - __ get_cache_and_index_at_bcp(cache, index, 1);
  57. +
  58. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  59. + __ restore_bcp();
  60. + resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  61. +
  62. __ bind(L1);
  63. }
  64. }
  65. @@ -2258,7 +2279,7 @@
  66. const Register flags = rax;
  67. resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  68. - jvmti_post_field_access(cache, index, is_static, false);
  69. + jvmti_post_field_access(cache, index, byte_no, is_static, false);
  70. load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  71. if (!is_static) pop_and_check_object(obj);
  72. @@ -2393,7 +2414,7 @@
  73. // The registers cache and index expected to be set before call.
  74. // The function may destroy various registers, just not the cache and index registers.
  75. -void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is_static) {
  76. +void TemplateTable::jvmti_post_field_mod(Register cache, Register index, int byte_no, bool is_static) {
  77. ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();
  78. @@ -2451,7 +2472,11 @@
  79. // rcx: jvalue object on the stack
  80. __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification),
  81. rbx, rax, rcx);
  82. - __ get_cache_and_index_at_bcp(cache, index, 1);
  83. +
  84. + // (tw) Redefinition might have occured => reresolve the cp entry.
  85. + __ restore_bcp();
  86. + resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  87. +
  88. __ bind(L1);
  89. }
  90. }
  91. @@ -2467,7 +2492,7 @@
  92. const Register flags = rax;
  93. resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  94. - jvmti_post_field_mod(cache, index, is_static);
  95. + jvmti_post_field_mod(cache, index, byte_no, is_static);
  96. load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  97. // Doug Lea believes this is not needed with current Sparcs (TSO) and Intel (PSO).
  98. @@ -2818,6 +2843,11 @@
  99. // rcx: cache entry pointer
  100. __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access), rax, rcx);
  101. __ pop_ptr(rax); // restore object pointer
  102. +
  103. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  104. + __ restore_bcp();
  105. + resolve_cache_and_index(1, noreg, rax, rcx, sizeof(u2));
  106. +
  107. __ bind(L1);
  108. }
  109. @@ -3008,6 +3038,26 @@
  110. __ bind(notFinal);
  111. + // DCEVM: Check if we are calling an old method (and have to go slow path)
  112. + Label notOld;
  113. + __ movl(rax, flags);
  114. + __ andl(rax, (1 << ConstantPoolCacheEntry::is_old_method_shift));
  115. + __ jcc(Assembler::zero, notOld);
  116. +
  117. + // Need a null check here!
  118. + __ null_check(recv);
  119. +
  120. + // Call out to VM to do look up based on correct vTable version (has to iterate back over the class history of the receiver class)
  121. + // DCEVM: TODO: Check if we can improve performance by inlining.
  122. + // DCEVM: TODO: Check if this additional branch affects normal execution time.
  123. + __ call_VM(method, CAST_FROM_FN_PTR(address, InterpreterRuntime::find_correct_method), recv, index);
  124. +
  125. + // profile this call
  126. + __ profile_final_call(rax);
  127. + __ jump_from_interpreted(method, rdx);
  128. +
  129. + __ bind(notOld);
  130. +
  131. // get receiver klass
  132. __ null_check(recv, oopDesc::klass_offset_in_bytes());
  133. __ load_klass(rax, recv);
  134. @@ -3093,6 +3143,31 @@
  135. invokevirtual_helper(rbx, rcx, rdx);
  136. __ bind(notMethod);
  137. + // DCEVM: Check if we are calling an old method (and have to go slow path)
  138. + //__ movl(rax, rdx);
  139. + Label notOld;
  140. + __ andl(rdx, (1 << ConstantPoolCacheEntry::is_old_method_shift));
  141. + __ jcc(Assembler::zero, notOld);
  142. +
  143. + // Get receiver klass into rdx - also a null check
  144. + __ movptr(rdx, Address(rcx, oopDesc::klass_offset_in_bytes()));
  145. + __ verify_oop(rdx);
  146. +
  147. + // Call out to VM to do look up based on correct vTable version (has to iterate back over the class history of the receiver class)
  148. + // DCEVM: TODO: Check if we can improve performance by inlining.
  149. + // DCEVM: TODO: Check if this additional branch affects normal execution time.
  150. + // DCEVM: TODO: Check the exact semantic (with respect to destoying registers) of call_VM
  151. + __ call_VM(rbx, CAST_FROM_FN_PTR(address, InterpreterRuntime::find_correct_interface_method), rcx, rax, rbx);
  152. +
  153. + // DCEVM: TODO: Check if resolved method could be null.
  154. +
  155. + // profile this call
  156. + __ profile_virtual_call(rdx, rsi, rdi);
  157. +
  158. + __ jump_from_interpreted(rbx, rdx);
  159. +
  160. + __ bind(notOld);
  161. +
  162. // Get receiver klass into rdx - also a null check
  163. __ restore_locals(); // restore rdi
  164. __ null_check(rcx, oopDesc::klass_offset_in_bytes());
  165. diff --git a/src/cpu/x86/vm/templateTable_x86_64.cpp b/src/cpu/x86/vm/templateTable_x86_64.cpp
  166. index 932ee97..67bb710 100644
  167. --- a/src/cpu/x86/vm/templateTable_x86_64.cpp
  168. +++ b/src/cpu/x86/vm/templateTable_x86_64.cpp
  169. @@ -2151,6 +2151,22 @@
  170. // resolve first time through
  171. address entry;
  172. switch (bytecode()) {
  173. + case Bytecodes::_fast_agetfield : // fall through
  174. + case Bytecodes::_fast_bgetfield : // fall through
  175. + case Bytecodes::_fast_cgetfield : // fall through
  176. + case Bytecodes::_fast_dgetfield : // fall through
  177. + case Bytecodes::_fast_fgetfield : // fall through
  178. + case Bytecodes::_fast_igetfield : // fall through
  179. + case Bytecodes::_fast_lgetfield : // fall through
  180. + case Bytecodes::_fast_sgetfield : // fall through
  181. + case Bytecodes::_fast_aputfield : // fall through
  182. + case Bytecodes::_fast_bputfield : // fall through
  183. + case Bytecodes::_fast_cputfield : // fall through
  184. + case Bytecodes::_fast_dputfield : // fall through
  185. + case Bytecodes::_fast_fputfield : // fall through
  186. + case Bytecodes::_fast_iputfield : // fall through
  187. + case Bytecodes::_fast_lputfield : // fall through
  188. + case Bytecodes::_fast_sputfield : // fall through
  189. case Bytecodes::_getstatic:
  190. case Bytecodes::_putstatic:
  191. case Bytecodes::_getfield:
  192. @@ -2267,7 +2283,7 @@
  193. // The registers cache and index expected to be set before call.
  194. // Correct values of the cache and index registers are preserved.
  195. void TemplateTable::jvmti_post_field_access(Register cache, Register index,
  196. - bool is_static, bool has_tos) {
  197. + int byte_no, bool is_static, bool has_tos) {
  198. // do the JVMTI work here to avoid disturbing the register state below
  199. // We use c_rarg registers here because we want to use the register used in
  200. // the call to the VM
  201. @@ -2298,7 +2314,11 @@
  202. __ call_VM(noreg, CAST_FROM_FN_PTR(address,
  203. InterpreterRuntime::post_field_access),
  204. c_rarg1, c_rarg2, c_rarg3);
  205. - __ get_cache_and_index_at_bcp(cache, index, 1);
  206. +
  207. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  208. + __ restore_bcp();
  209. + resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  210. +
  211. __ bind(L1);
  212. }
  213. }
  214. @@ -2320,7 +2340,7 @@
  215. const Register bc = c_rarg3; // uses same reg as obj, so don't mix them
  216. resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  217. - jvmti_post_field_access(cache, index, is_static, false);
  218. + jvmti_post_field_access(cache, index, byte_no, is_static, false);
  219. load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  220. if (!is_static) {
  221. @@ -2455,7 +2475,7 @@
  222. // The registers cache and index expected to be set before call.
  223. // The function may destroy various registers, just not the cache and index registers.
  224. -void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is_static) {
  225. +void TemplateTable::jvmti_post_field_mod(Register cache, Register index, int byte_no, bool is_static) {
  226. transition(vtos, vtos);
  227. ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();
  228. @@ -2507,7 +2527,11 @@
  229. CAST_FROM_FN_PTR(address,
  230. InterpreterRuntime::post_field_modification),
  231. c_rarg1, c_rarg2, c_rarg3);
  232. - __ get_cache_and_index_at_bcp(cache, index, 1);
  233. +
  234. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  235. + __ restore_bcp();
  236. + resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  237. +
  238. __ bind(L1);
  239. }
  240. }
  241. @@ -2523,7 +2547,7 @@
  242. const Register bc = c_rarg3;
  243. resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  244. - jvmti_post_field_mod(cache, index, is_static);
  245. + jvmti_post_field_mod(cache, index, byte_no, is_static);
  246. load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  247. // [jk] not needed currently
  248. @@ -2837,6 +2861,11 @@
  249. InterpreterRuntime::post_field_access),
  250. c_rarg1, c_rarg2);
  251. __ pop_ptr(rax); // restore object pointer
  252. +
  253. + // DCEVM: Redefinition might have occured => reresolve the cp entry.
  254. + __ restore_bcp();
  255. + resolve_cache_and_index(1, noreg, rax, rcx, sizeof(u2));
  256. +
  257. __ bind(L1);
  258. }
  259. @@ -3073,6 +3102,26 @@
  260. __ bind(notFinal);
  261. + // DCEVM: Check if we are calling an old method (and have to go slow path)
  262. + Label notOld;
  263. + __ movl(rax, flags);
  264. + __ andl(rax, (1 << ConstantPoolCacheEntry::is_old_method_shift));
  265. + __ jcc(Assembler::zero, notOld);
  266. +
  267. + // Need a null check here!
  268. + __ null_check(recv);
  269. +
  270. + // Call out to VM to do look up based on correct vTable version (has to iterate back over the class history of the receiver class)
  271. + // DCEVM: TODO: Check if we can improve performance by inlining.
  272. + // DCEVM: TODO: Check if this additional branch affects normal execution time.
  273. + __ call_VM(method, CAST_FROM_FN_PTR(address, InterpreterRuntime::find_correct_method), recv, index);
  274. +
  275. + // profile this call
  276. + __ profile_final_call(rax);
  277. + __ jump_from_interpreted(method, rdx);
  278. +
  279. + __ bind(notOld);
  280. +
  281. // get receiver klass
  282. __ null_check(recv, oopDesc::klass_offset_in_bytes());
  283. __ load_klass(rax, recv);
  284. @@ -3156,6 +3205,35 @@
  285. invokevirtual_helper(rbx, rcx, rdx);
  286. __ bind(notMethod);
  287. + // DCEVM: Check if we are calling an old method (and have to go slow path)
  288. + Label notOld;
  289. + __ andl(rdx, (1 << ConstantPoolCacheEntry::is_old_method_shift));
  290. + __ jcc(Assembler::zero, notOld);
  291. +
  292. + // Call out to VM to do look up based on correct vTable version (has to iterate back over the class history of the receiver class)
  293. + // DCEVM: TODO: Check if we can improve performance by inlining.
  294. + // DCEVM: TODO: Check if this additional branch affects normal execution time.
  295. + // DCEVM: TODO: Check the exact semantic (with respect to destoying registers) of call_VM
  296. + // DCEVM: FIXME: What exactly should we store here?
  297. + __ push(rcx); // destroyed by Linux arguments passing conventions
  298. + __ movptr(r14, rcx);
  299. + __ call_VM(rbx, CAST_FROM_FN_PTR(address, InterpreterRuntime::find_correct_interface_method), r14, rax, rbx);
  300. + __ pop(rcx);
  301. +
  302. + // Get receiver klass into rdx - also a null check
  303. + __ restore_locals(); // restore r14
  304. + __ load_klass(rdx, rcx);
  305. + __ verify_oop(rdx);
  306. +
  307. + // DCEVM: TODO: Check if resolved method could be null.
  308. +
  309. + // profile this call
  310. + __ profile_virtual_call(rdx, r13, r14);
  311. +
  312. + __ jump_from_interpreted(rbx, rdx);
  313. +
  314. + __ bind(notOld);
  315. +
  316. // Get receiver klass into rdx - also a null check
  317. __ restore_locals(); // restore r14
  318. __ null_check(rcx, oopDesc::klass_offset_in_bytes());
  319. diff --git a/src/share/vm/c1/c1_Compilation.hpp b/src/share/vm/c1/c1_Compilation.hpp
  320. index 9a8ca61..196ab25 100644
  321. --- a/src/share/vm/c1/c1_Compilation.hpp
  322. +++ b/src/share/vm/c1/c1_Compilation.hpp
  323. @@ -242,8 +242,8 @@
  324. #define BAILOUT(msg) { bailout(msg); return; }
  325. #define BAILOUT_(msg, res) { bailout(msg); return res; }
  326. -#define CHECK_BAILOUT() { if (bailed_out()) return; }
  327. -#define CHECK_BAILOUT_(res) { if (bailed_out()) return res; }
  328. +#define CHECK_BAILOUT() { if (((CompilerThread *)Thread::current())->should_bailout()) bailout("Aborted externally"); if (bailed_out()) return; }
  329. +#define CHECK_BAILOUT_(res) { if (((CompilerThread *)Thread::current())->should_bailout()) bailout("Aborted externally"); if (bailed_out()) return res; }
  330. class InstructionMark: public StackObj {
  331. diff --git a/src/share/vm/ci/ciEnv.cpp b/src/share/vm/ci/ciEnv.cpp
  332. index e20db5d..57f37db 100644
  333. --- a/src/share/vm/ci/ciEnv.cpp
  334. +++ b/src/share/vm/ci/ciEnv.cpp
  335. @@ -1172,3 +1172,11 @@
  336. // If memory is low, we stop compiling methods.
  337. record_method_not_compilable("out of memory");
  338. }
  339. +
  340. +// DCEVM: Called after class redefinition to clean up possibly invalidated state.
  341. +void ciEnv::cleanup_after_redefinition() {
  342. +
  343. + if (_factory != NULL) {
  344. + _factory->cleanup_after_redefinition();
  345. + }
  346. +}
  347. diff --git a/src/share/vm/ci/ciEnv.hpp b/src/share/vm/ci/ciEnv.hpp
  348. index 103e532..abe2e37 100644
  349. --- a/src/share/vm/ci/ciEnv.hpp
  350. +++ b/src/share/vm/ci/ciEnv.hpp
  351. @@ -417,6 +417,8 @@
  352. void record_failure(const char* reason);
  353. void record_method_not_compilable(const char* reason, bool all_tiers = true);
  354. void record_out_of_memory_failure();
  355. +
  356. + void cleanup_after_redefinition();
  357. };
  358. #endif // SHARE_VM_CI_CIENV_HPP
  359. diff --git a/src/share/vm/ci/ciObjectFactory.cpp b/src/share/vm/ci/ciObjectFactory.cpp
  360. index e0ab96b..36efef4 100644
  361. --- a/src/share/vm/ci/ciObjectFactory.cpp
  362. +++ b/src/share/vm/ci/ciObjectFactory.cpp
  363. @@ -296,6 +296,11 @@
  364. // into the table. We need to recompute our index.
  365. index = find(keyHandle(), _ci_objects);
  366. }
  367. +
  368. + if (is_found_at(index, keyHandle(), _ci_objects)) {
  369. + // DCEVM: Check if this is an error? Can occur when redefining classes.
  370. + return _ci_objects->at(index);
  371. + }
  372. assert(!is_found_at(index, keyHandle(), _ci_objects), "no double insert");
  373. insert(index, new_object, _ci_objects);
  374. return new_object;
  375. @@ -764,3 +769,50 @@
  376. _unloaded_instances->length(),
  377. _unloaded_klasses->length());
  378. }
  379. +
  380. +// DCEVM: Resoring the ciObject arrays after class redefinition
  381. +void ciObjectFactory::sort_ci_objects(GrowableArray<ciObject*>* objects) {
  382. +
  383. + // Resort the _ci_objects array. The order of two class pointers can be changed during class redefinition.
  384. + oop last = NULL;
  385. + for (int j = 0; j< objects->length(); j++) {
  386. + oop o = objects->at(j)->get_oop();
  387. + if (last >= o) {
  388. + int cur_last_index = j - 1;
  389. + oop cur_last = last;
  390. + while (cur_last >= o) {
  391. +
  392. + // Swap the two objects to guarantee ordering
  393. + ciObject *tmp = objects->at(cur_last_index);
  394. + objects->at_put(cur_last_index, objects->at(cur_last_index + 1));
  395. + objects->at_put(cur_last_index + 1, tmp);
  396. +
  397. + // Decrement index to move one step to the left
  398. + cur_last_index--;
  399. + if (cur_last_index < 0) {
  400. + break;
  401. + }
  402. + cur_last = objects->at(cur_last_index)->get_oop();
  403. + }
  404. + } else {
  405. + assert(last < o, "out of order");
  406. + last = o;
  407. + }
  408. + }
  409. +
  410. +#ifdef ASSERT
  411. + if (CIObjectFactoryVerify) {
  412. + oop last = NULL;
  413. + for (int j = 0; j< objects->length(); j++) {
  414. + oop o = objects->at(j)->get_oop();
  415. + assert(last < o, "out of order");
  416. + last = o;
  417. + }
  418. + }
  419. +#endif // ASSERT
  420. +}
  421. +
  422. +// DCEVM: Called after class redefinition to clean up possibly invalidated state.
  423. +void ciObjectFactory::cleanup_after_redefinition() {
  424. + sort_ci_objects(_ci_objects);
  425. +}
  426. diff --git a/src/share/vm/ci/ciObjectFactory.hpp b/src/share/vm/ci/ciObjectFactory.hpp
  427. index 26cc2c3..855a4ac 100644
  428. --- a/src/share/vm/ci/ciObjectFactory.hpp
  429. +++ b/src/share/vm/ci/ciObjectFactory.hpp
  430. @@ -38,6 +38,7 @@
  431. class ciObjectFactory : public ResourceObj {
  432. friend class VMStructs;
  433. friend class ciEnv;
  434. + friend class CompileBroker;
  435. private:
  436. static volatile bool _initialized;
  437. @@ -137,6 +138,11 @@
  438. void print_contents();
  439. void print();
  440. +
  441. +private:
  442. +
  443. + static void sort_ci_objects(GrowableArray<ciObject*>* objects);
  444. + void cleanup_after_redefinition();
  445. };
  446. #endif // SHARE_VM_CI_CIOBJECTFACTORY_HPP
  447. diff --git a/src/share/vm/classfile/classFileParser.cpp b/src/share/vm/classfile/classFileParser.cpp
  448. index 505bad1..2912a66 100644
  449. --- a/src/share/vm/classfile/classFileParser.cpp
  450. +++ b/src/share/vm/classfile/classFileParser.cpp
  451. @@ -795,6 +795,7 @@
  452. Handle class_loader,
  453. Handle protection_domain,
  454. Symbol* class_name,
  455. + KlassHandle old_klass,
  456. TRAPS) {
  457. ClassFileStream* cfs = stream();
  458. assert(length > 0, "only called for length>0");
  459. @@ -813,6 +814,9 @@
  460. interface_index, CHECK_(nullHandle));
  461. if (cp->tag_at(interface_index).is_klass()) {
  462. interf = KlassHandle(THREAD, cp->resolved_klass_at(interface_index));
  463. + if (!old_klass.is_null() && !interf->is_newest_version()) {
  464. + interf = KlassHandle(THREAD, interf->newest_version());
  465. + }
  466. } else {
  467. Symbol* unresolved_klass = cp->klass_name_at(interface_index);
  468. @@ -825,6 +829,9 @@
  469. klassOop k = SystemDictionary::resolve_super_or_fail(class_name,
  470. unresolved_klass, class_loader, protection_domain,
  471. false, CHECK_(nullHandle));
  472. + if (!old_klass.is_null()) {
  473. + k = k->klass_part()->newest_version();
  474. + }
  475. interf = KlassHandle(THREAD, k);
  476. }
  477. @@ -1923,6 +1930,8 @@
  478. int runtime_invisible_parameter_annotations_length = 0;
  479. u1* annotation_default = NULL;
  480. int annotation_default_length = 0;
  481. + u2 code_section_table_length;
  482. + typeArrayHandle code_section_table;
  483. // Parse code and exceptions attribute
  484. u2 method_attributes_count = cfs->get_u2_fast();
  485. @@ -2092,6 +2101,24 @@
  486. parse_stackmap_table(code_attribute_length, CHECK_(nullHandle));
  487. stackmap_data = typeArrayHandle(THREAD, sm);
  488. parsed_stackmap_attribute = true;
  489. + } else if (UseMethodForwardPoints && cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_code_sections()) {
  490. + int length = code_attribute_length;
  491. + int value_count = length / sizeof(u2);
  492. + int line_count = length / 3;
  493. + if (TraceRedefineClasses >= 3) {
  494. + tty->print_cr("Found code section attribute when loading class with %d entries", value_count, line_count);
  495. + }
  496. + code_section_table_length = value_count;
  497. + code_section_table = oopFactory::new_permanent_shortArray(value_count, CHECK_NULL);
  498. + code_section_table->set_length(value_count);
  499. +
  500. + for (int i = 0; i < value_count; ++i) {
  501. + u2 value = cfs->get_u2(CHECK_(nullHandle));
  502. + code_section_table->short_at_put(i, value);
  503. + if (TraceRedefineClasses >= 4) {
  504. + tty->print_cr("Code section table at %d: %d", i, value);
  505. + }
  506. + }
  507. } else {
  508. // Skip unknown attributes
  509. cfs->skip_u1(code_attribute_length, CHECK_(nullHandle));
  510. @@ -2216,6 +2243,18 @@
  511. }
  512. #endif
  513. + // DCEVM: TODO: Get a different solution for the problem of method forward
  514. + // points and variable sized interpreter frames.
  515. + if (UseMethodForwardPoints) {
  516. + if (max_stack > MethodForwardPointsMaxStack) {
  517. + fatal(err_msg("Method has too large stack (%d), increase the value of MethodForwardPointsMaxStack (%d)", max_stack, MethodForwardPointsMaxStack));
  518. + }
  519. + if (max_locals > MethodForwardPointsMaxLocals) {
  520. + fatal(err_msg("Method has too many locals (%d), increase the value of MethodForwardPointsMaxLocals (%d)", max_stack, MethodForwardPointsMaxStack));
  521. + }
  522. + max_stack = MethodForwardPointsMaxStack;
  523. + max_locals = MethodForwardPointsMaxLocals;
  524. + }
  525. // Fill in code attribute information
  526. m->set_max_stack(max_stack);
  527. m->set_max_locals(max_locals);
  528. @@ -2228,6 +2267,8 @@
  529. * sure that the oops can pass verification when this field is set.
  530. */
  531. m->constMethod()->set_stackmap_data(stackmap_data());
  532. +
  533. + m->constMethod()->set_code_section_table(code_section_table());
  534. // Copy byte codes
  535. m->set_code(code_start);
  536. @@ -2825,6 +2866,15 @@
  537. "Invalid Deprecated classfile attribute length %u in class file %s",
  538. attribute_length, CHECK);
  539. }
  540. + } else if (tag == vmSymbols::tag_field_redefinition_policy()) {
  541. + // DCEVM: Check for deleted field attribute
  542. + _field_redefinition_policy = cfs->get_u1_fast();
  543. + } else if (tag == vmSymbols::tag_static_field_redefinition_policy()) {
  544. + // DCEVM: Check for deleted static field attribute
  545. + _static_field_redefinition_policy = cfs->get_u1_fast();
  546. + } else if (tag == vmSymbols::tag_method_redefinition_policy()) {
  547. + // DCEVM: Check for deleted method attribute
  548. + _method_redefinition_policy = cfs->get_u1_fast();
  549. } else if (_major_version >= JAVA_1_5_VERSION) {
  550. if (tag == vmSymbols::tag_signature()) {
  551. if (attribute_length != 2) {
  552. @@ -2929,6 +2979,17 @@
  553. }
  554. k->set_inner_classes(_inner_classes());
  555. k->set_class_annotations(_annotations());
  556. +
  557. +
  558. + if (_field_redefinition_policy != 0xff) {
  559. + k->set_field_redefinition_policy(_field_redefinition_policy);
  560. + }
  561. + if (_static_field_redefinition_policy != 0xff) {
  562. + k->set_static_field_redefinition_policy(_static_field_redefinition_policy);
  563. + }
  564. + if (_method_redefinition_policy != 0xff) {
  565. + k->set_method_redefinition_policy(_method_redefinition_policy);
  566. + }
  567. }
  568. typeArrayHandle ClassFileParser::assemble_annotations(u1* runtime_visible_annotations,
  569. @@ -2952,9 +3013,126 @@
  570. }
  571. +// DCEVM: Finds the super symbols by reading the bytes of the class and returns
  572. +// them in a growable array.
  573. +void ClassFileParser::findSuperSymbols(Symbol* name,
  574. + Handle class_loader,
  575. + Handle protection_domain,
  576. + KlassHandle old_klass,
  577. + GrowableArray<Symbol*> &handles,
  578. + TRAPS) {
  579. +
  580. + _cp_patches = NULL;
  581. + // So that JVMTI can cache class file in the state before retransformable agents
  582. + // have modified it
  583. + unsigned char *cached_class_file_bytes = NULL;
  584. +
  585. + ClassFileStream* cfs = stream();
  586. +
  587. + _has_finalizer = _has_empty_finalizer = _has_vanilla_constructor = false;
  588. +
  589. + instanceKlassHandle nullHandle;
  590. +
  591. + // Save the class file name for easier error message printing.
  592. + _class_name = name != NULL ? name : vmSymbols::unknown_class_name();
  593. +
  594. + cfs->guarantee_more(8, CHECK); // magic, major, minor
  595. + // Magic value
  596. + u4 magic = cfs->get_u4_fast();
  597. + if (magic != JAVA_CLASSFILE_MAGIC) {
  598. + // Invalid class file!
  599. + return;
  600. + }
  601. +
  602. + // Version numbers
  603. + u2 minor_version = cfs->get_u2_fast();
  604. + u2 major_version = cfs->get_u2_fast();
  605. +
  606. + // Check version numbers - we check this even with verifier off
  607. + if (!is_supported_version(major_version, minor_version)) {
  608. +
  609. + // Unsupported version!
  610. + return;
  611. + }
  612. +
  613. + _major_version = major_version;
  614. + _minor_version = minor_version;
  615. +
  616. +
  617. + // Check if verification needs to be relaxed for this class file
  618. + // Do not restrict it to jdk1.0 or jdk1.1 to maintain backward compatibility (4982376)
  619. + _relax_verify = Verifier::relax_verify_for(class_loader());
  620. + _need_verify = false;
  621. +
  622. + // Constant pool
  623. + constantPoolHandle cp = parse_constant_pool(class_loader(), CHECK);
  624. + int cp_size = cp->length();
  625. +
  626. + cfs->guarantee_more(8, CHECK); // flags, this_class, super_class, infs_len
  627. +
  628. + // Access flags
  629. + AccessFlags access_flags;
  630. + jint flags = cfs->get_u2_fast() & JVM_RECOGNIZED_CLASS_MODIFIERS;
  631. +
  632. + if ((flags & JVM_ACC_INTERFACE) && _major_version < JAVA_6_VERSION) {
  633. + // Set abstract bit for old class files for backward compatibility
  634. + flags |= JVM_ACC_ABSTRACT;
  635. + }
  636. + access_flags.set_flags(flags);
  637. +
  638. + // This class and superclass
  639. + instanceKlassHandle super_klass;
  640. + u2 this_class_index = cfs->get_u2_fast();
  641. + check_property(
  642. + valid_cp_range(this_class_index, cp_size) &&
  643. + cp->tag_at(this_class_index).is_unresolved_klass(),
  644. + "Invalid this class index %u in constant pool in class file %s",
  645. + this_class_index, CHECK);
  646. +
  647. + Symbol* class_name = cp->unresolved_klass_at(this_class_index);
  648. + assert(class_name != NULL, "class_name can't be null");
  649. +
  650. + // Update _class_name which could be null previously to be class_name
  651. + _class_name = class_name;
  652. +
  653. + // DCEVM: DO NOT release all handles when parsing is done
  654. + {// HandleMark hm(THREAD);
  655. +
  656. + // Checks if name in class file matches requested name
  657. + if (name != NULL && class_name != name) {
  658. + return;
  659. + }
  660. +
  661. + u2 super_class_index = cfs->get_u2_fast();
  662. +
  663. + if (super_class_index != 0) {
  664. + Symbol* super_class = cp->klass_name_at(super_class_index);
  665. + handles.append(super_class);
  666. + } else {
  667. + // DCEVM: This redefinition must be for the Object class.
  668. + }
  669. +
  670. + // Interfaces
  671. + u2 itfs_len = cfs->get_u2_fast();
  672. + objArrayHandle local_interfaces;
  673. + if (itfs_len == 0) {
  674. + local_interfaces = objArrayHandle(THREAD, Universe::the_empty_system_obj_array());
  675. + } else {
  676. + local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, old_klass, CHECK);
  677. + }
  678. +
  679. + for (int i=0; i<local_interfaces->length(); i++) {
  680. + oop o = local_interfaces->obj_at(i);
  681. + Symbol* interface_handle = ((klassOop)o)->klass_part()->name();
  682. + handles.append(interface_handle);
  683. + }
  684. + }
  685. +}
  686. +
  687. instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  688. Handle class_loader,
  689. Handle protection_domain,
  690. + KlassHandle old_klass,
  691. KlassHandle host_klass,
  692. GrowableArray<Handle>* cp_patches,
  693. TempNewSymbol& parsed_name,
  694. @@ -3005,10 +3183,13 @@
  695. unsigned char* ptr = cfs->buffer();
  696. unsigned char* end_ptr = cfs->buffer() + cfs->length();
  697. + bool pretend_new_universe = Thread::current()->pretend_new_universe();
  698. + Thread::current()->set_pretend_new_universe(false);
  699. JvmtiExport::post_class_file_load_hook(name, class_loader, protection_domain,
  700. &ptr, &end_ptr,
  701. &cached_class_file_bytes,
  702. &cached_class_file_length);
  703. + Thread::current()->set_pretend_new_universe(pretend_new_universe);
  704. if (ptr != cfs->buffer()) {
  705. // JVMTI agent has modified class file data.
  706. @@ -3164,7 +3345,11 @@
  707. // However, make sure it is not an array type.
  708. bool is_array = false;
  709. if (cp->tag_at(super_class_index).is_klass()) {
  710. - super_klass = instanceKlassHandle(THREAD, cp->resolved_klass_at(super_class_index));
  711. + klassOop resolved_klass = cp->resolved_klass_at(super_class_index);
  712. + if (!old_klass.is_null()) {
  713. + resolved_klass = resolved_klass->klass_part()->newest_version();
  714. + }
  715. + super_klass = instanceKlassHandle(THREAD, resolved_klass);
  716. if (_need_verify)
  717. is_array = super_klass->oop_is_array();
  718. } else if (_need_verify) {
  719. @@ -3182,7 +3367,7 @@
  720. if (itfs_len == 0) {
  721. local_interfaces = objArrayHandle(THREAD, Universe::the_empty_system_obj_array());
  722. } else {
  723. - local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, CHECK_(nullHandle));
  724. + local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, old_klass, CHECK_(nullHandle));
  725. }
  726. u2 java_fields_count = 0;
  727. @@ -3237,7 +3422,9 @@
  728. protection_domain,
  729. true,
  730. CHECK_(nullHandle));
  731. -
  732. + if (!old_klass.is_null()) {
  733. + k = k->klass_part()->newest_version();
  734. + }
  735. KlassHandle kh (THREAD, k);
  736. super_klass = instanceKlassHandle(THREAD, kh());
  737. }
  738. @@ -3626,6 +3813,19 @@
  739. rt = REF_NONE;
  740. } else {
  741. rt = super_klass->reference_type();
  742. +
  743. + // DCEVM: With class redefinition, it can also happen that special classes are loaded.
  744. + if (name == vmSymbols::java_lang_ref_Reference()) {
  745. + rt = REF_OTHER;
  746. + } else if (name == vmSymbols::java_lang_ref_SoftReference()) {
  747. + rt = REF_SOFT;
  748. + } else if (name == vmSymbols::java_lang_ref_WeakReference()) {
  749. + rt = REF_WEAK;
  750. + } else if (name == vmSymbols::java_lang_ref_FinalReference()) {
  751. + rt = REF_FINAL;
  752. + } else if (name == vmSymbols::java_lang_ref_PhantomReference()) {
  753. + rt = REF_PHANTOM;
  754. + }
  755. }
  756. // We can now create the basic klassOop for this klass
  757. @@ -3726,7 +3926,7 @@
  758. fill_oop_maps(this_klass, nonstatic_oop_map_count, nonstatic_oop_offsets, nonstatic_oop_counts);
  759. // Fill in has_finalizer, has_vanilla_constructor, and layout_helper
  760. - set_precomputed_flags(this_klass);
  761. + set_precomputed_flags(this_klass, old_klass);
  762. // reinitialize modifiers, using the InnerClasses attribute
  763. int computed_modifiers = this_klass->compute_modifier_flags(CHECK_(nullHandle));
  764. @@ -3748,6 +3948,10 @@
  765. // Allocate mirror and initialize static fields
  766. java_lang_Class::create_mirror(this_klass, CHECK_(nullHandle));
  767. +
  768. + if (rt == REF_OTHER) {
  769. + instanceRefKlass::update_nonstatic_oop_maps(ik);
  770. + }
  771. ClassLoadingService::notify_class_loaded(instanceKlass::cast(this_klass()),
  772. false /* not shared class */);
  773. @@ -3891,7 +4095,7 @@
  774. }
  775. -void ClassFileParser::set_precomputed_flags(instanceKlassHandle k) {
  776. +void ClassFileParser::set_precomputed_flags(instanceKlassHandle k, KlassHandle old_klass) {
  777. klassOop super = k->super();
  778. // Check if this klass has an empty finalize method (i.e. one with return bytecode only),
  779. @@ -3899,7 +4103,9 @@
  780. if (!_has_empty_finalizer) {
  781. if (_has_finalizer ||
  782. (super != NULL && super->klass_part()->has_finalizer())) {
  783. - k->set_has_finalizer();
  784. + if (old_klass.is_null() || old_klass->has_finalizer()) {
  785. + k->set_has_finalizer();
  786. + }
  787. }
  788. }
  789. @@ -3915,7 +4121,7 @@
  790. // Check if this klass supports the java.lang.Cloneable interface
  791. if (SystemDictionary::Cloneable_klass_loaded()) {
  792. - if (k->is_subtype_of(SystemDictionary::Cloneable_klass())) {
  793. + if (k->is_subtype_of(SystemDictionary::Cloneable_klass()) || k->is_subtype_of(SystemDictionary::Cloneable_klass()->klass_part()->newest_version())) {
  794. k->set_is_cloneable();
  795. }
  796. }
  797. diff --git a/src/share/vm/classfile/classFileParser.hpp b/src/share/vm/classfile/classFileParser.hpp
  798. index a95a784..ac217fc 100644
  799. --- a/src/share/vm/classfile/classFileParser.hpp
  800. +++ b/src/share/vm/classfile/classFileParser.hpp
  801. @@ -64,6 +64,9 @@
  802. int _sde_length;
  803. typeArrayHandle _inner_classes;
  804. typeArrayHandle _annotations;
  805. + u1 _field_redefinition_policy;
  806. + u1 _static_field_redefinition_policy;
  807. + u1 _method_redefinition_policy;
  808. void set_class_synthetic_flag(bool x) { _synthetic_flag = x; }
  809. void set_class_sourcefile(Symbol* x) { _sourcefile = x; }
  810. @@ -151,6 +154,7 @@
  811. Handle class_loader,
  812. Handle protection_domain,
  813. Symbol* class_name,
  814. + KlassHandle old_klass,
  815. TRAPS);
  816. // Field parsing
  817. @@ -239,7 +243,7 @@
  818. unsigned int nonstatic_oop_map_count,
  819. int* nonstatic_oop_offsets,
  820. unsigned int* nonstatic_oop_counts);
  821. - void set_precomputed_flags(instanceKlassHandle k);
  822. + void set_precomputed_flags(instanceKlassHandle k, KlassHandle old_klass);
  823. objArrayHandle compute_transitive_interfaces(instanceKlassHandle super,
  824. objArrayHandle local_ifs, TRAPS);
  825. @@ -345,7 +349,12 @@
  826. public:
  827. // Constructor
  828. - ClassFileParser(ClassFileStream* st) { set_stream(st); }
  829. + ClassFileParser(ClassFileStream* st) {
  830. + set_stream(st);
  831. + _field_redefinition_policy = 0xff;
  832. + _static_field_redefinition_policy = 0xff;
  833. + _method_redefinition_policy = 0xff;
  834. + }
  835. // Parse .class file and return new klassOop. The klassOop is not hooked up
  836. // to the system dictionary or any other structures, so a .class file can
  837. @@ -357,21 +366,33 @@
  838. instanceKlassHandle parseClassFile(Symbol* name,
  839. Handle class_loader,
  840. Handle protection_domain,
  841. + KlassHandle old_klass,
  842. TempNewSymbol& parsed_name,
  843. bool verify,
  844. TRAPS) {
  845. KlassHandle no_host_klass;
  846. - return parseClassFile(name, class_loader, protection_domain, no_host_klass, NULL, parsed_name, verify, THREAD);
  847. + return parseClassFile(name, class_loader, protection_domain, old_klass, no_host_klass, NULL, parsed_name, verify, THREAD);
  848. }
  849. instanceKlassHandle parseClassFile(Symbol* name,
  850. Handle class_loader,
  851. Handle protection_domain,
  852. + KlassHandle old_klass,
  853. KlassHandle host_klass,
  854. GrowableArray<Handle>* cp_patches,
  855. TempNewSymbol& parsed_name,
  856. bool verify,
  857. TRAPS);
  858. + static void initialize_static_field(fieldDescriptor* fd, TRAPS);
  859. +
  860. + // DCEVM: Creates symbol handles for the super class and the interfaces
  861. + void findSuperSymbols(Symbol* name,
  862. + Handle class_loader,
  863. + Handle protection_domain,
  864. + KlassHandle old_klass,
  865. + GrowableArray<Symbol*> &handles,
  866. + TRAPS);
  867. +
  868. // Verifier checks
  869. static void check_super_class_access(instanceKlassHandle this_klass, TRAPS);
  870. static void check_super_interface_access(instanceKlassHandle this_klass, TRAPS);
  871. diff --git a/src/share/vm/classfile/classLoader.cpp b/src/share/vm/classfile/classLoader.cpp
  872. index a2e61a4..450e19f 100644
  873. --- a/src/share/vm/classfile/classLoader.cpp
  874. +++ b/src/share/vm/classfile/classLoader.cpp
  875. @@ -915,6 +915,7 @@
  876. instanceKlassHandle result = parser.parseClassFile(h_name,
  877. class_loader,
  878. protection_domain,
  879. + KlassHandle(),
  880. parsed_name,
  881. false,
  882. CHECK_(h));
  883. diff --git a/src/share/vm/classfile/dictionary.cpp b/src/share/vm/classfile/dictionary.cpp
  884. index 78e76cc..ee21f3a 100644
  885. --- a/src/share/vm/classfile/dictionary.cpp
  886. +++ b/src/share/vm/classfile/dictionary.cpp
  887. @@ -326,6 +326,21 @@
  888. }
  889. }
  890. +
  891. +// DCEVM: Just the classes from defining class loaders
  892. +void Dictionary::classes_do(ObjectClosure *closure) {
  893. + for (int index = 0; index < table_size(); index++) {
  894. + for (DictionaryEntry* probe = bucket(index);
  895. + probe != NULL;
  896. + probe = probe->next()) {
  897. + klassOop k = probe->klass();
  898. + if (probe->loader() == instanceKlass::cast(k)->class_loader()) {
  899. + closure->do_object(k);
  900. + }
  901. + }
  902. + }
  903. +}
  904. +
  905. // Added for initialize_itable_for_klass to handle exceptions
  906. // Just the classes from defining class loaders
  907. void Dictionary::classes_do(void f(klassOop, TRAPS), TRAPS) {
  908. @@ -433,6 +448,33 @@
  909. add_entry(index, entry);
  910. }
  911. +// DCEVM: Updates the klass entry to point to the new klassOop. Necessary only for class redefinition.
  912. +bool Dictionary::update_klass(int index, unsigned int hash, Symbol* name, Handle loader, KlassHandle k, KlassHandle old_class) {
  913. +
  914. + // There are several entries for the same class in the dictionary: One extra entry for each parent classloader of the classloader of the class.
  915. + bool found = false;
  916. + for (int index = 0; index < table_size(); index++) {
  917. + for (DictionaryEntry* entry = bucket(index); entry != NULL; entry = entry->next()) {
  918. + if (entry->klass() == old_class()) {
  919. + entry->set_literal(k());
  920. + found = true;
  921. + }
  922. + }
  923. + }
  924. +
  925. + return found;
  926. +}
  927. +
  928. +// DCEVM: Undo previous updates to the system dictionary
  929. +void Dictionary::rollback_redefinition() {
  930. + for (int index = 0; index < table_size(); index++) {
  931. + for (DictionaryEntry* entry = bucket(index); entry != NULL; entry = entry->next()) {
  932. + if (entry->klass()->klass_part()->is_redefining()) {
  933. + entry->set_literal(entry->klass()->klass_part()->old_version());
  934. + }
  935. + }
  936. + }
  937. +}
  938. // This routine does not lock the system dictionary.
  939. //
  940. @@ -459,12 +501,22 @@
  941. return NULL;
  942. }
  943. +// DCEVM: return old version if we are not in the new universe?
  944. +klassOop Dictionary::intercept_for_version(klassOop k) {
  945. + if (k == NULL) return k;
  946. +
  947. + if (k->klass_part()->is_redefining() && !Thread::current()->pretend_new_universe()) {
  948. + return k->klass_part()->old_version();
  949. + }
  950. +
  951. + return k;
  952. +}
  953. klassOop Dictionary::find(int index, unsigned int hash, Symbol* name,
  954. Handle loader, Handle protection_domain, TRAPS) {
  955. DictionaryEntry* entry = get_entry(index, hash, name, loader);
  956. if (entry != NULL && entry->is_valid_protection_domain(protection_domain)) {
  957. - return entry->klass();
  958. + return intercept_for_version(entry->klass());
  959. } else {
  960. return NULL;
  961. }
  962. @@ -477,7 +529,7 @@
  963. assert (index == index_for(name, loader), "incorrect index?");
  964. DictionaryEntry* entry = get_entry(index, hash, name, loader);
  965. - return (entry != NULL) ? entry->klass() : (klassOop)NULL;
  966. + return intercept_for_version((entry != NULL) ? entry->klass() : (klassOop)NULL);
  967. }
  968. @@ -489,7 +541,7 @@
  969. assert (index == index_for(name, Handle()), "incorrect index?");
  970. DictionaryEntry* entry = get_entry(index, hash, name, Handle());
  971. - return (entry != NULL) ? entry->klass() : (klassOop)NULL;
  972. + return intercept_for_version((entry != NULL) ? entry->klass() : (klassOop)NULL);
  973. }
  974. diff --git a/src/share/vm/classfile/dictionary.hpp b/src/share/vm/classfile/dictionary.hpp
  975. index bd33760..186d0eb 100644
  976. --- a/src/share/vm/classfile/dictionary.hpp
  977. +++ b/src/share/vm/classfile/dictionary.hpp
  978. @@ -73,6 +73,10 @@
  979. void add_klass(Symbol* class_name, Handle class_loader,KlassHandle obj);
  980. + bool update_klass(int index, unsigned int hash, Symbol* name, Handle loader, KlassHandle k, KlassHandle old_class);
  981. +
  982. + void rollback_redefinition();
  983. +
  984. klassOop find_class(int index, unsigned int hash,
  985. Symbol* name, Handle loader);
  986. @@ -89,6 +93,7 @@
  987. void classes_do(void f(klassOop, TRAPS), TRAPS);
  988. void classes_do(void f(klassOop, oop));
  989. void classes_do(void f(klassOop, oop, TRAPS), TRAPS);
  990. + void classes_do(ObjectClosure *closure);
  991. void methods_do(void f(methodOop));
  992. @@ -105,6 +110,7 @@
  993. bool do_unloading(BoolObjectClosure* is_alive);
  994. // Protection domains
  995. + static klassOop intercept_for_version(klassOop k);
  996. klassOop find(int index, unsigned int hash, Symbol* name,
  997. Handle loader, Handle protection_domain, TRAPS);
  998. bool is_valid_protection_domain(int index, unsigned int hash,
  999. diff --git a/src/share/vm/classfile/javaClasses.cpp b/src/share/vm/classfile/javaClasses.cpp
  1000. index 7dd5f1b..9c7d8eb 100644
  1001. --- a/src/share/vm/classfile/javaClasses.cpp
  1002. +++ b/src/share/vm/classfile/javaClasses.cpp
  1003. @@ -1798,7 +1798,7 @@
  1004. klassOop klass = SystemDictionary::reflect_Method_klass();
  1005. // This class is eagerly initialized during VM initialization, since we keep a refence
  1006. // to one of the methods
  1007. - assert(instanceKlass::cast(klass)->is_initialized(), "must be initialized");
  1008. + assert(instanceKlass::cast(klass)->is_initialized() || klass->klass_part()->old_version() != NULL, "must be initialized");
  1009. return instanceKlass::cast(klass)->allocate_instance_handle(CHECK_NH);
  1010. }
  1011. diff --git a/src/share/vm/classfile/javaClasses.hpp b/src/share/vm/classfile/javaClasses.hpp
  1012. index 36d1cec..a6de98e 100644
  1013. --- a/src/share/vm/classfile/javaClasses.hpp
  1014. +++ b/src/share/vm/classfile/javaClasses.hpp
  1015. @@ -213,7 +213,6 @@
  1016. class java_lang_Class : AllStatic {
  1017. friend class VMStructs;
  1018. -
  1019. private:
  1020. // The fake offsets are added by the class loader when java.lang.Class is loaded
  1021. diff --git a/src/share/vm/classfile/loaderConstraints.cpp b/src/share/vm/classfile/loaderConstraints.cpp
  1022. index 8650cd9..965cce2 100644
  1023. --- a/src/share/vm/classfile/loaderConstraints.cpp
  1024. +++ b/src/share/vm/classfile/loaderConstraints.cpp
  1025. @@ -449,7 +449,7 @@
  1026. if (k != NULL) {
  1027. // We found the class in the system dictionary, so we should
  1028. // make sure that the klassOop matches what we already have.
  1029. - guarantee(k == probe->klass(), "klass should be in dictionary");
  1030. + guarantee(k == probe->klass()->klass_part()->newest_version(), "klass should be in dictionary");
  1031. } else {
  1032. // If we don't find the class in the system dictionary, it
  1033. // has to be in the placeholders table.
  1034. diff --git a/src/share/vm/classfile/loaderConstraints.hpp b/src/share/vm/classfile/loaderConstraints.hpp
  1035. index d01b2c4..1ad80f7 100644
  1036. --- a/src/share/vm/classfile/loaderConstraints.hpp
  1037. +++ b/src/share/vm/classfile/loaderConstraints.hpp
  1038. @@ -106,7 +106,7 @@
  1039. klassOop klass() { return literal(); }
  1040. klassOop* klass_addr() { return literal_addr(); }
  1041. - void set_klass(klassOop k) { set_literal(k); }
  1042. + void set_klass(klassOop k) { set_literal(k); assert(k == NULL || !k->klass_part()->is_redefining(), "just checking"); }
  1043. LoaderConstraintEntry* next() {
  1044. return (LoaderConstraintEntry*)HashtableEntry<klassOop, mtClass>::next();
  1045. diff --git a/src/share/vm/classfile/systemDictionary.cpp b/src/share/vm/classfile/systemDictionary.cpp
  1046. index 2fa221b..8e45161 100644
  1047. --- a/src/share/vm/classfile/systemDictionary.cpp
  1048. +++ b/src/share/vm/classfile/systemDictionary.cpp
  1049. @@ -157,6 +157,7 @@
  1050. // can return a null klass
  1051. klass = handle_resolution_exception(class_name, class_loader, protection_domain, throw_error, k_h, THREAD);
  1052. }
  1053. + assert(klass == NULL || klass->klass_part()->is_newest_version() || klass->klass_part()->newest_version()->klass_part()->is_redefining(), "must be");
  1054. return klass;
  1055. }
  1056. @@ -199,7 +200,8 @@
  1057. // Forwards to resolve_instance_class_or_null
  1058. klassOop SystemDictionary::resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS) {
  1059. - assert(!THREAD->is_Compiler_thread(),
  1060. + // DCEVM: Check if this relaxing of the condition is correct? Test case hs203t004 failing otherwise.
  1061. + assert(!THREAD->is_Compiler_thread() || JvmtiThreadState::state_for(JavaThread::current())->get_class_being_redefined() != NULL,
  1062. err_msg("can not load classes with compiler thread: class=%s, classloader=%s",
  1063. class_name->as_C_string(),
  1064. class_loader.is_null() ? "null" : class_loader->klass()->klass_part()->name()->as_C_string()));
  1065. @@ -961,6 +963,7 @@
  1066. instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
  1067. class_loader,
  1068. protection_domain,
  1069. + KlassHandle(),
  1070. host_klass,
  1071. cp_patches,
  1072. parsed_name,
  1073. @@ -1022,7 +1025,14 @@
  1074. Handle protection_domain,
  1075. ClassFileStream* st,
  1076. bool verify,
  1077. + KlassHandle old_class,
  1078. TRAPS) {
  1079. + bool redefine_classes_locked = false;
  1080. + if (!Thread::current()->redefine_classes_mutex()->owned_by_self()) {
  1081. + Thread::current()->redefine_classes_mutex()->lock();
  1082. + redefine_classes_locked = true;
  1083. + }
  1084. +
  1085. // Classloaders that support parallelism, e.g. bootstrap classloader,
  1086. // or all classloaders with UnsyncloadClass do not acquire lock here
  1087. bool DoObjectLock = true;
  1088. @@ -1050,9 +1060,14 @@
  1089. instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
  1090. class_loader,
  1091. protection_domain,
  1092. + old_class,
  1093. parsed_name,
  1094. verify,
  1095. THREAD);
  1096. + if (!old_class.is_null() && !k.is_null()) {
  1097. + k->set_redefining(true);
  1098. + k->set_old_version(old_class());
  1099. + }
  1100. const char* pkg = "java/";
  1101. if (!HAS_PENDING_EXCEPTION &&
  1102. @@ -1087,11 +1102,16 @@
  1103. // Add class just loaded
  1104. // If a class loader supports parallel classloading handle parallel define requests
  1105. // find_or_define_instance_class may return a different instanceKlass
  1106. - if (is_parallelCapable(class_loader)) {
  1107. + // (tw) TODO: for class redefinition the parallel version does not work, check if this is a problem?
  1108. + if (is_parallelCapable(class_loader) && old_class.is_null()) {
  1109. k = find_or_define_instance_class(class_name, class_loader, k, THREAD);
  1110. } else {
  1111. - define_instance_class(k, THREAD);
  1112. + define_instance_class(k, old_class, THREAD);
  1113. }
  1114. + }
  1115. +
  1116. + if (redefine_classes_locked) {
  1117. + Thread::current()->redefine_classes_mutex()->unlock();
  1118. }
  1119. // If parsing the class file or define_instance_class failed, we
  1120. @@ -1122,7 +1142,7 @@
  1121. MutexLocker mu(SystemDictionary_lock, THREAD);
  1122. klassOop check = find_class(parsed_name, class_loader);
  1123. - assert(check == k(), "should be present in the dictionary");
  1124. + assert((check == k() && !k->is_redefining()) || (k->is_redefining() && check == k->old_version()), "should be present in the dictionary");
  1125. klassOop check2 = find_class(h_name, h_loader);
  1126. assert(check == check2, "name inconsistancy in SystemDictionary");
  1127. @@ -1349,7 +1369,11 @@
  1128. }
  1129. }
  1130. -void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) {
  1131. +void SystemDictionary::rollback_redefinition() {
  1132. + dictionary()->rollback_redefinition();
  1133. +}
  1134. +
  1135. +void SystemDictionary::define_instance_class(instanceKlassHandle k, KlassHandle old_class, TRAPS) {
  1136. Handle class_loader_h(THREAD, k->class_loader());
  1137. @@ -1376,13 +1400,23 @@
  1138. Symbol* name_h = k->name();
  1139. unsigned int d_hash = dictionary()->compute_hash(name_h, class_loader_h);
  1140. int d_index = dictionary()->hash_to_index(d_hash);
  1141. - check_constraints(d_index, d_hash, k, class_loader_h, true, CHECK);
  1142. +
  1143. + // DCEVM: Update version of the klassOop in the system dictionary
  1144. + // TODO: Check for thread safety!
  1145. + if (!old_class.is_null()) {
  1146. + bool ok = dictionary()->update_klass(d_index, d_hash, name_h, class_loader_h, k, old_class);
  1147. + assert (ok, "must have found old class and updated!");
  1148. + }
  1149. + check_constraints(d_index, d_hash, k, class_loader_h, old_class.is_null(), CHECK);
  1150. +
  1151. + if(!old_class.is_null() && TraceRedefineClasses >= 3){ tty->print_cr("Class has been updated!"); }
  1152. // Register class just loaded with class loader (placed in Vector)
  1153. // Note we do this before updating the dictionary, as this can
  1154. // fail with an OutOfMemoryError (if it does, we will *not* put this
  1155. // class in the dictionary and will not update the class hierarchy).
  1156. - if (k->class_loader() != NULL) {
  1157. + // (tw) Only register if not redefining a class.
  1158. + if (k->class_loader() != NULL && old_class.is_null()) {
  1159. methodHandle m(THREAD, Universe::loader_addClass_method());
  1160. JavaValue result(T_VOID);
  1161. JavaCallArguments args(class_loader_h);
  1162. @@ -1408,8 +1442,9 @@
  1163. }
  1164. k->eager_initialize(THREAD);
  1165. + // (tw) Only notify jvmti if not redefining a class.
  1166. // notify jvmti
  1167. - if (JvmtiExport::should_post_class_load()) {
  1168. + if (JvmtiExport::should_post_class_load() && old_class.is_null()) {
  1169. assert(THREAD->is_Java_thread(), "thread->is_Java_thread()");
  1170. JvmtiExport::post_class_load((JavaThread *) THREAD, k());
  1171. @@ -1482,7 +1517,7 @@
  1172. }
  1173. }
  1174. - define_instance_class(k, THREAD);
  1175. + define_instance_class(k, KlassHandle(), THREAD);
  1176. Handle linkage_exception = Handle(); // null handle
  1177. @@ -1613,6 +1648,14 @@
  1178. Universe::flush_dependents_on(k);
  1179. }
  1180. +// (tw) Remove from hierarchy - Undo add_to_hierarchy.
  1181. +void SystemDictionary::remove_from_hierarchy(instanceKlassHandle k) {
  1182. + assert(k.not_null(), "just checking");
  1183. +
  1184. + k->remove_from_sibling_list();
  1185. +
  1186. + // TODO: Remove from interfaces.
  1187. +}
  1188. // ----------------------------------------------------------------------------
  1189. // GC support
  1190. @@ -1702,6 +1745,24 @@
  1191. }
  1192. +// (tw) Iterate over all pre-loaded classes in the dictionary.
  1193. +void SystemDictionary::preloaded_classes_do(OopClosure *f) {
  1194. + for (int k = (int)FIRST_WKID; k < (int)WKID_LIMIT; k++) {
  1195. + f->do_oop((oop*) &_well_known_klasses[k]);
  1196. + }
  1197. +
  1198. + {
  1199. + for (int i = 0; i < T_VOID+1; i++) {
  1200. + if (_box_klasses[i] != NULL) {
  1201. + assert(i >= T_BOOLEAN, "checking");
  1202. + f->do_oop((oop*) &_box_klasses[i]);
  1203. + }
  1204. + }
  1205. + }
  1206. +
  1207. + // TODO: Check if we need to call FilterFieldsMap
  1208. +}
  1209. +
  1210. void SystemDictionary::preloaded_oops_do(OopClosure* f) {
  1211. for (int k = (int)FIRST_WKID; k < (int)WKID_LIMIT; k++) {
  1212. f->do_oop((oop*) &_well_known_klasses[k]);
  1213. @@ -1732,6 +1793,11 @@
  1214. // Don't iterate over placeholders
  1215. void SystemDictionary::classes_do(void f(klassOop)) {
  1216. dictionary()->classes_do(f);
  1217. +}
  1218. +
  1219. +// (tw) Iterate over all classes in the dictionary.
  1220. +void SystemDictionary::classes_do(ObjectClosure *closure) {
  1221. + dictionary()->classes_do(closure);
  1222. }
  1223. // Added for initialize_itable_for_klass
  1224. @@ -1870,7 +1936,9 @@
  1225. // Preload ref klasses and set reference types
  1226. instanceKlass::cast(WK_KLASS(Reference_klass))->set_reference_type(REF_OTHER);
  1227. - instanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));
  1228. +
  1229. + // (tw) This is now done in parseClassFile in order to support class redefinition
  1230. + // instanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));
  1231. initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(Cleaner_klass), scan, CHECK);
  1232. instanceKlass::cast(WK_KLASS(SoftReference_klass))->set_reference_type(REF_SOFT);
  1233. @@ -1957,7 +2025,11 @@
  1234. // also holds array classes
  1235. assert(check->klass_part()->oop_is_instance(), "noninstance in systemdictionary");
  1236. - if ((defining == true) || (k() != check)) {
  1237. + if ((defining == true) && ((k() != check) && k->old_version() != check)) {
  1238. + ResourceMark rm(Thread::current());
  1239. + tty->print_cr("(%d / %d) (%s/%s)", k->revision_number(), check->klass_part()->revision_number(), k->name()->as_C_string(), check->klass_part()->name()->as_C_string());
  1240. + k()->print();
  1241. + check->print();
  1242. linkage_error = "loader (instance of %s): attempted duplicate class "
  1243. "definition for name: \"%s\"";
  1244. } else {
  1245. diff --git a/src/share/vm/classfile/systemDictionary.hpp b/src/share/vm/classfile/systemDictionary.hpp
  1246. index 85474c5..2dabd95 100644
  1247. --- a/src/share/vm/classfile/systemDictionary.hpp
  1248. +++ b/src/share/vm/classfile/systemDictionary.hpp
  1249. @@ -270,7 +270,7 @@
  1250. // Resolve from stream (called by jni_DefineClass and JVM_DefineClass)
  1251. static klassOop resolve_from_stream(Symbol* class_name, Handle class_loader,
  1252. Handle protection_domain,
  1253. - ClassFileStream* st, bool verify, TRAPS);
  1254. + ClassFileStream* st, bool verify, KlassHandle old_class, TRAPS);
  1255. // Lookup an already loaded class. If not found NULL is returned.
  1256. static klassOop find(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS);
  1257. @@ -311,6 +311,8 @@
  1258. // Iterate over all klasses in dictionary
  1259. // Just the classes from defining class loaders
  1260. static void classes_do(void f(klassOop));
  1261. + static void classes_do(ObjectClosure *closure);
  1262. + static void preloaded_classes_do(OopClosure *closure);
  1263. // Added for initialize_itable_for_klass to handle exceptions
  1264. static void classes_do(void f(klassOop, TRAPS), TRAPS);
  1265. // All classes, and their class loaders
  1266. @@ -416,6 +418,8 @@
  1267. int limit = (int)end_id + 1;
  1268. initialize_wk_klasses_until((WKID) limit, start_id, THREAD);
  1269. }
  1270. +
  1271. + static void rollback_redefinition();
  1272. public:
  1273. #define WK_KLASS_DECLARE(name, symbol, option) \
  1274. @@ -598,11 +602,11 @@
  1275. // after waiting, but before reentering SystemDictionary_lock
  1276. // to preserve lock order semantics.
  1277. static void double_lock_wait(Handle lockObject, TRAPS);
  1278. - static void define_instance_class(instanceKlassHandle k, TRAPS);
  1279. + static void define_instance_class(instanceKlassHandle k, KlassHandle old_class, TRAPS);
  1280. static instanceKlassHandle find_or_define_instance_class(Symbol* class_name,
  1281. Handle class_loader,
  1282. instanceKlassHandle k, TRAPS);
  1283. - static instanceKlassHandle load_shared_class(Symbol* class_name,
  1284. + static instanceKlassHandle load_shared_class(Symbol* class_name, // after waiting, but before reentering SystemDictionary_lock,
  1285. Handle class_loader, TRAPS);
  1286. static instanceKlassHandle load_shared_class(instanceKlassHandle ik,
  1287. Handle class_loader, TRAPS);
  1288. @@ -617,12 +621,16 @@
  1289. // Setup link to hierarchy
  1290. static void add_to_hierarchy(instanceKlassHandle k, TRAPS);
  1291. +public:
  1292. + // Remove link to hierarchy
  1293. + static void remove_from_hierarchy(instanceKlassHandle k);
  1294. +
  1295. +private:
  1296. // event based tracing
  1297. static void post_class_load_event(const Ticks& start_time, instanceKlassHandle k,
  1298. Handle initiating_loader);
  1299. static void post_class_unload_events(BoolObjectClosure* is_alive);
  1300. -private:
  1301. // We pass in the hashtable index so we can calculate it outside of
  1302. // the SystemDictionary_lock.
  1303. diff --git a/src/share/vm/classfile/verifier.cpp b/src/share/vm/classfile/verifier.cpp
  1304. index 49c4b2c..74d7614 100644
  1305. --- a/src/share/vm/classfile/verifier.cpp
  1306. +++ b/src/share/vm/classfile/verifier.cpp
  1307. @@ -106,7 +106,7 @@
  1308. return !need_verify;
  1309. }
  1310. -bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, TRAPS) {
  1311. +bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, bool may_use_old_verifier, TRAPS) {
  1312. HandleMark hm;
  1313. ResourceMark rm(THREAD);
  1314. @@ -117,7 +117,8 @@
  1315. const char* klassName = klass->external_name();
  1316. bool can_failover = FailOverToOldVerifier &&
  1317. - klass->major_version() < NOFAILOVER_MAJOR_VERSION;
  1318. + klass->major_version() < NOFAILOVER_MAJOR_VERSION &&
  1319. + may_use_old_verifier;
  1320. // If the class should be verified, first see if we can use the split
  1321. // verifier. If not, or if verification fails and FailOverToOldVerifier
  1322. @@ -138,6 +139,7 @@
  1323. tty->print_cr(
  1324. "Fail over class verification to old verifier for: %s", klassName);
  1325. }
  1326. + assert(may_use_old_verifier, "");
  1327. exception_name = inference_verify(
  1328. klass, message_buffer, message_buffer_len, THREAD);
  1329. }
  1330. @@ -145,6 +147,7 @@
  1331. exception_message = split_verifier.exception_message();
  1332. }
  1333. } else {
  1334. + assert(may_use_old_verifier, "");
  1335. exception_name = inference_verify(
  1336. klass, message_buffer, message_buffer_len, THREAD);
  1337. }
  1338. @@ -159,6 +162,9 @@
  1339. }
  1340. tty->print_cr("End class verification for: %s", klassName);
  1341. }
  1342. + } else if (TraceClassInitialization) {
  1343. + // (tw) Output not verified classes
  1344. + tty->print_cr("Class %s was not verified", klassName);
  1345. }
  1346. if (HAS_PENDING_EXCEPTION) {
  1347. @@ -210,7 +216,7 @@
  1348. // NOTE: this is called too early in the bootstrapping process to be
  1349. // guarded by Universe::is_gte_jdk14x_version()/UseNewReflection.
  1350. (refl_magic_klass == NULL ||
  1351. - !klass->is_subtype_of(refl_magic_klass) ||
  1352. + !(klass->is_subtype_of(refl_magic_klass) || klass->is_subtype_of(refl_magic_klass->klass_part()->newest_version())) ||
  1353. VerifyReflectionBytecodes)
  1354. );
  1355. }
  1356. @@ -517,7 +523,7 @@
  1357. ClassVerifier::ClassVerifier(
  1358. instanceKlassHandle klass, TRAPS)
  1359. - : _thread(THREAD), _exception_type(NULL), _message(NULL), _klass(klass) {
  1360. + : _thread(THREAD), _exception_type(NULL), _message(NULL), _klass(klass->newest_version()), _klass_to_verify(klass) {
  1361. _this_type = VerificationType::reference_type(klass->name());
  1362. // Create list to hold symbols in reference area.
  1363. _symbols = new GrowableArray<Symbol*>(100, 0, NULL);
  1364. @@ -547,7 +553,7 @@
  1365. _klass->external_name());
  1366. }
  1367. - objArrayHandle methods(THREAD, _klass->methods());
  1368. + objArrayHandle methods(THREAD, _klass_to_verify->methods());
  1369. int num_methods = methods->length();
  1370. for (int index = 0; index < num_methods; index++) {
  1371. @@ -2668,7 +2674,10 @@
  1372. VerificationType stack_object_type =
  1373. current_frame->pop_stack(ref_class_type, CHECK_VERIFY(this));
  1374. if (current_type() != stack_object_type) {
  1375. - assert(cp->cache() == NULL, "not rewritten yet");
  1376. +
  1377. + // (tw) TODO: Check if relaxing the following assertion is correct. For class redefinition we might call the verifier twice.
  1378. + //assert(cp->cache() == NULL, "not rewritten yet");
  1379. +
  1380. Symbol* ref_class_name =
  1381. cp->klass_name_at(cp->klass_ref_index_at(index));
  1382. // See the comments in verify_field_instructions() for
  1383. diff --git a/src/share/vm/classfile/verifier.hpp b/src/share/vm/classfile/verifier.hpp
  1384. index 92c4fd2..5e8e0da 100644
  1385. --- a/src/share/vm/classfile/verifier.hpp
  1386. +++ b/src/share/vm/classfile/verifier.hpp
  1387. @@ -48,7 +48,7 @@
  1388. * Otherwise, no exception is thrown and the return indicates the
  1389. * error.
  1390. */
  1391. - static bool verify(instanceKlassHandle klass, Mode mode, bool should_verify_class, TRAPS);
  1392. + static bool verify(instanceKlassHandle klass, Mode mode, bool should_verify_class, bool may_use_old_verifier, TRAPS);
  1393. // Return false if the class is loaded by the bootstrap loader,
  1394. // or if defineClass was called requesting skipping verification
  1395. @@ -257,7 +257,10 @@
  1396. ErrorContext _error_context; // contains information about an error
  1397. +public:
  1398. void verify_method(methodHandle method, TRAPS);
  1399. +
  1400. +private:
  1401. char* generate_code_data(methodHandle m, u4 code_length, TRAPS);
  1402. void verify_exception_handler_table(u4 code_length, char* code_data,
  1403. int& min, int& max, TRAPS);
  1404. @@ -341,6 +344,7 @@
  1405. VerificationType object_type() const;
  1406. + instanceKlassHandle _klass_to_verify;
  1407. instanceKlassHandle _klass; // the class being verified
  1408. methodHandle _method; // current method being verified
  1409. VerificationType _this_type; // the verification type of the current class
  1410. diff --git a/src/share/vm/classfile/vmSymbols.hpp b/src/share/vm/classfile/vmSymbols.hpp
  1411. index 51ceb15..7ef1e1f 100644
  1412. --- a/src/share/vm/classfile/vmSymbols.hpp
  1413. +++ b/src/share/vm/classfile/vmSymbols.hpp
  1414. @@ -139,6 +139,10 @@
  1415. template(tag_annotation_default, "AnnotationDefault") \
  1416. template(tag_enclosing_method, "EnclosingMethod") \
  1417. template(tag_bootstrap_methods, "BootstrapMethods") \
  1418. + template(tag_static_field_redefinition_policy, "StaticFieldRedefinitionPolicy") \
  1419. + template(tag_field_redefinition_policy, "FieldRedefinitionPolicy") \
  1420. + template(tag_method_redefinition_policy, "MethodRedefinitionPolicy") \
  1421. + template(tag_code_sections, "CodeSections") \
  1422. \
  1423. /* exception klasses: at least all exceptions thrown by the VM have entries here */ \
  1424. template(java_lang_ArithmeticException, "java/lang/ArithmeticException") \
  1425. @@ -380,6 +384,10 @@
  1426. template(oop_size_name, "oop_size") \
  1427. template(static_oop_field_count_name, "static_oop_field_count") \
  1428. \
  1429. + /* mutator in case of class redefinition */ \
  1430. + template(static_transformer_name, "$staticTransformer") \
  1431. + template(transformer_name, "$transformer") \
  1432. + \
  1433. /* non-intrinsic name/signature pairs: */ \
  1434. template(register_method_name, "register") \
  1435. do_alias(register_method_signature, object_void_signature) \
  1436. diff --git a/src/share/vm/compiler/compileBroker.cpp b/src/share/vm/compiler/compileBroker.cpp
  1437. index 3e8a65a..fe96a94 100644
  1438. --- a/src/share/vm/compiler/compileBroker.cpp
  1439. +++ b/src/share/vm/compiler/compileBroker.cpp
  1440. @@ -1181,6 +1181,14 @@
  1441. int comp_level,
  1442. methodHandle hot_method, int hot_count,
  1443. const char* comment, Thread* THREAD) {
  1444. + JavaThread* thread = JavaThread::current();
  1445. + if (thread->is_Compiler_thread() && thread->as_CompilerThread()->should_bailout()) {
  1446. + return NULL; // FIXME: DCEVM: should we do something else?
  1447. + }
  1448. + if (instanceKlass::cast(method->method_holder())->is_not_initialized()) {
  1449. + return NULL; // FIXME: DCEVM: how should we avoid this?
  1450. + }
  1451. +
  1452. // make sure arguments make sense
  1453. assert(method->method_holder()->klass_part()->oop_is_instance(), "not an instance method");
  1454. assert(osr_bci == InvocationEntryBci || (0 <= osr_bci && osr_bci < method->code_size()), "bci out of range");
  1455. @@ -1260,6 +1268,7 @@
  1456. }
  1457. // RedefineClasses() has replaced this method; just return
  1458. + // (tw) This is important for the new version of hotswapping: Old code will only execute properly in the interpreter!
  1459. if (method->is_old()) {
  1460. return NULL;
  1461. }
  1462. @@ -1592,6 +1601,8 @@
  1463. // Never compile a method if breakpoints are present in it
  1464. if (method()->number_of_breakpoints() == 0) {
  1465. + thread->compilation_mutex()->lock();
  1466. + thread->set_should_bailout(false);
  1467. // Compile the method.
  1468. if ((UseCompiler || AlwaysCompileLoopMethods) && CompileBroker::should_compile_new_jobs()) {
  1469. #ifdef COMPILER1
  1470. @@ -1615,6 +1626,7 @@
  1471. // After compilation is disabled, remove remaining methods from queue
  1472. method->clear_queued_for_compilation();
  1473. }
  1474. + thread->compilation_mutex()->unlock();
  1475. }
  1476. }
  1477. }
  1478. @@ -2165,3 +2177,15 @@
  1479. st->cr();
  1480. #endif
  1481. }
  1482. +
  1483. +// (tw) Clean up compiler interface after a class redefinition step
  1484. +void CompileBroker::cleanup_after_redefinition() {
  1485. + int num_threads = _method_threads->length();
  1486. +
  1487. + ciObjectFactory::sort_ci_objects(ciObjectFactory::_shared_ci_objects);
  1488. + for (int i=0; i<num_threads; i++) {
  1489. + if (_method_threads->at(i)->env() != NULL && _method_threads->at(i)->env() != (ciEnv *)badAddress) {
  1490. + _method_threads->at(i)->env()->cleanup_after_redefinition();
  1491. + }
  1492. + }
  1493. +}
  1494. diff --git a/src/share/vm/compiler/compileBroker.hpp b/src/share/vm/compiler/compileBroker.hpp
  1495. index 29f2b22..37989d1 100644
  1496. --- a/src/share/vm/compiler/compileBroker.hpp
  1497. +++ b/src/share/vm/compiler/compileBroker.hpp
  1498. @@ -408,6 +408,7 @@
  1499. static void print_compiler_threads_on(outputStream* st);
  1500. + static void cleanup_after_redefinition();
  1501. static int get_total_compile_count() { return _total_compile_count; }
  1502. static int get_total_bailout_count() { return _total_bailout_count; }
  1503. static int get_total_invalidated_count() { return _total_invalidated_count; }
  1504. diff --git a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
  1505. index a3abd66..b45f9e1 100644
  1506. --- a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
  1507. +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
  1508. @@ -162,6 +162,13 @@
  1509. }
  1510. }
  1511. +
  1512. +HeapWord* CompactibleFreeListSpace::forward_compact_top(size_t size,
  1513. + CompactPoint* cp, HeapWord* compact_top) {
  1514. + ShouldNotReachHere();
  1515. + return NULL;
  1516. +}
  1517. +
  1518. // Like CompactibleSpace forward() but always calls cross_threshold() to
  1519. // update the block offset table. Removed initialize_threshold call because
  1520. // CFLS does not use a block offset array for contiguous spaces.
  1521. diff --git a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
  1522. index 24509b6..6670b73 100644
  1523. --- a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
  1524. +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
  1525. @@ -149,6 +149,7 @@
  1526. // Support for compacting cms
  1527. HeapWord* cross_threshold(HeapWord* start, HeapWord* end);
  1528. + HeapWord* forward_compact_top(size_t size, CompactPoint* cp, HeapWord* compact_top);
  1529. HeapWord* forward(oop q, size_t size, CompactPoint* cp, HeapWord* compact_top);
  1530. // Initialization helpers.
  1531. diff --git a/src/share/vm/gc_implementation/shared/markSweep.cpp b/src/share/vm/gc_implementation/shared/markSweep.cpp
  1532. index 29841d8..a13a35d 100644
  1533. --- a/src/share/vm/gc_implementation/shared/markSweep.cpp
  1534. +++ b/src/share/vm/gc_implementation/shared/markSweep.cpp
  1535. @@ -32,6 +32,8 @@
  1536. #include "oops/objArrayKlass.inline.hpp"
  1537. #include "oops/oop.inline.hpp"
  1538. +GrowableArray<oop>* MarkSweep::_rescued_oops = NULL;
  1539. +
  1540. Stack<oop, mtGC> MarkSweep::_marking_stack;
  1541. Stack<DataLayout*, mtGC> MarkSweep::_revisit_mdo_stack;
  1542. Stack<Klass*, mtGC> MarkSweep::_revisit_klass_stack;
  1543. @@ -357,3 +359,86 @@
  1544. }
  1545. #endif
  1546. +
  1547. +// (tw) Copy the rescued objects to their destination address after compaction.
  1548. +void MarkSweep::copy_rescued_objects_back() {
  1549. +
  1550. + if (_rescued_oops != NULL) {
  1551. +
  1552. + for (int i=0; i<_rescued_oops->length(); i++) {
  1553. + oop rescued_obj = _rescued_oops->at(i);
  1554. +
  1555. + int size = rescued_obj->size();
  1556. + oop new_obj = rescued_obj->forwardee();
  1557. +
  1558. + if (rescued_obj->blueprint()->new_version() != NULL) {
  1559. + MarkSweep::update_fields(rescued_obj, new_obj);
  1560. + } else {
  1561. + Copy::aligned_disjoint_words((HeapWord*)rescued_obj, (HeapWord*)new_obj, size);
  1562. + }
  1563. +
  1564. + FREE_RESOURCE_ARRAY(HeapWord, rescued_obj, size);
  1565. +
  1566. + new_obj->init_mark();
  1567. + assert(new_obj->is_oop(), "must be a valid oop");
  1568. + }
  1569. + _rescued_oops->clear();
  1570. + _rescued_oops = NULL;
  1571. + }
  1572. +}
  1573. +
  1574. +// (tw) Update instances of a class whose fields changed.
  1575. +void MarkSweep::update_fields(oop q, oop new_location) {
  1576. +
  1577. + assert(q->blueprint()->new_version() != NULL, "class of old object must have new version");
  1578. +
  1579. + klassOop old_klass_oop = q->klass();
  1580. + klassOop new_klass_oop = q->blueprint()->new_version();
  1581. +
  1582. + instanceKlass *old_klass = instanceKlass::cast(old_klass_oop);
  1583. + instanceKlass *new_klass = instanceKlass::cast(new_klass_oop);
  1584. +
  1585. + int size = q->size_given_klass(old_klass);
  1586. + int new_size = q->size_given_klass(new_klass);
  1587. +
  1588. + oop tmp_obj = q;
  1589. +
  1590. + if (new_klass_oop->klass_part()->is_copying_backwards()) {
  1591. + if (((HeapWord *)q >= (HeapWord *)new_location && (HeapWord *)q < (HeapWord *)new_location + new_size) ||
  1592. + ((HeapWord *)new_location >= (HeapWord *)q && (HeapWord *)new_location < (HeapWord *)q + size)) {
  1593. + tmp_obj = (oop)resource_allocate_bytes(size * HeapWordSize);
  1594. + Copy::aligned_disjoint_words((HeapWord*)q, (HeapWord*)tmp_obj, size);
  1595. + }
  1596. + }
  1597. +
  1598. + int *cur = new_klass_oop->klass_part()->update_information();
  1599. +
  1600. + tmp_obj->set_klass_no_check(new_klass_oop);
  1601. +
  1602. + if (cur == NULL) {
  1603. + assert(size == new_size, "just checking");
  1604. + Copy::conjoint_words(((HeapWord *)tmp_obj), ((HeapWord *)new_location), size);
  1605. + } else {
  1606. + int destOffset = 0;
  1607. + while (*cur != 0) {
  1608. + if (*cur > 0) {
  1609. + int size = *cur;
  1610. + cur++;
  1611. + int offset = *cur;
  1612. + Copy::conjoint_jbytes(((char *)tmp_obj) + offset, ((char *)new_location) + destOffset, size);
  1613. + destOffset += size;
  1614. + cur++;
  1615. + } else {
  1616. + assert(*cur < 0, "");
  1617. + int skip = -*cur;
  1618. + Copy::fill_to_bytes(((char*)new_location) + destOffset, skip, 0);
  1619. + destOffset += skip;
  1620. + cur++;
  1621. + }
  1622. + }
  1623. + }
  1624. +
  1625. + if (tmp_obj != q) {
  1626. + FREE_RESOURCE_ARRAY(HeapWord, tmp_obj, size);
  1627. + }
  1628. +}
  1629. diff --git a/src/share/vm/gc_implementation/shared/markSweep.hpp b/src/share/vm/gc_implementation/shared/markSweep.hpp
  1630. index eb8252c..b96a677 100644
  1631. --- a/src/share/vm/gc_implementation/shared/markSweep.hpp
  1632. +++ b/src/share/vm/gc_implementation/shared/markSweep.hpp
  1633. @@ -117,7 +117,11 @@
  1634. friend class AdjustPointerClosure;
  1635. friend class KeepAliveClosure;
  1636. friend class VM_MarkSweep;
  1637. + friend class GenMarkSweep;
  1638. friend void marksweep_init();
  1639. +
  1640. +public:
  1641. + static GrowableArray<oop>* _rescued_oops;
  1642. //
  1643. // Vars
  1644. @@ -208,6 +212,8 @@
  1645. template <class T> static inline void mark_and_push(T* p);
  1646. static inline void push_objarray(oop obj, size_t index);
  1647. + static void copy_rescued_objects_back();
  1648. + static void update_fields(oop q, oop new_location);
  1649. static void follow_stack(); // Empty marking stack.
  1650. static void preserve_mark(oop p, markOop mark);
  1651. diff --git a/src/share/vm/interpreter/interpreterRuntime.cpp b/src/share/vm/interpreter/interpreterRuntime.cpp
  1652. index 1a1af1b..94972f0 100644
  1653. --- a/src/share/vm/interpreter/interpreterRuntime.cpp
  1654. +++ b/src/share/vm/interpreter/interpreterRuntime.cpp
  1655. @@ -402,7 +402,7 @@
  1656. assert(h_exception.not_null(), "NULL exceptions should be handled by athrow");
  1657. assert(h_exception->is_oop(), "just checking");
  1658. // Check that exception is a subclass of Throwable, otherwise we have a VerifyError
  1659. - if (!(h_exception->is_a(SystemDictionary::Throwable_klass()))) {
  1660. + if (!(h_exception->is_a(SystemDictionary::Throwable_klass()->klass_part()->newest_version())) && !(h_exception->is_a(SystemDictionary::Throwable_klass()))) {
  1661. if (ExitVMOnVerifyError) vm_exit(-1);
  1662. ShouldNotReachHere();
  1663. }
  1664. @@ -656,6 +656,82 @@
  1665. JvmtiExport::post_raw_breakpoint(thread, method, bcp);
  1666. IRT_END
  1667. +// (tw) Correctly resolve method when running old code.
  1668. +IRT_ENTRY(void, InterpreterRuntime::forward_method(JavaThread *thread))
  1669. + {
  1670. + MonitorLockerEx ml(RedefinitionSync_lock);
  1671. + while (Threads::wait_at_instrumentation_entry()) {
  1672. + ml.wait();
  1673. + }
  1674. + }
  1675. + frame f = last_frame(thread);
  1676. + methodOop m = f.interpreter_frame_method();
  1677. + methodOop forward_method = m->forward_method();
  1678. + if (forward_method != NULL) {
  1679. + int bci = f.interpreter_frame_bci();
  1680. +
  1681. + if (TraceRedefineClasses >= 3) {
  1682. + tty->print_cr("Executing NOP in method %s at bci %d %d", m->name()->as_C_string(), bci, m->is_in_code_section(bci + 1));
  1683. + }
  1684. +
  1685. + int next_bci = bci - 1;
  1686. + // First try bci before NOP.
  1687. + if (!m->is_in_code_section(next_bci)) {
  1688. + // Try bci after NOP.
  1689. + next_bci = bci + 1;
  1690. + if (!m->is_in_code_section(next_bci)) return;
  1691. + }
  1692. +
  1693. + int new_bci = m->calculate_forward_bci(next_bci, forward_method);
  1694. + if (TraceRedefineClasses >= 2) {
  1695. + tty->print_cr("Transferring execution of %s to new method old_bci=%d new_bci=%d", forward_method->name()->as_C_string(), bci, new_bci);
  1696. + }
  1697. + RegisterMap reg_map(thread);
  1698. + vframe* vf = vframe::new_vframe(&f, &reg_map, thread);
  1699. + interpretedVFrame *iframe = (interpretedVFrame *)vf;
  1700. + iframe->set_method(forward_method, new_bci - 1);
  1701. + }
  1702. +IRT_END
  1703. +
  1704. +// (tw) Correctly resolve method when running old code.
  1705. +IRT_ENTRY(void, InterpreterRuntime::find_correct_method(JavaThread *thread, oopDesc* receiverOop, int vTableIndex))
  1706. + // extract receiver from the outgoing argument list if necessary
  1707. + Handle receiver(thread, receiverOop);
  1708. +
  1709. + // TODO: Check for invokeinterface!
  1710. + Bytecodes::Code bytecode = Bytecodes::_invokevirtual;
  1711. +
  1712. + int method_holder_revision_number = method(thread)->method_holder()->klass_part()->revision_number();
  1713. + klassOop klass = receiverOop->klass();
  1714. + while (klass->klass_part()->revision_number() > method_holder_revision_number) {
  1715. + klass = klass->klass_part()->old_version();
  1716. + }
  1717. +
  1718. + // TODO: Check for correctness if different vtable indices in different versions?
  1719. +
  1720. + methodOop method = ((instanceKlass *)klass->klass_part())->method_at_vtable(vTableIndex);
  1721. + thread->set_vm_result(method);
  1722. +IRT_END
  1723. +
  1724. +// Correctly resolve interface method when running old code.
  1725. +IRT_ENTRY(void, InterpreterRuntime::find_correct_interface_method(JavaThread *thread, oopDesc* receiverOop, oopDesc* interface_klass, int vTableIndex))
  1726. +
  1727. + // extract receiver from the outgoing argument list if necessary
  1728. + Handle receiver(thread, receiverOop);
  1729. +
  1730. + // TODO: Check for invokeinterface!
  1731. + Bytecodes::Code bytecode = Bytecodes::_invokevirtual;
  1732. +
  1733. + int method_holder_revision_number = method(thread)->method_holder()->klass_part()->revision_number();
  1734. + klassOop klass = receiverOop->klass();
  1735. + while (klass->klass_part()->revision_number() > method_holder_revision_number) {
  1736. + klass = klass->klass_part()->old_version();
  1737. + }
  1738. +
  1739. + methodOop method = ((instanceKlass *)klass->klass_part())->method_at_itable((klassOop)interface_klass, vTableIndex, THREAD);
  1740. + thread->set_vm_result(method);
  1741. +IRT_END
  1742. +
  1743. IRT_ENTRY(void, InterpreterRuntime::resolve_invoke(JavaThread* thread, Bytecodes::Code bytecode)) {
  1744. // extract receiver from the outgoing argument list if necessary
  1745. Handle receiver(thread, NULL);
  1746. @@ -684,6 +760,10 @@
  1747. if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
  1748. int retry_count = 0;
  1749. while (info.resolved_method()->is_old()) {
  1750. + // (tw) If we are executing an old method, this is OK!
  1751. + if (method(thread)->is_old()) {
  1752. + break;
  1753. + }
  1754. // It is very unlikely that method is redefined more than 100 times
  1755. // in the middle of resolve. If it is looping here more than 100 times
  1756. // means then there could be a bug here.
  1757. diff --git a/src/share/vm/interpreter/interpreterRuntime.hpp b/src/share/vm/interpreter/interpreterRuntime.hpp
  1758. index 6d5f13a..50fa219 100644
  1759. --- a/src/share/vm/interpreter/interpreterRuntime.hpp
  1760. +++ b/src/share/vm/interpreter/interpreterRuntime.hpp
  1761. @@ -141,6 +141,9 @@
  1762. static void post_method_entry(JavaThread *thread);
  1763. static void post_method_exit (JavaThread *thread);
  1764. static int interpreter_contains(address pc);
  1765. + static void forward_method(JavaThread *thread);
  1766. + static void find_correct_method(JavaThread *thread, oopDesc* receiver, int vTableIndex);
  1767. + static void find_correct_interface_method(JavaThread *thread, oopDesc* receiver, oopDesc* interface_klass, int vTableIndex);
  1768. // Native signature handlers
  1769. static void prepare_native_call(JavaThread* thread, methodOopDesc* method);
  1770. diff --git a/src/share/vm/interpreter/linkResolver.cpp b/src/share/vm/interpreter/linkResolver.cpp
  1771. index 1676add..ccd5241 100644
  1772. --- a/src/share/vm/interpreter/linkResolver.cpp
  1773. +++ b/src/share/vm/interpreter/linkResolver.cpp
  1774. @@ -153,8 +153,8 @@
  1775. // Klass resolution
  1776. void LinkResolver::check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS) {
  1777. - if (!Reflection::verify_class_access(ref_klass->as_klassOop(),
  1778. - sel_klass->as_klassOop(),
  1779. + if (!Reflection::verify_class_access(ref_klass->as_klassOop()->klass_part()->newest_version(),
  1780. + sel_klass->as_klassOop()->klass_part()->newest_version(),
  1781. true)) {
  1782. ResourceMark rm(THREAD);
  1783. Exceptions::fthrow(
  1784. @@ -346,7 +346,7 @@
  1785. // We'll check for the method name first, as that's most likely
  1786. // to be false (so we'll short-circuit out of these tests).
  1787. if (sel_method->name() == vmSymbols::clone_name() &&
  1788. - sel_klass() == SystemDictionary::Object_klass() &&
  1789. + sel_klass()->klass_part()->newest_version() == SystemDictionary::Object_klass()->klass_part()->newest_version() &&
  1790. resolved_klass->oop_is_array()) {
  1791. // We need to change "protected" to "public".
  1792. assert(flags.is_protected(), "clone not protected?");
  1793. @@ -412,6 +412,154 @@
  1794. }
  1795. }
  1796. +
  1797. +void LinkResolver::lookup_method(methodHandle& resolved_method, KlassHandle resolved_klass,
  1798. + Symbol* method_name, Symbol* method_signature, bool is_interface, KlassHandle current_klass, TRAPS) {
  1799. +
  1800. + // Interface method lookup?
  1801. + if (is_interface) {
  1802. +
  1803. + // lookup method in this interface or its super, java.lang.Object
  1804. + lookup_instance_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1805. +
  1806. + if (resolved_method.is_null() && !resolved_klass->oop_is_array()) {
  1807. + // lookup method in all the super-interfaces
  1808. + lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1809. + }
  1810. +
  1811. + // Other methods
  1812. + } else {
  1813. + Handle nested_exception;
  1814. +
  1815. + // 2. lookup method in resolved klass and its super klasses
  1816. + lookup_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1817. +
  1818. + if (resolved_method.is_null() && !resolved_klass->oop_is_array()) { // not found in the class hierarchy
  1819. + // 3. lookup method in all the interfaces implemented by the resolved klass
  1820. + lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1821. +
  1822. + if (resolved_method.is_null()) {
  1823. + // JSR 292: see if this is an implicitly generated method MethodHandle.linkToVirtual(*...), etc
  1824. + lookup_polymorphic_method(resolved_method, resolved_klass, method_name, method_signature,
  1825. + current_klass, (Handle*)NULL, (Handle*)NULL, THREAD);
  1826. + if (HAS_PENDING_EXCEPTION) {
  1827. + nested_exception = Handle(THREAD, PENDING_EXCEPTION);
  1828. + CLEAR_PENDING_EXCEPTION;
  1829. + }
  1830. + }
  1831. + }
  1832. + }
  1833. +}
  1834. +
  1835. +void LinkResolver::lookup_correct_field(fieldDescriptor &fd, KlassHandle &sel_klass, KlassHandle resolved_klass, KlassHandle current_klass, Symbol* field_name, Symbol* field_sig, bool is_static) {
  1836. +
  1837. + // First attempt unversioned
  1838. + sel_klass = KlassHandle(Thread::current(), resolved_klass->find_field(field_name, field_sig, &fd));
  1839. +
  1840. + if (!current_klass.is_null() && !current_klass->is_newest_version()) {
  1841. +
  1842. + // 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).
  1843. + int redefinition_policy = current_klass->new_version()->klass_part()->field_redefinition_policy();
  1844. + if (is_static) {
  1845. + redefinition_policy = current_klass->new_version()->klass_part()->static_field_redefinition_policy();
  1846. + }
  1847. +
  1848. + assert(redefinition_policy != Klass::StaticCheck, "if the policy is static check, then we can never reach here");
  1849. +
  1850. + if (redefinition_policy != Klass::DynamicCheck) {
  1851. +
  1852. + if (redefinition_policy == Klass::AccessOldMembers) {
  1853. + // Forget looked up fields
  1854. + sel_klass = KlassHandle(Thread::current(), (oop)NULL);
  1855. + }
  1856. +
  1857. + assert(redefinition_policy == Klass::AccessOldMembers || redefinition_policy == Klass::AccessDeletedMembers, "");
  1858. +
  1859. + if (sel_klass.is_null() || fd.is_static() != is_static /* access old static field field is changed from static to non-static */) {
  1860. +
  1861. + // Select correct version for resolved klass.
  1862. + find_correct_resolved_klass(resolved_klass, current_klass);
  1863. +
  1864. + sel_klass = KlassHandle(Thread::current(), instanceKlass::cast(resolved_klass())->find_field(field_name, field_sig, &fd));
  1865. +
  1866. + // FIXME: idubrov
  1867. + //if (sel_klass.is_null()) {
  1868. + // TRACE_RC2("Trying to resolve field (%s) in old universe failed => exception is the correct behaviour", field_name->as_C_string());
  1869. + //} else {
  1870. + // assert(sel_klass->new_version() != NULL, "must be old class!");
  1871. + // TRACE_RC2("Resolved a field in the old universe (%s)!", field_name->as_C_string());
  1872. + //}
  1873. + }
  1874. + }
  1875. + }
  1876. +}
  1877. +
  1878. +void LinkResolver::lookup_correct_method(methodHandle& resolved_method, KlassHandle resolved_klass, KlassHandle current_klass,
  1879. + Symbol* method_name, Symbol* method_signature, bool is_interface, TRAPS) {
  1880. +
  1881. + // First attempt unversioned
  1882. + lookup_method(resolved_method, resolved_klass, method_name, method_signature, is_interface, current_klass, CHECK);
  1883. +
  1884. + // (tw) Are we in an old method that wants to see a different view on the world?
  1885. + if (!current_klass.is_null() && !current_klass->is_newest_version()) {
  1886. +
  1887. + // 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).
  1888. + int method_redefinition_policy = current_klass->new_version()->klass_part()->method_redefinition_policy();
  1889. + assert(method_redefinition_policy != Klass::StaticCheck, "if the policy is static check, then we can never reach here");
  1890. +
  1891. + if (method_redefinition_policy != Klass::DynamicCheck) {
  1892. +
  1893. + // We do not throw the exception
  1894. + if (method_redefinition_policy == Klass::AccessOldMembers) {
  1895. + // Forget any new member lookup
  1896. + resolved_method = methodHandle(THREAD, NULL);
  1897. + }
  1898. +
  1899. + assert(method_redefinition_policy == Klass::AccessOldMembers || method_redefinition_policy == Klass::AccessDeletedMembers, "");
  1900. +
  1901. + if (resolved_method.is_null()) {
  1902. +
  1903. + // Select correct version for resolved klass.
  1904. + find_correct_resolved_klass(resolved_klass, current_klass);
  1905. +
  1906. + // Now do the lookup in a second attempt with a different resolved klass.
  1907. + lookup_method(resolved_method, resolved_klass, method_name, method_signature, is_interface, current_klass, CHECK);
  1908. +
  1909. + // FIXME: idubrov
  1910. + //IF_TRACE_RC2 {
  1911. + // ResourceMark rm(THREAD);
  1912. + // if (resolved_method.is_null()) {
  1913. + // TRACE_RC2("Trying to resolve method (%s) in old universe failed => exception is the correct behaviour", method_name->as_C_string());
  1914. + // } else {
  1915. + // assert(resolved_method->is_old(), "must be old method!");
  1916. + // TRACE_RC2("Resolved a method in the old universe (%s)!", resolved_method->name()->as_C_string());
  1917. + // }
  1918. + //}
  1919. + }
  1920. + }
  1921. + }
  1922. +
  1923. + if (resolved_method.is_null()) {
  1924. + // no method found
  1925. + ResourceMark rm(THREAD);
  1926. + THROW_MSG(vmSymbols::java_lang_NoSuchMethodError(),
  1927. + methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()),
  1928. + method_name,
  1929. + method_signature));
  1930. + }
  1931. +}
  1932. +
  1933. +void LinkResolver::find_correct_resolved_klass(KlassHandle &resolved_klass, KlassHandle &current_klass) {
  1934. + int current_klass_revision = current_klass->revision_number();
  1935. + int resolved_klass_revision = resolved_klass->revision_number();
  1936. + // FIXME: idubrov
  1937. + //TRACE_RC2("The two different revision numbers for interfaces: current=%d / resolved_callee=%d", current_klass_revision, resolved_klass_revision);
  1938. +
  1939. + while (resolved_klass->revision_number() > current_klass_revision) {
  1940. + assert(resolved_klass->old_version(), "must have old version");
  1941. + resolved_klass = KlassHandle(Thread::current(), resolved_klass->old_version());
  1942. + }
  1943. +}
  1944. void LinkResolver::resolve_method(methodHandle& resolved_method, KlassHandle resolved_klass,
  1945. Symbol* method_name, Symbol* method_signature,
  1946. KlassHandle current_klass, bool check_access, TRAPS) {
  1947. @@ -424,35 +572,8 @@
  1948. THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
  1949. }
  1950. - Handle nested_exception;
  1951. -
  1952. - // 2. lookup method in resolved klass and its super klasses
  1953. - lookup_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1954. -
  1955. - if (resolved_method.is_null() && !resolved_klass->oop_is_array()) { // not found in the class hierarchy
  1956. - // 3. lookup method in all the interfaces implemented by the resolved klass
  1957. - lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1958. -
  1959. - if (resolved_method.is_null()) {
  1960. - // JSR 292: see if this is an implicitly generated method MethodHandle.linkToVirtual(*...), etc
  1961. - lookup_polymorphic_method(resolved_method, resolved_klass, method_name, method_signature,
  1962. - current_klass, (Handle*)NULL, (Handle*)NULL, THREAD);
  1963. - if (HAS_PENDING_EXCEPTION) {
  1964. - nested_exception = Handle(THREAD, PENDING_EXCEPTION);
  1965. - CLEAR_PENDING_EXCEPTION;
  1966. - }
  1967. - }
  1968. - }
  1969. -
  1970. - if (resolved_method.is_null()) {
  1971. - // 4. method lookup failed
  1972. - ResourceMark rm(THREAD);
  1973. - THROW_MSG_CAUSE(vmSymbols::java_lang_NoSuchMethodError(),
  1974. - methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()),
  1975. - method_name,
  1976. - method_signature),
  1977. - nested_exception);
  1978. - }
  1979. + // 2. and 3. and 4. lookup method in resolved klass and its super klasses
  1980. + lookup_correct_method(resolved_method, resolved_klass, current_klass, method_name, method_signature, false, CHECK);
  1981. // 5. check if method is concrete
  1982. if (resolved_method->is_abstract() && !resolved_klass->is_abstract()) {
  1983. @@ -520,7 +641,10 @@
  1984. }
  1985. // lookup method in this interface or its super, java.lang.Object
  1986. - lookup_instance_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  1987. + lookup_correct_method(resolved_method, resolved_klass, current_klass, method_name, method_signature, true, CHECK);
  1988. +
  1989. +
  1990. +
  1991. if (resolved_method.is_null() && !resolved_klass->oop_is_array()) {
  1992. // lookup method in all the super-interfaces
  1993. @@ -621,9 +745,14 @@
  1994. THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string());
  1995. }
  1996. + KlassHandle ref_klass(THREAD, pool->pool_holder()->klass_part());
  1997. +
  1998. // Resolve instance field
  1999. fieldDescriptor fd; // find_field initializes fd if found
  2000. - KlassHandle sel_klass(THREAD, resolved_klass->find_field(field, sig, &fd));
  2001. +
  2002. + KlassHandle sel_klass;
  2003. + lookup_correct_field(fd, sel_klass, resolved_klass, ref_klass, field, sig, is_static);
  2004. +
  2005. // check if field exists; i.e., if a klass containing the field def has been selected
  2006. if (sel_klass.is_null()){
  2007. ResourceMark rm(THREAD);
  2008. @@ -631,7 +760,6 @@
  2009. }
  2010. // check access
  2011. - KlassHandle ref_klass(THREAD, pool->pool_holder());
  2012. check_field_accessability(ref_klass, resolved_klass, sel_klass, fd, CHECK);
  2013. // check for errors
  2014. @@ -643,7 +771,7 @@
  2015. }
  2016. // Final fields can only be accessed from its own class.
  2017. - if (is_put && fd.access_flags().is_final() && sel_klass() != pool->pool_holder()) {
  2018. + if (is_put && fd.access_flags().is_final() && sel_klass() != pool->pool_holder()->klass_part()->active_version() && sel_klass() != pool->pool_holder()) {
  2019. THROW(vmSymbols::java_lang_IllegalAccessError());
  2020. }
  2021. @@ -848,7 +976,7 @@
  2022. bool check_access, bool check_null_and_abstract, TRAPS) {
  2023. methodHandle resolved_method;
  2024. linktime_resolve_virtual_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK);
  2025. - runtime_resolve_virtual_method(result, resolved_method, resolved_klass, recv, receiver_klass, check_null_and_abstract, CHECK);
  2026. + runtime_resolve_virtual_method(result, resolved_method, resolved_klass, recv, receiver_klass, current_klass, check_null_and_abstract, CHECK);
  2027. }
  2028. // throws linktime exceptions
  2029. @@ -878,6 +1006,7 @@
  2030. KlassHandle resolved_klass,
  2031. Handle recv,
  2032. KlassHandle recv_klass,
  2033. + KlassHandle current_klass,
  2034. bool check_null_and_abstract,
  2035. TRAPS) {
  2036. @@ -926,10 +1055,44 @@
  2037. // recv_klass might be an arrayKlassOop but all vtables start at
  2038. // the same place. The cast is to avoid virtual call and assertion.
  2039. instanceKlass* inst = (instanceKlass*)recv_klass()->klass_part();
  2040. - selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index));
  2041. +
  2042. + // (tw) The type of the virtual method call and the type of the receiver do not need to
  2043. + // have anything in common, as the receiver type could've been hotswapped.
  2044. + // Does not always work (method could be resolved with correct dynamic type and later
  2045. + // be called at the same place with a wrong dynamic type).
  2046. + // (tw) TODO: Need to handle the static type vs dynamic type issue more generally.
  2047. +
  2048. + // The vTable must be based on the view of the world of the resolved method
  2049. + klassOop method_holder = resolved_method->method_holder();
  2050. +
  2051. + if (method_holder->klass_part()->new_version() != NULL) {
  2052. + // We are executing in old code
  2053. + // FIXME: idubrov
  2054. + //TRACE_RC2("Calling a method in old code");
  2055. + while (method_holder->klass_part()->revision_number() < inst->revision_number()) {
  2056. + inst = (instanceKlass *)(inst->old_version()->klass_part());
  2057. + }
  2058. + }
  2059. +
  2060. + if (inst->is_subtype_of(method_holder)) {
  2061. + selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index));
  2062. + } else {
  2063. +
  2064. + tty->print_cr("Failure:");
  2065. + inst->as_klassOop()->print();
  2066. + inst->super()->print();
  2067. + juint off = inst->super_check_offset();
  2068. + klassOop sup = *(klassOop*)( (address)inst->as_klassOop() + off );
  2069. + sup->print();
  2070. + method_holder->print();
  2071. +
  2072. + bool b = inst->is_subtype_of(method_holder);
  2073. + 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!");
  2074. + }
  2075. }
  2076. }
  2077. +
  2078. // check if method exists
  2079. if (selected_method.is_null()) {
  2080. ResourceMark rm(THREAD);
  2081. diff --git a/src/share/vm/interpreter/linkResolver.hpp b/src/share/vm/interpreter/linkResolver.hpp
  2082. index dfd74f9..cf6e44a 100644
  2083. --- a/src/share/vm/interpreter/linkResolver.hpp
  2084. +++ b/src/share/vm/interpreter/linkResolver.hpp
  2085. @@ -110,7 +110,11 @@
  2086. // It does all necessary link-time checks & throws exceptions if necessary.
  2087. class LinkResolver: AllStatic {
  2088. - private:
  2089. +private:
  2090. + static void lookup_method (methodHandle& result, KlassHandle resolved_klass, Symbol* name, Symbol* signature, bool is_interface, KlassHandle current_klass, TRAPS);
  2091. + 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);
  2092. + static void lookup_correct_method (methodHandle& result, KlassHandle resolved_klass, KlassHandle current_klass, Symbol* name, Symbol* signature, bool is_interface, TRAPS);
  2093. + static void find_correct_resolved_klass (KlassHandle &resolved_klass, KlassHandle &current_klass);
  2094. static void lookup_method_in_klasses (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
  2095. static void lookup_instance_method_in_klasses (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
  2096. static void lookup_method_in_interfaces (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
  2097. @@ -133,7 +137,7 @@
  2098. 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);
  2099. static void runtime_resolve_special_method (CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, KlassHandle current_klass, bool check_access, TRAPS);
  2100. - 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);
  2101. + 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);
  2102. 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);
  2103. static void check_field_accessability (KlassHandle ref_klass, KlassHandle resolved_klass, KlassHandle sel_klass, fieldDescriptor& fd, TRAPS);
  2104. diff --git a/src/share/vm/interpreter/templateTable.hpp b/src/share/vm/interpreter/templateTable.hpp
  2105. index 17e9f26..e77500f 100644
  2106. --- a/src/share/vm/interpreter/templateTable.hpp
  2107. +++ b/src/share/vm/interpreter/templateTable.hpp
  2108. @@ -329,8 +329,8 @@
  2109. static void shouldnotreachhere();
  2110. // jvmti support
  2111. - static void jvmti_post_field_access(Register cache, Register index, bool is_static, bool has_tos);
  2112. - static void jvmti_post_field_mod(Register cache, Register index, bool is_static);
  2113. + static void jvmti_post_field_access(Register cache, Register index, int byte_no, bool is_static, bool has_tos);
  2114. + static void jvmti_post_field_mod(Register cache, Register index, int byte_no, bool is_static);
  2115. static void jvmti_post_fast_field_mod();
  2116. // debugging of TemplateGenerator
  2117. diff --git a/src/share/vm/memory/genMarkSweep.cpp b/src/share/vm/memory/genMarkSweep.cpp
  2118. index 76e18d8..6af7c14 100644
  2119. --- a/src/share/vm/memory/genMarkSweep.cpp
  2120. +++ b/src/share/vm/memory/genMarkSweep.cpp
  2121. @@ -421,6 +421,7 @@
  2122. // in the same order in phase2, phase3 and phase4. We don't quite do that
  2123. // here (perm_gen first rather than last), so we tell the validate code
  2124. // to use a higher index (saved from phase2) when verifying perm_gen.
  2125. + assert(_rescued_oops == NULL, "must be empty before processing");
  2126. GenCollectedHeap* gch = GenCollectedHeap::heap();
  2127. Generation* pg = gch->perm_gen();
  2128. @@ -433,10 +434,14 @@
  2129. VALIDATE_MARK_SWEEP_ONLY(reset_live_oop_tracking(false));
  2130. + MarkSweep::copy_rescued_objects_back();
  2131. +
  2132. GenCompactClosure blk;
  2133. gch->generation_iterate(&blk, true);
  2134. VALIDATE_MARK_SWEEP_ONLY(compaction_complete());
  2135. + MarkSweep::copy_rescued_objects_back();
  2136. +
  2137. pg->post_compact(); // Shared spaces verification.
  2138. }
  2139. diff --git a/src/share/vm/memory/permGen.cpp b/src/share/vm/memory/permGen.cpp
  2140. index 350f583..59faad1 100644
  2141. --- a/src/share/vm/memory/permGen.cpp
  2142. +++ b/src/share/vm/memory/permGen.cpp
  2143. @@ -57,7 +57,12 @@
  2144. for (;;) {
  2145. {
  2146. - MutexLocker ml(Heap_lock);
  2147. + // (tw) Only lock when not at a safepoint (necessary to use the split verifier from the VmThread)
  2148. + Monitor *lock = Heap_lock;
  2149. + if (SafepointSynchronize::is_at_safepoint()) {
  2150. + lock = NULL;
  2151. + }
  2152. + MutexLockerEx ml(lock);
  2153. if ((obj = gen->allocate(size, false)) != NULL) {
  2154. return obj;
  2155. }
  2156. diff --git a/src/share/vm/memory/space.cpp b/src/share/vm/memory/space.cpp
  2157. index f97bc34..9b20d08 100644
  2158. --- a/src/share/vm/memory/space.cpp
  2159. +++ b/src/share/vm/memory/space.cpp
  2160. @@ -378,6 +378,31 @@
  2161. _compaction_top = bottom();
  2162. }
  2163. +// (tw) Calculates the compact_top that will be used for placing the next object with the giving size on the heap.
  2164. +HeapWord* CompactibleSpace::forward_compact_top(size_t size,
  2165. +CompactPoint* cp, HeapWord* compact_top) {
  2166. + // First check if we should switch compaction space
  2167. + assert(this == cp->space, "'this' should be current compaction space.");
  2168. + size_t compaction_max_size = pointer_delta(end(), compact_top);
  2169. + while (size > compaction_max_size) {
  2170. + // switch to next compaction space
  2171. + cp->space->set_compaction_top(compact_top);
  2172. + cp->space = cp->space->next_compaction_space();
  2173. + if (cp->space == NULL) {
  2174. + cp->gen = GenCollectedHeap::heap()->prev_gen(cp->gen);
  2175. + assert(cp->gen != NULL, "compaction must succeed");
  2176. + cp->space = cp->gen->first_compaction_space();
  2177. + assert(cp->space != NULL, "generation must have a first compaction space");
  2178. + }
  2179. + compact_top = cp->space->bottom();
  2180. + cp->space->set_compaction_top(compact_top);
  2181. + cp->threshold = cp->space->initialize_threshold();
  2182. + compaction_max_size = pointer_delta(cp->space->end(), compact_top);
  2183. + }
  2184. +
  2185. + return compact_top;
  2186. +}
  2187. +
  2188. HeapWord* CompactibleSpace::forward(oop q, size_t size,
  2189. CompactPoint* cp, HeapWord* compact_top) {
  2190. // q is alive
  2191. @@ -401,7 +426,7 @@
  2192. }
  2193. // store the forwarding pointer into the mark word
  2194. - if ((HeapWord*)q != compact_top) {
  2195. + if ((HeapWord*)q != compact_top || (size_t)q->size() != size) {
  2196. q->forward_to(oop(compact_top));
  2197. assert(q->is_gc_marked(), "encoding the pointer should preserve the mark");
  2198. } else {
  2199. @@ -449,7 +474,208 @@
  2200. // Faster object search.
  2201. void ContiguousSpace::prepare_for_compaction(CompactPoint* cp) {
  2202. - SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size);
  2203. + if (!Universe::is_redefining_gc_run()) {
  2204. + SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size);
  2205. + return;
  2206. + }
  2207. +
  2208. + /* Compute the new addresses for the live objects and store it in the mark
  2209. + * Used by universe::mark_sweep_phase2()
  2210. + */
  2211. + HeapWord* compact_top; /* This is where we are currently compacting to. */
  2212. +
  2213. + /* We're sure to be here before any objects are compacted into this
  2214. + * space, so this is a good time to initialize this:
  2215. + */
  2216. + set_compaction_top(bottom());
  2217. +
  2218. + if (cp->space == NULL) {
  2219. + assert(cp->gen != NULL, "need a generation");
  2220. + assert(cp->threshold == NULL, "just checking");
  2221. + assert(cp->gen->first_compaction_space() == this, "just checking");
  2222. + cp->space = cp->gen->first_compaction_space();
  2223. + compact_top = cp->space->bottom();
  2224. + cp->space->set_compaction_top(compact_top);
  2225. + cp->threshold = cp->space->initialize_threshold();
  2226. + } else {
  2227. + compact_top = cp->space->compaction_top();
  2228. + }
  2229. +
  2230. + /* We allow some amount of garbage towards the bottom of the space, so
  2231. + * we don't start compacting before there is a significant gain to be made.
  2232. + * Occasionally, we want to ensure a full compaction, which is determined
  2233. + * by the MarkSweepAlwaysCompactCount parameter.
  2234. + */
  2235. + int invocations = SharedHeap::heap()->perm_gen()->stat_record()->invocations;
  2236. + bool skip_dead = (MarkSweepAlwaysCompactCount < 1)
  2237. + ||((invocations % MarkSweepAlwaysCompactCount) != 0);
  2238. +
  2239. + size_t allowed_deadspace = 0;
  2240. + if (skip_dead) {
  2241. + int ratio = (int)allowed_dead_ratio();
  2242. + allowed_deadspace = (capacity() * ratio / 100) / HeapWordSize;
  2243. + }
  2244. +
  2245. + HeapWord* q = bottom();
  2246. + HeapWord* t = end();
  2247. +
  2248. + HeapWord* end_of_live= q; /* One byte beyond the last byte of the last
  2249. + live object. */
  2250. + HeapWord* first_dead = end();/* The first dead object. */
  2251. + LiveRange* liveRange = NULL; /* The current live range, recorded in the
  2252. + first header of preceding free area. */
  2253. + _first_dead = first_dead;
  2254. +
  2255. + const intx interval = PrefetchScanIntervalInBytes;
  2256. +
  2257. + while (q < t) {
  2258. + assert(!block_is_obj(q) ||
  2259. + oop(q)->mark()->is_marked() || oop(q)->mark()->is_unlocked() ||
  2260. + oop(q)->mark()->has_bias_pattern(),
  2261. + "these are the only valid states during a mark sweep");
  2262. + if (block_is_obj(q) && oop(q)->is_gc_marked()) {
  2263. + /* prefetch beyond q */
  2264. + Prefetch::write(q, interval);
  2265. + /* size_t size = oop(q)->size(); changing this for cms for perm gen */
  2266. + size_t size = block_size(q);
  2267. +
  2268. + // DCEVM: begin
  2269. + //////////////////////////////////////////////////////////////////////////
  2270. + size_t forward_size = size;
  2271. +
  2272. + // Compute the forward sizes and leave out objects whose position could
  2273. + // possibly overlap other objects.
  2274. +
  2275. + // DCEVM: There is a new version of the class of q => different size
  2276. + if (oop(q)->blueprint()->new_version() != NULL && oop(q)->blueprint()->new_version()->klass_part()->update_information() != NULL) {
  2277. +
  2278. + size_t new_size = oop(q)->size_given_klass(oop(q)->blueprint()->new_version()->klass_part());
  2279. + assert(size != new_size || oop(q)->is_perm(), "instances without changed size have to be updated prior to GC run");
  2280. + forward_size = new_size;
  2281. + }
  2282. +
  2283. + compact_top = cp->space->forward_compact_top(forward_size, cp, compact_top);
  2284. +
  2285. + bool rescueing = false;
  2286. + if (rescueing = must_rescue(oop(q), oop(compact_top))) {
  2287. + if (MarkSweep::_rescued_oops == NULL) {
  2288. + MarkSweep::_rescued_oops = new GrowableArray<oop>(128);
  2289. + }
  2290. + // FIXME: idubrov
  2291. + //TRACE_RC5("rescue obj %d klass=%s", MarkSweep::_rescued_oops->length(), oop(q)->klass()->klass_part()->name()->as_C_string());
  2292. + MarkSweep::_rescued_oops->append(oop(q));
  2293. + } else {
  2294. + compact_top = cp->space->forward(oop(q), forward_size, cp, compact_top);
  2295. + }
  2296. +
  2297. + if ((size != forward_size || rescueing) && q < first_dead) {
  2298. + // (tw) This object moves => first_dead must be set to here!
  2299. + first_dead = q;
  2300. + }
  2301. + //////////////////////////////////////////////////////////////////////////
  2302. + q += size;
  2303. + end_of_live = q;
  2304. + } else {
  2305. + /* run over all the contiguous dead objects */
  2306. + HeapWord* end = q;
  2307. + do {
  2308. + /* prefetch beyond end */
  2309. + Prefetch::write(end, interval);
  2310. + end += block_size(end);
  2311. + } while (end < t && (!block_is_obj(end) || !oop(end)->is_gc_marked()));
  2312. +
  2313. + /* see if we might want to pretend this object is alive so that
  2314. + * we don't have to compact quite as often.
  2315. + */
  2316. + if (allowed_deadspace > 0 && q == compact_top) {
  2317. + size_t sz = pointer_delta(end, q);
  2318. + if (insert_deadspace(allowed_deadspace, q, sz)) {
  2319. + compact_top = cp->space->forward(oop(q), sz, cp, compact_top);
  2320. + q = end;
  2321. + end_of_live = end;
  2322. + continue;
  2323. + }
  2324. + }
  2325. +
  2326. + /* otherwise, it really is a free region. */
  2327. +
  2328. + /* for the previous LiveRange, record the end of the live objects. */
  2329. + if (liveRange) {
  2330. + liveRange->set_end(q);
  2331. + }
  2332. +
  2333. + /* record the current LiveRange object.
  2334. + * liveRange->start() is overlaid on the mark word.
  2335. + */
  2336. + liveRange = (LiveRange*)q;
  2337. + liveRange->set_start(end);
  2338. + liveRange->set_end(end);
  2339. +
  2340. + /* see if this is the first dead region. */
  2341. + if (q < first_dead) {
  2342. + first_dead = q;
  2343. + }
  2344. +
  2345. + /* move on to the next object */
  2346. + q = end;
  2347. + }
  2348. + }
  2349. +
  2350. + //////////////////////////////////////////////////////////////////////////
  2351. + // Compute the forwarding addresses for the objects that need to be
  2352. + // rescued.
  2353. + // TODO: empty the _rescued_oops after ALL spaces are compacted!
  2354. + if (MarkSweep::_rescued_oops != NULL) {
  2355. + // FIXME: idubrov
  2356. + //TRACE_RC2("Calculating new forward sizes for %d objects!", MarkSweep::_rescued_oops->length());
  2357. +
  2358. + for (int i=0; i<MarkSweep::_rescued_oops->length(); i++) {
  2359. + oop q = MarkSweep::_rescued_oops->at(i);
  2360. +
  2361. + /* size_t size = oop(q)->size(); changing this for cms for perm gen */
  2362. + size_t size = block_size((HeapWord*)q);
  2363. +
  2364. + size_t forward_size = size;
  2365. +
  2366. + // (tw) There is a new version of the class of q => different size
  2367. + if (oop(q)->blueprint()->new_version() != NULL) {
  2368. +
  2369. + size_t new_size = oop(q)->size_given_klass(oop(q)->blueprint()->new_version()->klass_part());
  2370. + assert(size != new_size || oop(q)->is_perm(), "instances without changed size have to be updated prior to GC run");
  2371. + forward_size = new_size;
  2372. + }
  2373. +
  2374. + compact_top = cp->space->forward(oop(q), forward_size, cp, compact_top);
  2375. + assert(compact_top <= t, "must not write over end of space!");
  2376. + }
  2377. + MarkSweep::_rescued_oops->clear();
  2378. + MarkSweep::_rescued_oops = NULL;
  2379. + }
  2380. + //////////////////////////////////////////////////////////////////////////
  2381. +
  2382. + assert(q == t, "just checking");
  2383. + if (liveRange != NULL) {
  2384. + liveRange->set_end(q);
  2385. + }
  2386. + _end_of_live = end_of_live;
  2387. + if (end_of_live < first_dead) {
  2388. + first_dead = end_of_live;
  2389. + }
  2390. + _first_dead = first_dead;
  2391. +
  2392. +// FIXME: idubrov
  2393. +// if (_first_dead > top()) {
  2394. +// _first_dead = top();
  2395. +// }
  2396. +//
  2397. +// if (_end_of_live > top()) {
  2398. +// _end_of_live = top();
  2399. +// }
  2400. + assert(_first_dead <= top(), "Must be smaller equal");
  2401. + assert(_end_of_live <= top(), "Must be smaller equal");
  2402. +
  2403. + /* save the compaction_top of the compaction space. */
  2404. + cp->space->set_compaction_top(compact_top);
  2405. }
  2406. void Space::adjust_pointers() {
  2407. @@ -490,17 +716,313 @@
  2408. assert(q == t, "just checking");
  2409. }
  2410. +
  2411. +#ifdef ASSERT
  2412. +
  2413. +int CompactibleSpace::space_index(oop obj) {
  2414. + GenCollectedHeap* heap = GenCollectedHeap::heap();
  2415. +
  2416. + if (heap->is_in_permanent(obj)) {
  2417. + return -1;
  2418. + }
  2419. +
  2420. + int index = 0;
  2421. + for (int i = heap->n_gens() - 1; i >= 0; i--) {
  2422. + Generation* gen = heap->get_gen(i);
  2423. + CompactibleSpace* space = gen->first_compaction_space();
  2424. + while (space != NULL) {
  2425. + if (space->is_in_reserved(obj)) {
  2426. + return index;
  2427. + }
  2428. + space = space->next_compaction_space();
  2429. + index++;
  2430. + }
  2431. + }
  2432. +
  2433. + tty->print_cr("could not compute space_index for %08xh", obj);
  2434. + index = 0;
  2435. + for (int i = heap->n_gens() - 1; i >= 0; i--) {
  2436. + Generation* gen = heap->get_gen(i);
  2437. + tty->print_cr(" generation %s: %08xh - %08xh", gen->name(), gen->reserved().start(), gen->reserved().end());
  2438. +
  2439. + CompactibleSpace* space = gen->first_compaction_space();
  2440. + while (space != NULL) {
  2441. + tty->print_cr(" %2d space %08xh - %08xh", index, space->bottom(), space->end());
  2442. + space = space->next_compaction_space();
  2443. + index++;
  2444. + }
  2445. + }
  2446. +
  2447. + ShouldNotReachHere();
  2448. + return 0;
  2449. +}
  2450. +#endif
  2451. +
  2452. +bool CompactibleSpace::must_rescue(oop old_obj, oop new_obj) {
  2453. +
  2454. + assert(is_in_reserved(old_obj), "old_obj must be in this space");
  2455. +
  2456. + if (old_obj->is_perm()) {
  2457. + // This object is in perm gen; check for invariant obj->klass() <= obj
  2458. + if (oop(old_obj)->blueprint()->new_version() != NULL) {
  2459. + return true;
  2460. + }
  2461. + }
  2462. +
  2463. + int size = old_obj->size();
  2464. + int original_size = size;
  2465. + if (oop(old_obj)->blueprint()->is_redefining()) {
  2466. + assert(oop(old_obj)->blueprint()->old_version() != NULL, "must not be null");
  2467. + original_size = oop(old_obj)->size_given_klass(oop(old_obj)->blueprint()->old_version()->klass_part());
  2468. + } else if (oop(old_obj)->blueprint()->new_version() != NULL) {
  2469. + size = oop(old_obj)->size_given_klass(oop(old_obj)->blueprint()->new_version()->klass_part());
  2470. + }
  2471. +
  2472. + bool normalComparison = (old_obj + original_size < new_obj + size);
  2473. +
  2474. + if (is_in_reserved(new_obj)) {
  2475. + // Old and new address are in same space, so just compare the address.
  2476. + // Must rescue if object moves towards the top of the space.
  2477. + assert(space_index(old_obj) == space_index(new_obj), "old_obj and new_obj must be in same space");
  2478. + return normalComparison;
  2479. +
  2480. + } else {
  2481. +
  2482. + assert(space_index(old_obj) != space_index(new_obj), "old_obj and new_obj must be in different spaces");
  2483. +
  2484. + Generation* tenured_gen = GenCollectedHeap::heap()->get_gen(1);
  2485. + if (tenured_gen->is_in_reserved(new_obj)) {
  2486. + // Must never rescue when moving from the new into the old generation.
  2487. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(old_obj), "old_obj must be in DefNewGeneration");
  2488. + assert(space_index(old_obj) > space_index(new_obj), "must be");
  2489. + return false;
  2490. +
  2491. + } else if (tenured_gen->is_in_reserved(old_obj)) {
  2492. + // Must always rescue when moving from the old into the new generation.
  2493. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(new_obj), "new_obj must be in DefNewGeneration");
  2494. + assert(space_index(old_obj) < space_index(new_obj), "must be");
  2495. + return true;
  2496. +
  2497. + } else {
  2498. + // In the new generation, eden is located before the from space, so a
  2499. + // simple pointer comparison is sufficient.
  2500. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(old_obj), "old_obj must be in DefNewGeneration");
  2501. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(new_obj), "new_obj must be in DefNewGeneration");
  2502. + assert((normalComparison) == (space_index(old_obj) < space_index(new_obj)), "slow and fast computation must yield same result");
  2503. + return normalComparison;
  2504. + }
  2505. + }
  2506. +}
  2507. +
  2508. +oop CompactibleSpace::rescue(oop old_obj) {
  2509. + assert(must_rescue(old_obj, old_obj->forwardee()), "do not call otherwise");
  2510. +
  2511. + int size = old_obj->size();
  2512. + oop rescued_obj = (oop)resource_allocate_bytes(size * HeapWordSize);
  2513. + Copy::aligned_disjoint_words((HeapWord*)old_obj, (HeapWord*)rescued_obj, size);
  2514. +
  2515. + if (MarkSweep::_rescued_oops == NULL) {
  2516. + MarkSweep::_rescued_oops = new GrowableArray<oop>(128);
  2517. + }
  2518. +
  2519. + MarkSweep::_rescued_oops->append(rescued_obj);
  2520. + return rescued_obj;
  2521. +}
  2522. +
  2523. void CompactibleSpace::adjust_pointers() {
  2524. // Check first is there is any work to do.
  2525. if (used() == 0) {
  2526. return; // Nothing to do.
  2527. }
  2528. + /* adjust all the interior pointers to point at the new locations of objects
  2529. + * Used by MarkSweep::mark_sweep_phase3() */
  2530. - SCAN_AND_ADJUST_POINTERS(adjust_obj_size);
  2531. + HeapWord* q = bottom();
  2532. + HeapWord* t = _end_of_live; /* Established by "prepare_for_compaction". */
  2533. +
  2534. + assert(_first_dead <= _end_of_live, "Stands to reason, no?");
  2535. +
  2536. + debug_only(HeapWord* prev_q = NULL);
  2537. + debug_only(HeapWord* prev_prev_q = NULL);
  2538. + debug_only(HeapWord* prev_prev_prev_q = NULL);
  2539. + if (q < t && _first_dead > q &&
  2540. + !oop(q)->is_gc_marked()) {
  2541. + /* we have a chunk of the space which hasn't moved and we've
  2542. + * reinitialized the mark word during the previous pass, so we can't
  2543. + * use is_gc_marked for the traversal. */
  2544. + HeapWord* end = _first_dead;
  2545. +
  2546. + while (q < end) {
  2547. + /* I originally tried to conjoin "block_start(q) == q" to the
  2548. + * assertion below, but that doesn't work, because you can't
  2549. + * accurately traverse previous objects to get to the current one
  2550. + * after their pointers (including pointers into permGen) have been
  2551. + * updated, until the actual compaction is done. dld, 4/00 */
  2552. + assert(block_is_obj(q),
  2553. + "should be at block boundaries, and should be looking at objs");
  2554. +
  2555. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::track_interior_pointers(oop(q)));
  2556. +
  2557. + /* point all the oops to the new location */
  2558. + size_t size = oop(q)->adjust_pointers();
  2559. + size = adjust_obj_size(size);
  2560. +
  2561. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::check_interior_pointers());
  2562. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::validate_live_oop(oop(q), size));
  2563. +
  2564. + debug_only(prev_prev_prev_q = prev_prev_q);
  2565. + debug_only(prev_prev_q = prev_q);
  2566. + debug_only(prev_q = q);
  2567. + q += size;
  2568. + }
  2569. +
  2570. + // (tw) first_dead can be live object!
  2571. + q = _first_dead;
  2572. +
  2573. +// if (_first_dead == t) {
  2574. +// q = t;
  2575. +// } else {
  2576. +// /* $$$ This is funky. Using this to read the previously written
  2577. +// * LiveRange. See also use below. */
  2578. +// q = (HeapWord*)oop(_first_dead)->mark()->decode_pointer();
  2579. +// }
  2580. + }
  2581. +
  2582. + const intx interval = PrefetchScanIntervalInBytes;
  2583. +
  2584. + debug_only(prev_q = NULL);
  2585. + debug_only(prev_prev_q = NULL);
  2586. + debug_only(prev_prev_prev_q = NULL);
  2587. + while (q < t) {
  2588. + /* prefetch beyond q */
  2589. + Prefetch::write(q, interval);
  2590. + if (oop(q)->is_gc_marked()) {
  2591. + /* q is alive */
  2592. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::track_interior_pointers(oop(q)));
  2593. + /* point all the oops to the new location */
  2594. + size_t size = oop(q)->adjust_pointers();
  2595. + size = adjust_obj_size(size);
  2596. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::check_interior_pointers());
  2597. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::validate_live_oop(oop(q), size));
  2598. + debug_only(prev_prev_prev_q = prev_prev_q);
  2599. + debug_only(prev_prev_q = prev_q);
  2600. + debug_only(prev_q = q);
  2601. + q += size;
  2602. + } else {
  2603. + /* q is not a live object, so its mark should point at the next
  2604. + * live object */
  2605. + debug_only(prev_prev_prev_q = prev_prev_q);
  2606. + debug_only(prev_prev_q = prev_q);
  2607. + debug_only(prev_q = q);
  2608. + q = (HeapWord*) oop(q)->mark()->decode_pointer();
  2609. + assert(q > prev_q, "we should be moving forward through memory");
  2610. + }
  2611. + }
  2612. +
  2613. + assert(q == t, "just checking");
  2614. }
  2615. void CompactibleSpace::compact() {
  2616. - SCAN_AND_COMPACT(obj_size);
  2617. +
  2618. + if(!Universe::is_redefining_gc_run()) {
  2619. + SCAN_AND_COMPACT(obj_size);
  2620. + return;
  2621. + }
  2622. +
  2623. + /* Copy all live objects to their new location
  2624. + * Used by MarkSweep::mark_sweep_phase4() */
  2625. +
  2626. + HeapWord* q = bottom();
  2627. + HeapWord* const t = _end_of_live;
  2628. + debug_only(HeapWord* prev_q = NULL);
  2629. +
  2630. + if (q < t && _first_dead > q &&
  2631. + !oop(q)->is_gc_marked()) {
  2632. + debug_only(
  2633. + /* we have a chunk of the space which hasn't moved and we've reinitialized
  2634. + * the mark word during the previous pass, so we can't use is_gc_marked for
  2635. + * the traversal. */
  2636. + HeapWord* const end = _first_dead;
  2637. +
  2638. + while (q < end) {
  2639. + size_t size = obj_size(q); // FIXME: idubrov oop(q)->size();
  2640. + assert(!oop(q)->is_gc_marked(),
  2641. + "should be unmarked (special dense prefix handling)");
  2642. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::live_oop_moved_to(q, size, q));
  2643. + debug_only(prev_q = q);
  2644. + q += size;
  2645. + }
  2646. + ) /* debug_only */
  2647. + // (tw) first_dead can be live object!
  2648. + q = _first_dead;
  2649. +
  2650. + //if (_first_dead == t) {
  2651. + // q = t;
  2652. + //} else {
  2653. + ///* $$$ Funky */
  2654. + //q = (HeapWord*) oop(_first_dead)->mark()->decode_pointer();
  2655. + //}
  2656. + }
  2657. +
  2658. + const intx scan_interval = PrefetchScanIntervalInBytes;
  2659. + const intx copy_interval = PrefetchCopyIntervalInBytes;
  2660. + while (q < t) {
  2661. + if (!oop(q)->is_gc_marked()) {
  2662. + /* mark is pointer to next marked oop */
  2663. + debug_only(prev_q = q);
  2664. + q = (HeapWord*) oop(q)->mark()->decode_pointer();
  2665. + assert(q > prev_q, "we should be moving forward through memory");
  2666. + } else {
  2667. + /* prefetch beyond q */
  2668. + Prefetch::read(q, scan_interval);
  2669. +
  2670. + /* size and destination */
  2671. + size_t size = obj_size(q);
  2672. + HeapWord* compaction_top = (HeapWord*)oop(q)->forwardee();
  2673. +
  2674. + if (must_rescue(oop(q), oop(q)->forwardee())) {
  2675. + oop dest_obj = rescue(oop(q));
  2676. + debug_only(Copy::fill_to_words(q, size, 0));
  2677. + } else {
  2678. +
  2679. + /* prefetch beyond compaction_top */
  2680. + Prefetch::write(compaction_top, copy_interval);
  2681. +
  2682. + /* copy object and reinit its mark */
  2683. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::live_oop_moved_to(q, size,
  2684. + compaction_top));
  2685. + assert(q != compaction_top || oop(q)->blueprint()->new_version() != NULL, "everything in this pass should be moving");
  2686. +
  2687. + if (oop(q)->blueprint()->new_version() != NULL) {
  2688. + MarkSweep::update_fields(oop(q), oop(compaction_top));
  2689. + } else {
  2690. + Copy::aligned_conjoint_words(q, compaction_top, size);
  2691. + }
  2692. + oop(compaction_top)->init_mark();
  2693. + assert(oop(compaction_top)->klass() != NULL, "should have a class");
  2694. + }
  2695. +
  2696. + debug_only(prev_q = q);
  2697. + q += size;
  2698. + }
  2699. + }
  2700. +
  2701. + /* Let's remember if we were empty before we did the compaction. */
  2702. + bool was_empty = used_region().is_empty();
  2703. + /* Reset space after compaction is complete */
  2704. + reset_after_compaction();
  2705. + /* We do this clear, below, since it has overloaded meanings for some */
  2706. + /* space subtypes. For example, OffsetTableContigSpace's that were */
  2707. + /* compacted into will have had their offset table thresholds updated */
  2708. + /* continuously, but those that weren't need to have their thresholds */
  2709. + /* re-initialized. Also mangles unused area for debugging. */
  2710. + if (used_region().is_empty()) {
  2711. + if (!was_empty) clear(SpaceDecorator::Mangle);
  2712. + } else {
  2713. + if (ZapUnusedHeapArea) mangle_unused_area();
  2714. + }
  2715. +
  2716. + //SCAN_AND_COMPACT(obj_size);
  2717. }
  2718. void Space::print_short() const { print_short_on(tty); }
  2719. diff --git a/src/share/vm/memory/space.hpp b/src/share/vm/memory/space.hpp
  2720. index ef2f2c6..b54d470 100644
  2721. --- a/src/share/vm/memory/space.hpp
  2722. +++ b/src/share/vm/memory/space.hpp
  2723. @@ -445,6 +445,9 @@
  2724. // indicates when the next such action should be taken.
  2725. virtual void prepare_for_compaction(CompactPoint* cp);
  2726. // MarkSweep support phase3
  2727. + DEBUG_ONLY(int space_index(oop obj));
  2728. + bool must_rescue(oop old_obj, oop new_obj);
  2729. + oop rescue(oop old_obj);
  2730. virtual void adjust_pointers();
  2731. // MarkSweep support phase4
  2732. virtual void compact();
  2733. @@ -475,6 +478,10 @@
  2734. virtual HeapWord* forward(oop q, size_t size, CompactPoint* cp,
  2735. HeapWord* compact_top);
  2736. + // (tw)
  2737. + virtual HeapWord* forward_compact_top(size_t size, CompactPoint* cp,
  2738. + HeapWord* compact_top);
  2739. +
  2740. // Return a size with adjusments as required of the space.
  2741. virtual size_t adjust_object_size_v(size_t size) const { return size; }
  2742. diff --git a/src/share/vm/memory/universe.cpp b/src/share/vm/memory/universe.cpp
  2743. index 4030d9d..da9a186 100644
  2744. --- a/src/share/vm/memory/universe.cpp
  2745. +++ b/src/share/vm/memory/universe.cpp
  2746. @@ -100,6 +100,8 @@
  2747. #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
  2748. #endif
  2749. +bool Universe::_is_redefining_gc_run = false;
  2750. +
  2751. // Known objects
  2752. klassOop Universe::_boolArrayKlassObj = NULL;
  2753. klassOop Universe::_byteArrayKlassObj = NULL;
  2754. @@ -204,6 +206,38 @@
  2755. f(systemObjArrayKlassObj());
  2756. }
  2757. +// DCEVM: This method should iterate all pointers that are not within heap objects.
  2758. +void Universe::root_oops_do(OopClosure *oopClosure) {
  2759. +
  2760. + class AlwaysTrueClosure: public BoolObjectClosure {
  2761. + public:
  2762. + void do_object(oop p) { ShouldNotReachHere(); }
  2763. + bool do_object_b(oop p) { return true; }
  2764. + };
  2765. + AlwaysTrueClosure always_true;
  2766. +
  2767. + // General strong roots
  2768. + Universe::oops_do(oopClosure);
  2769. + JNIHandles::oops_do(oopClosure);
  2770. + Threads::oops_do(oopClosure, NULL);
  2771. + ObjectSynchronizer::oops_do(oopClosure);
  2772. + FlatProfiler::oops_do(oopClosure);
  2773. + //Management::oops_do(oopClosure); // DCEVM: TODO: Check if this is correct?
  2774. + JvmtiExport::oops_do(oopClosure);
  2775. + // SO_AllClasses
  2776. + SystemDictionary::oops_do(oopClosure);
  2777. +
  2778. + // Now adjust pointers in remaining weak roots. (All of which should
  2779. + // have been cleared if they pointed to non-surviving objects.)
  2780. + // Global (weak) JNI handles
  2781. + JNIHandles::weak_oops_do(&always_true, oopClosure);
  2782. +
  2783. + CodeCache::oops_do(oopClosure);
  2784. + StringTable::oops_do(oopClosure);
  2785. + //ref_processor()->weak_oops_do(&oopClosure); // DCEVM: TODO: Check if this is correct?
  2786. + //PSScavenge::reference_processor()->weak_oops_do(&oopClosure); // DCEVM: TODO: Check if this is correct?
  2787. +}
  2788. +
  2789. void Universe::oops_do(OopClosure* f, bool do_all) {
  2790. f->do_oop((oop*) &_int_mirror);
  2791. diff --git a/src/share/vm/memory/universe.hpp b/src/share/vm/memory/universe.hpp
  2792. index 50fcb62..afb6b33 100644
  2793. --- a/src/share/vm/memory/universe.hpp
  2794. +++ b/src/share/vm/memory/universe.hpp
  2795. @@ -127,6 +127,8 @@
  2796. friend class SystemDictionary;
  2797. friend class VMStructs;
  2798. friend class CompactingPermGenGen;
  2799. + friend class Space;
  2800. + friend class ContiguousSpace;
  2801. friend class VM_PopulateDumpSharedSpace;
  2802. friend jint universe_init();
  2803. @@ -258,7 +260,18 @@
  2804. static void compute_verify_oop_data();
  2805. + static bool _is_redefining_gc_run;
  2806. +
  2807. public:
  2808. +
  2809. + static bool is_redefining_gc_run() {
  2810. + return _is_redefining_gc_run;
  2811. + }
  2812. +
  2813. + static void set_redefining_gc_run(bool b) {
  2814. + _is_redefining_gc_run = b;
  2815. + }
  2816. +
  2817. // Known classes in the VM
  2818. static klassOop boolArrayKlassObj() { return _boolArrayKlassObj; }
  2819. static klassOop byteArrayKlassObj() { return _byteArrayKlassObj; }
  2820. @@ -403,6 +416,8 @@
  2821. // Iteration
  2822. + static void root_oops_do(OopClosure *f);
  2823. +
  2824. // Apply "f" to the addresses of all the direct heap pointers maintained
  2825. // as static fields of "Universe".
  2826. static void oops_do(OopClosure* f, bool do_all = false);
  2827. @@ -419,6 +434,7 @@
  2828. // Debugging
  2829. static bool verify_in_progress() { return _verify_in_progress; }
  2830. + static void set_verify_in_progress(bool b) { _verify_in_progress = b; }
  2831. static void verify(VerifyOption option, const char* prefix, bool silent = VerifySilently);
  2832. static void verify(const char* prefix, bool silent = VerifySilently) {
  2833. verify(VerifyOption_Default, prefix, silent);
  2834. diff --git a/src/share/vm/oops/arrayKlass.cpp b/src/share/vm/oops/arrayKlass.cpp
  2835. index 16142b8..921e546 100644
  2836. --- a/src/share/vm/oops/arrayKlass.cpp
  2837. +++ b/src/share/vm/oops/arrayKlass.cpp
  2838. @@ -136,9 +136,9 @@
  2839. bool arrayKlass::compute_is_subtype_of(klassOop k) {
  2840. // An array is a subtype of Serializable, Clonable, and Object
  2841. - return k == SystemDictionary::Object_klass()
  2842. - || k == SystemDictionary::Cloneable_klass()
  2843. - || k == SystemDictionary::Serializable_klass();
  2844. + return k->klass_part()->newest_version() == SystemDictionary::Object_klass()->klass_part()->newest_version()
  2845. + || k->klass_part()->newest_version() == SystemDictionary::Cloneable_klass()->klass_part()->newest_version()
  2846. + || k->klass_part()->newest_version() == SystemDictionary::Serializable_klass()->klass_part()->newest_version();
  2847. }
  2848. diff --git a/src/share/vm/oops/constMethodKlass.cpp b/src/share/vm/oops/constMethodKlass.cpp
  2849. index e74811f..be3fe7d 100644
  2850. --- a/src/share/vm/oops/constMethodKlass.cpp
  2851. +++ b/src/share/vm/oops/constMethodKlass.cpp
  2852. @@ -102,6 +102,7 @@
  2853. constMethodOop cm = constMethodOop(obj);
  2854. MarkSweep::mark_and_push(cm->adr_constants());
  2855. MarkSweep::mark_and_push(cm->adr_stackmap_data());
  2856. + MarkSweep::mark_and_push(cm->adr_code_section_table());
  2857. // Performance tweak: We skip iterating over the klass pointer since we
  2858. // know that Universe::constMethodKlassObj never moves.
  2859. }
  2860. @@ -113,6 +114,7 @@
  2861. constMethodOop cm_oop = constMethodOop(obj);
  2862. PSParallelCompact::mark_and_push(cm, cm_oop->adr_constants());
  2863. PSParallelCompact::mark_and_push(cm, cm_oop->adr_stackmap_data());
  2864. + PSParallelCompact::mark_and_push(cm, cm_oop->adr_code_section_table());
  2865. // Performance tweak: We skip iterating over the klass pointer since we
  2866. // know that Universe::constMethodKlassObj never moves.
  2867. }
  2868. @@ -123,6 +125,7 @@
  2869. constMethodOop cm = constMethodOop(obj);
  2870. blk->do_oop(cm->adr_constants());
  2871. blk->do_oop(cm->adr_stackmap_data());
  2872. + blk->do_oop(cm->adr_code_section_table());
  2873. // Get size before changing pointers.
  2874. // Don't call size() or oop_size() since that is a virtual call.
  2875. int size = cm->object_size();
  2876. @@ -138,6 +141,8 @@
  2877. if (mr.contains(adr)) blk->do_oop(adr);
  2878. adr = cm->adr_stackmap_data();
  2879. if (mr.contains(adr)) blk->do_oop(adr);
  2880. + adr = cm->adr_code_section_table();
  2881. + if (mr.contains(adr)) blk->do_oop(adr);
  2882. // Get size before changing pointers.
  2883. // Don't call size() or oop_size() since that is a virtual call.
  2884. int size = cm->object_size();
  2885. @@ -152,6 +157,7 @@
  2886. constMethodOop cm = constMethodOop(obj);
  2887. MarkSweep::adjust_pointer(cm->adr_constants());
  2888. MarkSweep::adjust_pointer(cm->adr_stackmap_data());
  2889. + MarkSweep::adjust_pointer(cm->adr_code_section_table());
  2890. // Get size before changing pointers.
  2891. // Don't call size() or oop_size() since that is a virtual call.
  2892. int size = cm->object_size();
  2893. diff --git a/src/share/vm/oops/constMethodOop.hpp b/src/share/vm/oops/constMethodOop.hpp
  2894. index 549192b..5cea5c4 100644
  2895. --- a/src/share/vm/oops/constMethodOop.hpp
  2896. +++ b/src/share/vm/oops/constMethodOop.hpp
  2897. @@ -129,7 +129,7 @@
  2898. public:
  2899. oop* oop_block_beg() const { return adr_constants(); }
  2900. - oop* oop_block_end() const { return adr_stackmap_data() + 1; }
  2901. + oop* oop_block_end() const { return adr_code_section_table() + 1; }
  2902. private:
  2903. //
  2904. @@ -140,6 +140,9 @@
  2905. // Raw stackmap data for the method
  2906. typeArrayOop _stackmap_data;
  2907. +
  2908. + // (tw) Table mapping code sections for method forward points.
  2909. + typeArrayOop _code_section_table;
  2910. //
  2911. // End of the oop block.
  2912. @@ -194,6 +197,28 @@
  2913. oop_store_without_check((oop*)&_stackmap_data, (oop)sd);
  2914. }
  2915. bool has_stackmap_table() const { return _stackmap_data != NULL; }
  2916. +
  2917. + // code section table
  2918. + typeArrayOop code_section_table() const { return _code_section_table; }
  2919. + void set_code_section_table(typeArrayOop e) { oop_store_without_check((oop*) &_code_section_table, (oop) e); }
  2920. + bool has_code_section_table() const { return code_section_table() != NULL && code_section_table()->length() > 0; }
  2921. + static const int ValuesPerCodeSectionEntry = 3;
  2922. + int code_section_entries() const {
  2923. + if (!has_code_section_table()) return 0;
  2924. + return _code_section_table->length() / ValuesPerCodeSectionEntry;
  2925. + }
  2926. +
  2927. + int code_section_new_index_at(int index) const {
  2928. + return _code_section_table->short_at(index * ValuesPerCodeSectionEntry);
  2929. + }
  2930. +
  2931. + int code_section_original_index_at(int index) const {
  2932. + return _code_section_table->short_at(index * ValuesPerCodeSectionEntry + 1);
  2933. + }
  2934. +
  2935. + int code_section_length_at(int index) const {
  2936. + return _code_section_table->short_at(index * ValuesPerCodeSectionEntry + 2);
  2937. + }
  2938. void init_fingerprint() {
  2939. const uint64_t initval = CONST64(0x8000000000000000);
  2940. @@ -301,6 +326,7 @@
  2941. // Garbage collection support
  2942. oop* adr_constants() const { return (oop*)&_constants; }
  2943. oop* adr_stackmap_data() const { return (oop*)&_stackmap_data; }
  2944. + oop* adr_code_section_table() const { return (oop*)&_code_section_table; }
  2945. bool is_conc_safe() { return _is_conc_safe; }
  2946. void set_is_conc_safe(bool v) { _is_conc_safe = v; }
  2947. diff --git a/src/share/vm/oops/cpCacheOop.cpp b/src/share/vm/oops/cpCacheOop.cpp
  2948. index ad62921..f39f202 100644
  2949. --- a/src/share/vm/oops/cpCacheOop.cpp
  2950. +++ b/src/share/vm/oops/cpCacheOop.cpp
  2951. @@ -37,9 +37,15 @@
  2952. // Implememtation of ConstantPoolCacheEntry
  2953. +void ConstantPoolCacheEntry::copy_from(ConstantPoolCacheEntry *other) {
  2954. + _flags = other->_flags; // flags
  2955. +}
  2956. +
  2957. void ConstantPoolCacheEntry::initialize_entry(int index) {
  2958. assert(0 < index && index < 0x10000, "sanity check");
  2959. _indices = index;
  2960. + _f1 = NULL;
  2961. + _f2 = 0;
  2962. assert(constant_pool_index() == index, "");
  2963. }
  2964. @@ -162,7 +168,8 @@
  2965. int vtable_index) {
  2966. assert(!is_secondary_entry(), "");
  2967. assert(method->interpreter_entry() != NULL, "should have been set at this point");
  2968. - assert(!method->is_obsolete(), "attempt to write obsolete method to cpCache");
  2969. + // (tw) No longer valid assert
  2970. + //assert(!method->is_obsolete(), "attempt to write obsolete method to cpCache");
  2971. int byte_no = -1;
  2972. bool change_to_virtual = false;
  2973. @@ -183,6 +190,7 @@
  2974. set_method_flags(as_TosState(method->result_type()),
  2975. ( 1 << is_vfinal_shift) |
  2976. ((method->is_final_method() ? 1 : 0) << is_final_shift) |
  2977. + ((method->is_old() ? 1 : 0) << is_old_method_shift) |
  2978. ((change_to_virtual ? 1 : 0) << is_forced_virtual_shift),
  2979. method()->size_of_parameters());
  2980. set_f2_as_vfinal_method(method());
  2981. @@ -190,9 +198,13 @@
  2982. assert(vtable_index >= 0, "valid index");
  2983. assert(!method->is_final_method(), "sanity");
  2984. set_method_flags(as_TosState(method->result_type()),
  2985. + ((method->is_old() ? 1 : 0) << is_old_method_shift) |
  2986. ((change_to_virtual ? 1 : 0) << is_forced_virtual_shift),
  2987. method()->size_of_parameters());
  2988. set_f2(vtable_index);
  2989. +
  2990. + // (tw) save method holder in f1 for virtual calls
  2991. + set_f1(method());
  2992. }
  2993. byte_no = 2;
  2994. break;
  2995. @@ -206,7 +218,8 @@
  2996. // Once is_vfinal is set, it must stay that way, lest we get a dangling oop.
  2997. set_method_flags(as_TosState(method->result_type()),
  2998. ((is_vfinal() ? 1 : 0) << is_vfinal_shift) |
  2999. - ((method->is_final_method() ? 1 : 0) << is_final_shift),
  3000. + ((method->is_final_method() ? 1 : 0) << is_final_shift) |
  3001. + ((method->is_old() ? 1 : 0) << is_old_method_shift),
  3002. method()->size_of_parameters());
  3003. set_f1(method());
  3004. byte_no = 1;
  3005. @@ -259,7 +272,7 @@
  3006. set_f1(interf);
  3007. set_f2(index);
  3008. set_method_flags(as_TosState(method->result_type()),
  3009. - 0, // no option bits
  3010. + ((method->is_old() ? 1 : 0) << is_old_method_shift),
  3011. method()->size_of_parameters());
  3012. set_bytecode_1(Bytecodes::_invokeinterface);
  3013. }
  3014. @@ -520,27 +533,12 @@
  3015. // If this constantPoolCacheEntry refers to old_method then update it
  3016. // to refer to new_method.
  3017. bool ConstantPoolCacheEntry::adjust_method_entry(methodOop old_method,
  3018. - methodOop new_method, bool * trace_name_printed) {
  3019. + methodOop new_method) {
  3020. if (is_vfinal()) {
  3021. - // virtual and final so _f2 contains method ptr instead of vtable index
  3022. - if (f2_as_vfinal_method() == old_method) {
  3023. - // match old_method so need an update
  3024. - // NOTE: can't use set_f2_as_vfinal_method as it asserts on different values
  3025. - _f2 = (intptr_t)new_method;
  3026. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  3027. - if (!(*trace_name_printed)) {
  3028. - // RC_TRACE_MESG macro has an embedded ResourceMark
  3029. - RC_TRACE_MESG(("adjust: name=%s",
  3030. - Klass::cast(old_method->method_holder())->external_name()));
  3031. - *trace_name_printed = true;
  3032. - }
  3033. - // RC_TRACE macro has an embedded ResourceMark
  3034. - RC_TRACE(0x00400000, ("cpc vf-entry update: %s(%s)",
  3035. - new_method->name()->as_C_string(),
  3036. - new_method->signature()->as_C_string()));
  3037. - }
  3038. -
  3039. + // virtual and final so f2() contains method ptr instead of vtable index
  3040. + if (f2_as_vfinal_method() != NULL && f2_as_vfinal_method()->method_holder()->klass_part()->new_version()) {
  3041. + initialize_entry(constant_pool_index());
  3042. return true;
  3043. }
  3044. @@ -548,82 +546,25 @@
  3045. return false;
  3046. }
  3047. - if ((oop)_f1 == NULL) {
  3048. - // NULL f1() means this is a virtual entry so bail out
  3049. - // We are assuming that the vtable index does not need change.
  3050. + // (tw) check how to update interface methods!
  3051. + if (bytecode_1() == Bytecodes::_invokevirtual || bytecode_2() == Bytecodes::_invokevirtual) {
  3052. +
  3053. + if(f1_as_method()->method_holder()->klass_part()->new_version()) {
  3054. + initialize_entry(constant_pool_index());
  3055. + return true;
  3056. + }
  3057. +
  3058. return false;
  3059. }
  3060. if ((oop)_f1 == old_method) {
  3061. _f1 = new_method;
  3062. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  3063. - if (!(*trace_name_printed)) {
  3064. - // RC_TRACE_MESG macro has an embedded ResourceMark
  3065. - RC_TRACE_MESG(("adjust: name=%s",
  3066. - Klass::cast(old_method->method_holder())->external_name()));
  3067. - *trace_name_printed = true;
  3068. - }
  3069. - // RC_TRACE macro has an embedded ResourceMark
  3070. - RC_TRACE(0x00400000, ("cpc entry update: %s(%s)",
  3071. - new_method->name()->as_C_string(),
  3072. - new_method->signature()->as_C_string()));
  3073. - }
  3074. -
  3075. return true;
  3076. + } else if(_f1 != NULL && (bytecode_1() != Bytecodes::_invokeinterface && f1_as_method()->method_holder()->klass_part()->new_version())) {
  3077. + initialize_entry(constant_pool_index());
  3078. }
  3079. return false;
  3080. -}
  3081. -
  3082. -// a constant pool cache entry should never contain old or obsolete methods
  3083. -bool ConstantPoolCacheEntry::check_no_old_or_obsolete_entries() {
  3084. - if (is_vfinal()) {
  3085. - // virtual and final so _f2 contains method ptr instead of vtable index
  3086. - methodOop m = (methodOop)_f2;
  3087. - // Return false if _f2 refers to an old or an obsolete method.
  3088. - // _f2 == NULL || !m->is_method() are just as unexpected here.
  3089. - return (m != NULL && m->is_method() && !m->is_old() && !m->is_obsolete());
  3090. - } else if ((oop)_f1 == NULL || !((oop)_f1)->is_method()) {
  3091. - // _f1 == NULL || !_f1->is_method() are OK here
  3092. - return true;
  3093. - }
  3094. -
  3095. - methodOop m = (methodOop)_f1;
  3096. - // return false if _f1 refers to an old or an obsolete method
  3097. - return (!m->is_old() && !m->is_obsolete());
  3098. -}
  3099. -
  3100. -bool ConstantPoolCacheEntry::is_interesting_method_entry(klassOop k) {
  3101. - if (!is_method_entry()) {
  3102. - // not a method entry so not interesting by default
  3103. - return false;
  3104. - }
  3105. -
  3106. - methodOop m = NULL;
  3107. - if (is_vfinal()) {
  3108. - // virtual and final so _f2 contains method ptr instead of vtable index
  3109. - m = f2_as_vfinal_method();
  3110. - } else if (is_f1_null()) {
  3111. - // NULL _f1 means this is a virtual entry so also not interesting
  3112. - return false;
  3113. - } else {
  3114. - oop f1 = _f1; // _f1 is volatile
  3115. - if (!f1->is_method()) {
  3116. - // _f1 can also contain a klassOop for an interface
  3117. - return false;
  3118. - }
  3119. - m = f1_as_method();
  3120. - }
  3121. -
  3122. - assert(m != NULL && m->is_method(), "sanity check");
  3123. - if (m == NULL || !m->is_method() || (k != NULL && m->method_holder() != k)) {
  3124. - // robustness for above sanity checks or method is not in
  3125. - // the interesting class
  3126. - return false;
  3127. - }
  3128. -
  3129. - // the method is in the interesting class so the entry is interesting
  3130. - return true;
  3131. }
  3132. void ConstantPoolCacheEntry::print(outputStream* st, int index) const {
  3133. @@ -663,60 +604,18 @@
  3134. }
  3135. }
  3136. -// RedefineClasses() API support:
  3137. -// If any entry of this constantPoolCache points to any of
  3138. -// old_methods, replace it with the corresponding new_method.
  3139. -void constantPoolCacheOopDesc::adjust_method_entries(methodOop* old_methods, methodOop* new_methods,
  3140. - int methods_length, bool * trace_name_printed) {
  3141. -
  3142. - if (methods_length == 0) {
  3143. - // nothing to do if there are no methods
  3144. - return;
  3145. - }
  3146. -
  3147. - // get shorthand for the interesting class
  3148. - klassOop old_holder = old_methods[0]->method_holder();
  3149. +void constantPoolCacheOopDesc::adjust_entries(methodOop* old_methods, methodOop* new_methods,
  3150. + int methods_length) {
  3151. for (int i = 0; i < length(); i++) {
  3152. - if (!entry_at(i)->is_interesting_method_entry(old_holder)) {
  3153. - // skip uninteresting methods
  3154. - continue;
  3155. - }
  3156. -
  3157. - // The constantPoolCache contains entries for several different
  3158. - // things, but we only care about methods. In fact, we only care
  3159. - // about methods in the same class as the one that contains the
  3160. - // old_methods. At this point, we have an interesting entry.
  3161. -
  3162. - for (int j = 0; j < methods_length; j++) {
  3163. - methodOop old_method = old_methods[j];
  3164. - methodOop new_method = new_methods[j];
  3165. -
  3166. - if (entry_at(i)->adjust_method_entry(old_method, new_method,
  3167. - trace_name_printed)) {
  3168. - // current old_method matched this entry and we updated it so
  3169. - // break out and get to the next interesting entry if there one
  3170. - break;
  3171. - }
  3172. + if (entry_at(i)->is_field_entry()) {
  3173. + // (tw) TODO: Update only field offsets and modify only constant pool entries that
  3174. + // point to changed fields
  3175. + entry_at(i)->initialize_entry(entry_at(i)->constant_pool_index());
  3176. + } else if(entry_at(i)->is_method_entry()) {
  3177. + entry_at(i)->adjust_method_entry(NULL, NULL);
  3178. }
  3179. }
  3180. }
  3181. -// the constant pool cache should never contain old or obsolete methods
  3182. -bool constantPoolCacheOopDesc::check_no_old_or_obsolete_entries() {
  3183. - for (int i = 1; i < length(); i++) {
  3184. - if (entry_at(i)->is_interesting_method_entry(NULL) &&
  3185. - !entry_at(i)->check_no_old_or_obsolete_entries()) {
  3186. - return false;
  3187. - }
  3188. - }
  3189. - return true;
  3190. -}
  3191. -void constantPoolCacheOopDesc::dump_cache() {
  3192. - for (int i = 1; i < length(); i++) {
  3193. - if (entry_at(i)->is_interesting_method_entry(NULL)) {
  3194. - entry_at(i)->print(tty, i);
  3195. - }
  3196. - }
  3197. -}
  3198. diff --git a/src/share/vm/oops/cpCacheOop.hpp b/src/share/vm/oops/cpCacheOop.hpp
  3199. index b9107cd..653ab13 100644
  3200. --- a/src/share/vm/oops/cpCacheOop.hpp
  3201. +++ b/src/share/vm/oops/cpCacheOop.hpp
  3202. @@ -136,7 +136,8 @@
  3203. void set_bytecode_2(Bytecodes::Code code);
  3204. void set_f1(oop f1) {
  3205. oop existing_f1 = _f1; // read once
  3206. - assert(existing_f1 == NULL || existing_f1 == f1, "illegal field change");
  3207. + // (tw) need to relax assertion for redefinition
  3208. + // assert(existing_f1 == NULL || existing_f1 == f1, "illegal field change");
  3209. oop_store(&_f1, f1);
  3210. }
  3211. void release_set_f1(oop f1);
  3212. @@ -174,6 +175,7 @@
  3213. tos_state_mask = right_n_bits(tos_state_bits),
  3214. tos_state_shift = BitsPerInt - tos_state_bits, // see verify_tos_state_shift below
  3215. // misc. option bits; can be any bit position in [16..27]
  3216. + is_old_method_shift = 19,
  3217. is_vfinal_shift = 20,
  3218. is_volatile_shift = 21,
  3219. is_final_shift = 22,
  3220. @@ -206,6 +208,8 @@
  3221. // Initialization
  3222. void initialize_entry(int original_index); // initialize primary entry
  3223. void initialize_secondary_entry(int main_index); // initialize secondary entry
  3224. +
  3225. + void copy_from(ConstantPoolCacheEntry *other);
  3226. void set_field( // sets entry to resolved field state
  3227. Bytecodes::Code get_code, // the bytecode used for reading the field
  3228. @@ -368,10 +372,7 @@
  3229. // trace_name_printed is set to true if the current call has
  3230. // printed the klass name so that other routines in the adjust_*
  3231. // group don't print the klass name.
  3232. - bool adjust_method_entry(methodOop old_method, methodOop new_method,
  3233. - bool * trace_name_printed);
  3234. - bool check_no_old_or_obsolete_entries();
  3235. - bool is_interesting_method_entry(klassOop k);
  3236. + bool adjust_method_entry(methodOop old_method, methodOop new_method);
  3237. // Debugging & Printing
  3238. void print (outputStream* st, int index) const;
  3239. @@ -492,16 +493,9 @@
  3240. return (base_offset() + ConstantPoolCacheEntry::size_in_bytes() * index);
  3241. }
  3242. - // RedefineClasses() API support:
  3243. - // If any entry of this constantPoolCache points to any of
  3244. - // old_methods, replace it with the corresponding new_method.
  3245. - // trace_name_printed is set to true if the current call has
  3246. - // printed the klass name so that other routines in the adjust_*
  3247. - // group don't print the klass name.
  3248. - void adjust_method_entries(methodOop* old_methods, methodOop* new_methods,
  3249. - int methods_length, bool * trace_name_printed);
  3250. - bool check_no_old_or_obsolete_entries();
  3251. - void dump_cache();
  3252. + // (tw) Update method and field references
  3253. + void adjust_entries(methodOop* old_methods, methodOop* new_methods,
  3254. + int methods_length);
  3255. };
  3256. #endif // SHARE_VM_OOPS_CPCACHEOOP_HPP
  3257. diff --git a/src/share/vm/oops/instanceKlass.cpp b/src/share/vm/oops/instanceKlass.cpp
  3258. index a775b02..749458f 100644
  3259. --- a/src/share/vm/oops/instanceKlass.cpp
  3260. +++ b/src/share/vm/oops/instanceKlass.cpp
  3261. @@ -250,12 +250,118 @@
  3262. }
  3263. +void instanceKlass::initialize_redefined_class() {
  3264. + RC_TRACE(0x00000400, ("initializing redefined class %s",
  3265. + name()->as_C_string()));
  3266. +
  3267. + assert(!is_initialized(), "");
  3268. + assert(this->old_version() != NULL, "");
  3269. + assert(is_linked(), "must be linked before");
  3270. +
  3271. +
  3272. + instanceKlassHandle this_oop(Thread::current(), this->as_klassOop());
  3273. + class UpdateStaticFieldClosure : public FieldClosure {
  3274. +
  3275. + private:
  3276. + instanceKlassHandle this_oop;
  3277. +
  3278. + public:
  3279. + UpdateStaticFieldClosure(instanceKlassHandle this_oop) {
  3280. + this->this_oop = this_oop;
  3281. + }
  3282. +
  3283. + virtual void do_field(fieldDescriptor* fd) {
  3284. + fieldDescriptor result;
  3285. + bool found = ((instanceKlass *)(this_oop->old_version()->klass_part()))->find_local_field(fd->name(), fd->signature(), &result);
  3286. +
  3287. + if (found && result.is_static()) {
  3288. + int old_offset = result.offset();
  3289. + assert(result.field_type() == fd->field_type(), "Old and new field type does not match");
  3290. +
  3291. + oop new_location = this_oop()->java_mirror();
  3292. + oop old_location = this_oop->old_version()->java_mirror();
  3293. + int offset = fd->offset();
  3294. + RC_TRACE(0x00000400, ("Copying static field value for field '%s' old_offset=%d new_offset=%d",
  3295. + fd->name()->as_C_string(), old_offset, offset));
  3296. +
  3297. + oop cur_oop;
  3298. +
  3299. + switch(result.field_type()) {
  3300. +
  3301. + // Found static field with same name and type in the old klass => copy value from old to new klass
  3302. +
  3303. + case T_BOOLEAN:
  3304. + new_location->bool_field_put(offset, old_location->bool_field(old_offset));
  3305. + DEBUG_ONLY(old_location->byte_field_put(old_offset, 0));
  3306. + break;
  3307. +
  3308. + case T_CHAR:
  3309. + new_location->char_field_put(offset, old_location->char_field(old_offset));
  3310. + DEBUG_ONLY(old_location->char_field_put(old_offset, 0));
  3311. + break;
  3312. +
  3313. + case T_FLOAT:
  3314. + new_location->float_field_put(offset, old_location->float_field(old_offset));
  3315. + DEBUG_ONLY(old_location->float_field_put(old_offset, 0));
  3316. + break;
  3317. +
  3318. + case T_DOUBLE:
  3319. + new_location->double_field_put(offset, old_location->double_field(old_offset));
  3320. + DEBUG_ONLY(old_location->double_field_put(old_offset, 0));
  3321. + break;
  3322. +
  3323. + case T_BYTE:
  3324. + new_location->byte_field_put(offset, old_location->byte_field(old_offset));
  3325. + DEBUG_ONLY(old_location->byte_field_put(old_offset, 0));
  3326. + break;
  3327. +
  3328. + case T_SHORT:
  3329. + new_location->short_field_put(offset, old_location->short_field(old_offset));
  3330. + DEBUG_ONLY(old_location->short_field_put(old_offset, 0));
  3331. + break;
  3332. +
  3333. + case T_INT:
  3334. + new_location->int_field_put(offset, old_location->int_field(old_offset));
  3335. + DEBUG_ONLY(old_location->int_field_put(old_offset, 0));
  3336. + break;
  3337. +
  3338. + case T_LONG:
  3339. + new_location->long_field_put(offset, old_location->long_field(old_offset));
  3340. + DEBUG_ONLY(old_location->long_field_put(old_offset, 0));
  3341. + break;
  3342. +
  3343. + case T_OBJECT:
  3344. + case T_ARRAY:
  3345. + cur_oop = old_location->obj_field(old_offset);
  3346. + new_location->obj_field_put_raw(offset, cur_oop);
  3347. + old_location->obj_field_put_raw(old_offset, NULL);
  3348. + break;
  3349. +
  3350. + default:
  3351. + ShouldNotReachHere();
  3352. + }
  3353. + } else {
  3354. + RC_TRACE(0x00000200, ("New static field %s has_initial_value=%d",
  3355. + fd->name()->as_C_string(), (int)(fd->has_initial_value())));
  3356. + // field not found
  3357. + // (tw) TODO: Probably this call is not necessary here!
  3358. + // FIXME: idubrov
  3359. + //ClassFileParser::initialize_static_field(fd, Thread::current());
  3360. + }
  3361. + }
  3362. + };
  3363. +
  3364. + UpdateStaticFieldClosure cl(this_oop);
  3365. + this->do_local_static_fields(&cl);
  3366. +}
  3367. +
  3368. +
  3369. bool instanceKlass::verify_code(
  3370. instanceKlassHandle this_oop, bool throw_verifyerror, TRAPS) {
  3371. // 1) Verify the bytecodes
  3372. Verifier::Mode mode =
  3373. throw_verifyerror ? Verifier::ThrowException : Verifier::NoException;
  3374. - return Verifier::verify(this_oop, mode, this_oop->should_verify_class(), CHECK_false);
  3375. + return Verifier::verify(this_oop, mode, this_oop->should_verify_class(), true, CHECK_false);
  3376. }
  3377. @@ -362,7 +468,13 @@
  3378. jt->get_thread_stat()->perf_recursion_counts_addr(),
  3379. jt->get_thread_stat()->perf_timers_addr(),
  3380. PerfClassTraceTime::CLASS_VERIFY);
  3381. - bool verify_ok = verify_code(this_oop, throw_verifyerror, THREAD);
  3382. + if (this_oop->is_redefining()) {
  3383. + Thread::current()->set_pretend_new_universe(true);
  3384. + }
  3385. + bool verify_ok = verify_code(this_oop, throw_verifyerror, THREAD);
  3386. + if (this_oop->is_redefining()) {
  3387. + Thread::current()->set_pretend_new_universe(false);
  3388. + }
  3389. if (!verify_ok) {
  3390. return false;
  3391. }
  3392. @@ -400,7 +512,8 @@
  3393. }
  3394. #endif
  3395. this_oop->set_init_state(linked);
  3396. - if (JvmtiExport::should_post_class_prepare()) {
  3397. + // (tw) Must check for old version in order to prevent infinite loops.
  3398. + if (JvmtiExport::should_post_class_prepare() && this_oop->old_version() == NULL /* JVMTI deadlock otherwise */) {
  3399. Thread *thread = THREAD;
  3400. assert(thread->is_Java_thread(), "thread->is_Java_thread()");
  3401. JvmtiExport::post_class_prepare((JavaThread *) thread, this_oop());
  3402. @@ -673,6 +786,18 @@
  3403. return false;
  3404. }
  3405. +bool instanceKlass::implements_interface_any_version(klassOop k) const {
  3406. + k = k->klass_part()->newest_version();
  3407. + if (this->newest_version() == k) return true;
  3408. + assert(Klass::cast(k)->is_interface(), "should be an interface class");
  3409. + for (int i = 0; i < transitive_interfaces()->length(); i++) {
  3410. + if (((klassOop)transitive_interfaces()->obj_at(i))->klass_part()->newest_version() == k) {
  3411. + return true;
  3412. + }
  3413. + }
  3414. + return false;
  3415. +}
  3416. +
  3417. objArrayOop instanceKlass::allocate_objArray(int n, int length, TRAPS) {
  3418. if (length < 0) THROW_0(vmSymbols::java_lang_NegativeArraySizeException());
  3419. if (length > arrayOopDesc::max_array_length(T_OBJECT)) {
  3420. @@ -801,7 +926,25 @@
  3421. }
  3422. void instanceKlass::call_class_initializer_impl(instanceKlassHandle this_oop, TRAPS) {
  3423. +
  3424. + ResourceMark rm(THREAD);
  3425. methodHandle h_method(THREAD, this_oop->class_initializer());
  3426. +
  3427. + if (this_oop->revision_number() != -1){
  3428. + methodOop m = NULL;
  3429. + if (AllowAdvancedClassRedefinition) {
  3430. + m = this_oop->find_method(vmSymbols::static_transformer_name(), vmSymbols::void_method_signature());
  3431. + }
  3432. + methodHandle method(m);
  3433. + if (method() != NULL && method()->is_static()) {
  3434. + RC_TRACE(0x00000200, ("Calling static transformer instead of static initializer"));
  3435. + h_method = method;
  3436. + } else if (!((instanceKlass*)this_oop->old_version()->klass_part())->is_not_initialized()) {
  3437. + // Only execute the static initializer, if it was not yet executed for the old version of the class.
  3438. + return;
  3439. + }
  3440. + }
  3441. +
  3442. assert(!this_oop->is_initialized(), "we cannot initialize twice");
  3443. if (TraceClassInitialization) {
  3444. tty->print("%d Initializing ", call_class_initializer_impl_counter++);
  3445. @@ -949,6 +1092,137 @@
  3446. }
  3447. }
  3448. +void instanceKlass::store_update_information(GrowableArray<int> &values) {
  3449. + int *arr = NEW_C_HEAP_ARRAY(int, values.length(), mtClass);
  3450. + for (int i=0; i<values.length(); i++) {
  3451. + arr[i] = values.at(i);
  3452. + }
  3453. + set_update_information(arr);
  3454. +}
  3455. +
  3456. +void instanceKlass::clear_update_information() {
  3457. + FREE_C_HEAP_ARRAY(int, update_information(), mtClass);
  3458. + set_update_information(NULL);
  3459. +}
  3460. +
  3461. +typedef Pair<int, klassOop> typeInfoPair;
  3462. +
  3463. +void instanceKlass::store_type_check_information(GrowableArray< Pair<int, klassOop> > &values) {
  3464. + Pair<int, klassOop> *arr = NEW_C_HEAP_ARRAY(typeInfoPair, values.length(), mtClass);
  3465. + for (int i=0; i<values.length(); i++) {
  3466. + arr[i] = values.at(i);
  3467. + }
  3468. + set_type_check_information(arr);
  3469. +}
  3470. +
  3471. +void instanceKlass::clear_type_check_information() {
  3472. + FREE_C_HEAP_ARRAY(typeInfoPair, type_check_information(), mtClass);
  3473. + set_type_check_information(NULL);
  3474. +}
  3475. +
  3476. +void instanceKlass::do_fields_evolution(FieldEvolutionClosure* cl) {
  3477. +
  3478. + assert (old_version() != NULL, "must have old version!");
  3479. +
  3480. + klassOop old_klass_oop = old_version();
  3481. + instanceKlass *old_klass = instanceKlass::cast(old_klass_oop);
  3482. + instanceKlass *new_klass = this;
  3483. +
  3484. + fieldDescriptor fd;
  3485. + fieldDescriptor old_fd;
  3486. +
  3487. + instanceKlass *cur_new_klass = new_klass;
  3488. + klassOop cur_new_klass_oop = this->as_klassOop();
  3489. +
  3490. + if (_fields_not_changed) {
  3491. +
  3492. + class MyFieldClosure : public FieldClosure {
  3493. +
  3494. + FieldEvolutionClosure *_cl;
  3495. + public:
  3496. + MyFieldClosure(FieldEvolutionClosure *cl) {_cl = cl; }
  3497. + virtual void do_field(fieldDescriptor* fd) {
  3498. + _cl->do_changed_field(fd, fd);
  3499. + }
  3500. + };
  3501. +
  3502. + MyFieldClosure mfc(cl);
  3503. + do_nonstatic_fields(&mfc);
  3504. + } else {
  3505. +
  3506. + _fields_not_changed = true;
  3507. + GrowableArray<fieldDescriptor> fds;
  3508. + while (true) {
  3509. + for (JavaFieldStream fs(cur_new_klass); !fs.done(); fs.next()) {
  3510. + fd.initialize(cur_new_klass_oop, fs.index());
  3511. + if (fd.is_static()) {
  3512. + continue;
  3513. + }
  3514. + fds.append(fd);
  3515. + }
  3516. +
  3517. + if (cur_new_klass->super() != NULL) {
  3518. + cur_new_klass_oop = cur_new_klass->super();
  3519. + cur_new_klass = instanceKlass::cast(cur_new_klass_oop);
  3520. + } else {
  3521. + break;
  3522. + }
  3523. + }
  3524. +
  3525. + GrowableArray<fieldDescriptor> sortedFds;
  3526. + while (fds.length() > 0) {
  3527. + int minOffset = 0x7fffffff;
  3528. + int minIndex = -1;
  3529. + for (int i=0; i<fds.length(); i++) {
  3530. + int curOffset = fds.adr_at(i)->offset();
  3531. + if (curOffset < minOffset) {
  3532. + minOffset = curOffset;
  3533. + minIndex = i;
  3534. + }
  3535. + }
  3536. +
  3537. + sortedFds.append(fds.at(minIndex));
  3538. + fds.remove_at(minIndex);
  3539. + }
  3540. +
  3541. +
  3542. + for (int i=0; i<sortedFds.length(); i++) {
  3543. + fieldDescriptor &fd = *sortedFds.adr_at(i);
  3544. +
  3545. + char found = 0;
  3546. + instanceKlass *cur_old_klass = old_klass;
  3547. + klassOop cur_old_klass_oop = old_klass_oop;
  3548. + while (true) {
  3549. + for (JavaFieldStream fs(cur_old_klass); !fs.done(); fs.next()) {
  3550. + old_fd.initialize(cur_old_klass_oop, fs.index());
  3551. + if (old_fd.is_static()) {
  3552. + continue;
  3553. + }
  3554. + if (old_fd.name() == fd.name() && old_fd.signature() == fd.signature()) {
  3555. + found = 1;
  3556. + break;
  3557. + }
  3558. + }
  3559. + if (!found && cur_old_klass->super()) {
  3560. + cur_old_klass_oop = cur_old_klass->super();
  3561. + cur_old_klass = instanceKlass::cast(cur_old_klass_oop);
  3562. + } else {
  3563. + break;
  3564. + }
  3565. + }
  3566. +
  3567. + if (found) {
  3568. + if (old_fd.offset() != fd.offset()) {
  3569. + _fields_not_changed = false;
  3570. + }
  3571. + cl->do_changed_field(&old_fd, &fd);
  3572. + } else {
  3573. + _fields_not_changed = false;
  3574. + cl->do_new_field(&fd);
  3575. + }
  3576. + }
  3577. + }
  3578. +}
  3579. void instanceKlass::do_local_static_fields(FieldClosure* cl) {
  3580. for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
  3581. @@ -1368,6 +1642,20 @@
  3582. return id;
  3583. }
  3584. +bool instanceKlass::update_jmethod_id(methodOop method, jmethodID newMethodID) {
  3585. + size_t idnum = (size_t)method->method_idnum();
  3586. + jmethodID* jmeths = methods_jmethod_ids_acquire();
  3587. + size_t length; // length assigned as debugging crumb
  3588. + jmethodID id = NULL;
  3589. + if (jmeths != NULL && // If there is a cache
  3590. + (length = (size_t)jmeths[0]) > idnum) { // and if it is long enough,
  3591. + jmeths[idnum+1] = newMethodID; // Set the id (may be NULL)
  3592. + return true;
  3593. + }
  3594. +
  3595. + return false;
  3596. +}
  3597. +
  3598. // Cache an itable index
  3599. void instanceKlass::set_cached_itable_index(size_t idnum, int index) {
  3600. @@ -1527,6 +1815,13 @@
  3601. last = b;
  3602. b = b->next();
  3603. }
  3604. +
  3605. + // (tw) Hack as dependencies get wrong version of klassOop
  3606. + if(this->old_version() != NULL) {
  3607. + ((instanceKlass *)this->old_version()->klass_part())->remove_dependent_nmethod(nm);
  3608. + return;
  3609. + }
  3610. +
  3611. #ifdef ASSERT
  3612. tty->print_cr("### %s can't find dependent nmethod:", this->external_name());
  3613. nm->print();
  3614. @@ -2417,6 +2712,9 @@
  3615. klassOop mirrored_klass = java_lang_Class::as_klassOop(obj);
  3616. st->print(BULLET"fake entry for mirror: ");
  3617. mirrored_klass->print_value_on(st);
  3618. + if (mirrored_klass != NULL) {
  3619. + 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());
  3620. + }
  3621. st->cr();
  3622. st->print(BULLET"fake entry resolved_constructor: ");
  3623. methodOop ctor = java_lang_Class::resolved_constructor(obj);
  3624. diff --git a/src/share/vm/oops/instanceKlass.hpp b/src/share/vm/oops/instanceKlass.hpp
  3625. index bb613b0..71f0083 100644
  3626. --- a/src/share/vm/oops/instanceKlass.hpp
  3627. +++ b/src/share/vm/oops/instanceKlass.hpp
  3628. @@ -102,6 +102,22 @@
  3629. virtual void do_field(fieldDescriptor* fd) = 0;
  3630. };
  3631. +// (tw) Iterates over the fields of the old and new class
  3632. +class FieldEvolutionClosure : public StackObj {
  3633. +public:
  3634. + virtual void do_new_field(fieldDescriptor* fd) = 0;
  3635. + virtual void do_old_field(fieldDescriptor* fd) = 0;
  3636. + virtual void do_changed_field(fieldDescriptor* old_fd, fieldDescriptor *new_fd) = 0;
  3637. +};
  3638. +
  3639. +// (tw) Iterates over the methods of the old and new class
  3640. +class MethodEvolutionClosure : public StackObj {
  3641. +public:
  3642. + virtual void do_new_method(methodOop oop) = 0;
  3643. + virtual void do_old_method(methodOop oop) = 0;
  3644. + virtual void do_changed_method(methodOop oldOop, methodOop newOop) = 0;
  3645. +};
  3646. +
  3647. #ifndef PRODUCT
  3648. // Print fields.
  3649. // If "obj" argument to constructor is NULL, prints static fields, otherwise prints non-static fields.
  3650. @@ -287,6 +303,11 @@
  3651. // _idnum_allocated_count.
  3652. u1 _init_state; // state of class
  3653. + // (tw) Field that allows for a short-path when calculating updated fields for the second time and
  3654. + // no fields changed. Testing performance impact with this, can be removed later when the update
  3655. + // information is cached.
  3656. + bool _fields_not_changed;
  3657. +
  3658. u1 _reference_type; // reference type
  3659. // embedded Java vtable follows here
  3660. @@ -454,6 +475,7 @@
  3661. // initialization (virtuals from Klass)
  3662. bool should_be_initialized() const; // means that initialize should be called
  3663. void initialize(TRAPS);
  3664. + void initialize_redefined_class();
  3665. void link_class(TRAPS);
  3666. bool link_class_or_fail(TRAPS); // returns false on failure
  3667. void unlink_class();
  3668. @@ -631,6 +653,7 @@
  3669. static void get_jmethod_id_length_value(jmethodID* cache, size_t idnum,
  3670. size_t *length_p, jmethodID* id_p);
  3671. jmethodID jmethod_id_or_null(methodOop method);
  3672. + bool update_jmethod_id(methodOop method, jmethodID newMethodID);
  3673. // cached itable index support
  3674. void set_cached_itable_index(size_t idnum, int index);
  3675. @@ -713,6 +736,7 @@
  3676. // subclass/subinterface checks
  3677. bool implements_interface(klassOop k) const;
  3678. + bool implements_interface_any_version(klassOop k) const;
  3679. // Access to the implementor of an interface.
  3680. klassOop implementor() const
  3681. @@ -762,6 +786,12 @@
  3682. void do_local_static_fields(FieldClosure* cl);
  3683. void do_nonstatic_fields(FieldClosure* cl); // including inherited fields
  3684. void do_local_static_fields(void f(fieldDescriptor*, TRAPS), TRAPS);
  3685. + void do_fields_evolution(FieldEvolutionClosure *cl);
  3686. + void store_update_information(GrowableArray<int> &values);
  3687. + void clear_update_information();
  3688. + void store_type_check_information(GrowableArray< Pair<int, klassOop> > &values);
  3689. + void clear_type_check_information();
  3690. +
  3691. void methods_do(void f(methodOop method));
  3692. void array_klasses_do(void f(klassOop k));
  3693. diff --git a/src/share/vm/oops/instanceKlassKlass.cpp b/src/share/vm/oops/instanceKlassKlass.cpp
  3694. index 8e7dc12..63d6dc4 100644
  3695. --- a/src/share/vm/oops/instanceKlassKlass.cpp
  3696. +++ b/src/share/vm/oops/instanceKlassKlass.cpp
  3697. @@ -480,6 +480,28 @@
  3698. instanceKlass* ik = instanceKlass::cast(klassOop(obj));
  3699. klassKlass::oop_print_on(obj, st);
  3700. + // (tw) Output revision number and revision numbers of older / newer and oldest / newest version of this class.
  3701. +
  3702. + st->print(BULLET"revision: %d", ik->revision_number());
  3703. +
  3704. + if (ik->new_version() != NULL) {
  3705. + st->print(" (newer=%d)", ik->new_version()->klass_part()->revision_number());
  3706. + }
  3707. +
  3708. + if (ik->newest_version() != ik->new_version() && ik->newest_version() != obj) {
  3709. + st->print(" (newest=%d)", ik->newest_version()->klass_part()->revision_number());
  3710. + }
  3711. +
  3712. + if (ik->old_version() != NULL) {
  3713. + st->print(" (old=%d)", ik->old_version()->klass_part()->revision_number());
  3714. + }
  3715. +
  3716. + if (ik->oldest_version() != ik->old_version() && ik->oldest_version() != obj) {
  3717. + st->print(" (oldest=%d)", ik->oldest_version()->klass_part()->revision_number());
  3718. + }
  3719. +
  3720. + st->cr();
  3721. +
  3722. st->print(BULLET"instance size: %d", ik->size_helper()); st->cr();
  3723. st->print(BULLET"klass size: %d", ik->object_size()); st->cr();
  3724. st->print(BULLET"access: "); ik->access_flags().print_on(st); st->cr();
  3725. @@ -663,7 +685,7 @@
  3726. }
  3727. guarantee(sib->as_klassOop()->is_klass(), "should be klass");
  3728. guarantee(sib->as_klassOop()->is_perm(), "should be in permspace");
  3729. - guarantee(sib->super() == super, "siblings should have same superklass");
  3730. + guarantee(sib->super() == super || super->klass_part()->newest_version() == SystemDictionary::Object_klass(), "siblings should have same superklass");
  3731. sib = sib->next_sibling();
  3732. }
  3733. diff --git a/src/share/vm/oops/instanceRefKlass.cpp b/src/share/vm/oops/instanceRefKlass.cpp
  3734. index 7db4f03..1171487 100644
  3735. --- a/src/share/vm/oops/instanceRefKlass.cpp
  3736. +++ b/src/share/vm/oops/instanceRefKlass.cpp
  3737. @@ -455,10 +455,13 @@
  3738. instanceKlass* ik = instanceKlass::cast(k);
  3739. // Check that we have the right class
  3740. - debug_only(static bool first_time = true);
  3741. - assert(k == SystemDictionary::Reference_klass() && first_time,
  3742. - "Invalid update of maps");
  3743. - debug_only(first_time = false);
  3744. +
  3745. + // (tw) Asserts no longer valid for class redefinition
  3746. + // debug_only(static bool first_time = true);
  3747. +
  3748. + //assert(k == SystemDictionary::Reference_klass() && first_time,
  3749. + // "Invalid update of maps");
  3750. + //debug_only(first_time = false);
  3751. assert(ik->nonstatic_oop_map_count() == 1, "just checking");
  3752. OopMapBlock* map = ik->start_of_nonstatic_oop_maps();
  3753. diff --git a/src/share/vm/oops/klass.cpp b/src/share/vm/oops/klass.cpp
  3754. index ff33181..28537e2 100644
  3755. --- a/src/share/vm/oops/klass.cpp
  3756. +++ b/src/share/vm/oops/klass.cpp
  3757. @@ -55,6 +55,26 @@
  3758. return false;
  3759. }
  3760. +void Klass::update_supers_to_newest_version() {
  3761. +
  3762. + if (super() != NULL) set_super(super()->klass_part()->newest_version());
  3763. +
  3764. + for (uint i=0; i<primary_super_limit(); i++) {
  3765. + klassOop cur = _primary_supers[i];
  3766. + if (cur != NULL) {
  3767. + _primary_supers[i] = cur->klass_part()->newest_version();
  3768. + }
  3769. + }
  3770. +
  3771. + // Scan the array-of-objects
  3772. + int cnt = secondary_supers()->length();
  3773. + for (int i = 0; i < cnt; i++) {
  3774. + klassOop cur = (klassOop)secondary_supers()->obj_at(i);
  3775. + if (cur != NULL) {
  3776. + secondary_supers()->obj_at_put(i, cur->klass_part()->newest_version());
  3777. + }
  3778. + }
  3779. +}
  3780. bool Klass::search_secondary_supers(klassOop k) const {
  3781. // Put some extra logic here out-of-line, before the search proper.
  3782. // This cuts down the size of the inline method.
  3783. @@ -170,6 +190,16 @@
  3784. kl->set_alloc_size(0);
  3785. TRACE_INIT_ID(kl);
  3786. + kl->set_redefinition_flags(Klass::NoRedefinition);
  3787. + kl->set_redefining(false);
  3788. + kl->set_new_version(NULL);
  3789. + kl->set_old_version(NULL);
  3790. + kl->set_redefinition_index(-1);
  3791. + kl->set_revision_number(-1);
  3792. + kl->set_field_redefinition_policy(DynamicCheck);
  3793. + kl->set_static_field_redefinition_policy(AccessDeletedMembers);
  3794. + kl->set_method_redefinition_policy(AccessDeletedMembers);
  3795. +
  3796. kl->set_prototype_header(markOopDesc::prototype());
  3797. kl->set_biased_lock_revocation_count(0);
  3798. kl->set_last_biased_lock_bulk_revocation_time(0);
  3799. @@ -241,7 +271,7 @@
  3800. set_super(NULL);
  3801. oop_store_without_check((oop*) &_primary_supers[0], (oop) this->as_klassOop());
  3802. assert(super_depth() == 0, "Object must already be initialized properly");
  3803. - } else if (k != super() || k == SystemDictionary::Object_klass()) {
  3804. + } else if (k != super() || k->klass_part()->super() == NULL) {
  3805. assert(super() == NULL || super() == SystemDictionary::Object_klass(),
  3806. "initialize this only once to a non-trivial value");
  3807. set_super(k);
  3808. diff --git a/src/share/vm/oops/klass.hpp b/src/share/vm/oops/klass.hpp
  3809. index a449e87..52364ba 100644
  3810. --- a/src/share/vm/oops/klass.hpp
  3811. +++ b/src/share/vm/oops/klass.hpp
  3812. @@ -171,6 +171,7 @@
  3813. void* operator new(size_t ignored, KlassHandle& klass, int size, TRAPS);
  3814. };
  3815. +template<class L, class R> class Pair;
  3816. class Klass : public Klass_vtbl {
  3817. friend class VMStructs;
  3818. @@ -223,6 +224,39 @@
  3819. oop* oop_block_beg() const { return adr_secondary_super_cache(); }
  3820. oop* oop_block_end() const { return adr_next_sibling() + 1; }
  3821. + // (tw) Different class redefinition flags of code evolution.
  3822. + enum RedefinitionFlags {
  3823. +
  3824. + // This class is not redefined at all!
  3825. + NoRedefinition,
  3826. +
  3827. + // There are changes to the class meta data.
  3828. + ModifyClass = 1,
  3829. +
  3830. + // The size of the class meta data changes.
  3831. + ModifyClassSize = ModifyClass << 1,
  3832. +
  3833. + // There are change to the instance format.
  3834. + ModifyInstances = ModifyClassSize << 1,
  3835. +
  3836. + // The size of instances changes.
  3837. + ModifyInstanceSize = ModifyInstances << 1,
  3838. +
  3839. + // A super type of this class is removed.
  3840. + RemoveSuperType = ModifyInstanceSize << 1,
  3841. +
  3842. + // This class (or one of its super classes) has an instance transformer method.
  3843. + HasInstanceTransformer = RemoveSuperType << 1,
  3844. + };
  3845. +
  3846. + // (tw) Different policies dealing with deleted fields / methods in old code.
  3847. + enum RedefinitionPolicy {
  3848. + StaticCheck,
  3849. + DynamicCheck,
  3850. + AccessDeletedMembers,
  3851. + AccessOldMembers
  3852. + };
  3853. +
  3854. protected:
  3855. //
  3856. // The oop block. All oop fields must be declared here and only oop fields
  3857. @@ -242,6 +276,10 @@
  3858. oop _java_mirror;
  3859. // Superclass
  3860. klassOop _super;
  3861. + // Old class
  3862. + klassOop _old_version;
  3863. + // New class
  3864. + klassOop _new_version;
  3865. // First subclass (NULL if none); _subklass->next_sibling() is next one
  3866. klassOop _subklass;
  3867. // Sibling link (or NULL); links all subklasses of a klass
  3868. @@ -253,6 +291,19 @@
  3869. jint _modifier_flags; // Processed access flags, for use by Class.getModifiers.
  3870. AccessFlags _access_flags; // Access flags. The class/interface distinction is stored here.
  3871. +
  3872. + // (tw) Non-oop fields for enhanced class redefinition
  3873. + jint _revision_number; // The revision number for redefined classes
  3874. + jint _redefinition_index; // Index of this class when performing the redefinition
  3875. + bool _subtype_changed;
  3876. + int _redefinition_flags; // Level of class redefinition
  3877. + bool _is_copying_backwards; // Does the class need to copy fields backwards? => possibly overwrite itself?
  3878. + int * _update_information; // Update information
  3879. + Pair<int, klassOop> * _type_check_information; // Offsets of object fields that need a type check
  3880. + char _method_redefinition_policy;
  3881. + char _field_redefinition_policy;
  3882. + char _static_field_redefinition_policy;
  3883. + bool _is_redefining;
  3884. #ifndef PRODUCT
  3885. int _verify_count; // to avoid redundant verifies
  3886. @@ -301,6 +352,99 @@
  3887. klassOop secondary_super_cache() const { return _secondary_super_cache; }
  3888. void set_secondary_super_cache(klassOop k) { oop_store_without_check((oop*) &_secondary_super_cache, (oop) k); }
  3889. +
  3890. + // BEGIN class redefinition utilities
  3891. +
  3892. + // double links between new and old version of a class
  3893. + klassOop old_version() const { return _old_version; }
  3894. + void set_old_version(klassOop klass) { assert(_old_version == NULL || klass == NULL, "Can only be set once!"); _old_version = klass; }
  3895. + klassOop new_version() const { return _new_version; }
  3896. + void set_new_version(klassOop klass) { assert(_new_version == NULL || klass == NULL, "Can only be set once!"); _new_version = klass; }
  3897. +
  3898. + // A subtype of this class is no longer a subtype
  3899. + bool has_subtype_changed() const { return _subtype_changed; }
  3900. + void set_subtype_changed(bool b) { assert(is_newest_version() || new_version()->klass_part()->is_newest_version(), "must be newest or second newest version");
  3901. + _subtype_changed = b; }
  3902. + // state of being redefined
  3903. + int redefinition_index() const { return _redefinition_index; }
  3904. + void set_redefinition_index(int index) { _redefinition_index = index; }
  3905. + void set_redefining(bool b) { _is_redefining = b; }
  3906. + bool is_redefining() const { return _is_redefining; }
  3907. + int redefinition_flags() const { return _redefinition_flags; }
  3908. + bool check_redefinition_flag(int flags) const { return (_redefinition_flags & flags) != 0; }
  3909. + void set_redefinition_flags(int flags) { _redefinition_flags = flags; }
  3910. + bool is_copying_backwards() const { return _is_copying_backwards; }
  3911. + void set_copying_backwards(bool b) { _is_copying_backwards = b; }
  3912. +
  3913. + // update information
  3914. + int *update_information() const { return _update_information; }
  3915. + void set_update_information(int *info) { _update_information = info; }
  3916. + Pair<int, klassOop> *type_check_information() const { return _type_check_information; }
  3917. + void set_type_check_information(Pair<int, klassOop> *info) { _type_check_information = info; }
  3918. +
  3919. + bool is_same_or_older_version(klassOop klass) const {
  3920. + if (Klass::cast(klass) == this) { return true; }
  3921. + else if (_old_version == NULL) { return false; }
  3922. + else { return _old_version->klass_part()->is_same_or_older_version(klass); }
  3923. + }
  3924. +
  3925. + // Revision number for redefined classes, -1 for originally loaded classes
  3926. + jint revision_number() const {
  3927. + return _revision_number;
  3928. + }
  3929. +
  3930. + bool was_redefined() const {
  3931. + return _revision_number != -1;
  3932. + }
  3933. +
  3934. + void set_revision_number(jint number) {
  3935. + _revision_number = number;
  3936. + }
  3937. +
  3938. + char method_redefinition_policy() {
  3939. + return _method_redefinition_policy;
  3940. + }
  3941. +
  3942. + void set_method_redefinition_policy(char v) {
  3943. + _method_redefinition_policy = v;
  3944. + }
  3945. +
  3946. + char field_redefinition_policy() {
  3947. + return _field_redefinition_policy;
  3948. + }
  3949. +
  3950. + void set_field_redefinition_policy(char v) {
  3951. + _field_redefinition_policy = v;
  3952. + }
  3953. +
  3954. + char static_field_redefinition_policy() {
  3955. + return _static_field_redefinition_policy;
  3956. + }
  3957. +
  3958. + void set_static_field_redefinition_policy(char v) {
  3959. + _static_field_redefinition_policy = v;
  3960. + }
  3961. +
  3962. + klassOop oldest_version() const {
  3963. + if (_old_version == NULL) { return this->as_klassOop(); }
  3964. + else { return _old_version->klass_part()->oldest_version(); };
  3965. + }
  3966. +
  3967. + klassOop newest_version() const {
  3968. + if (_new_version == NULL) { return this->as_klassOop(); }
  3969. + else { return _new_version->klass_part()->newest_version(); };
  3970. + }
  3971. +
  3972. + klassOop active_version() const {
  3973. + if (_new_version == NULL || _new_version->klass_part()->is_redefining()) { return this->as_klassOop(); assert(!this->is_redefining(), "just checking"); }
  3974. + else { return _new_version->klass_part()->active_version(); };
  3975. + }
  3976. +
  3977. + bool is_newest_version() const {
  3978. + return _new_version == NULL;
  3979. + }
  3980. +
  3981. + // END class redefinition utilities
  3982. objArrayOop secondary_supers() const { return _secondary_supers; }
  3983. void set_secondary_supers(objArrayOop k) { oop_store_without_check((oop*) &_secondary_supers, (oop) k); }
  3984. @@ -362,6 +506,8 @@
  3985. void set_next_sibling(klassOop s);
  3986. oop* adr_super() const { return (oop*)&_super; }
  3987. + oop* adr_old_version() const { return (oop*)&_old_version; }
  3988. + oop* adr_new_version() const { return (oop*)&_new_version; }
  3989. oop* adr_primary_supers() const { return (oop*)&_primary_supers[0]; }
  3990. oop* adr_secondary_super_cache() const { return (oop*)&_secondary_super_cache; }
  3991. oop* adr_secondary_supers()const { return (oop*)&_secondary_supers; }
  3992. @@ -491,6 +637,7 @@
  3993. return search_secondary_supers(k);
  3994. }
  3995. }
  3996. + void update_supers_to_newest_version();
  3997. bool search_secondary_supers(klassOop k) const;
  3998. // Find LCA in class hierarchy
  3999. @@ -818,6 +965,8 @@
  4000. inline oop klassOopDesc::java_mirror() const { return klass_part()->java_mirror(); }
  4001. +inline klassOop klassOopDesc::old_version() const { return klass_part()->old_version(); }
  4002. +inline klassOop klassOopDesc::new_version() const { return klass_part()->new_version(); }
  4003. #endif // SHARE_VM_OOPS_KLASS_HPP
  4004. diff --git a/src/share/vm/oops/klassKlass.cpp b/src/share/vm/oops/klassKlass.cpp
  4005. index 06809d5..9c08f32 100644
  4006. --- a/src/share/vm/oops/klassKlass.cpp
  4007. +++ b/src/share/vm/oops/klassKlass.cpp
  4008. @@ -68,6 +68,8 @@
  4009. Klass* k = Klass::cast(klassOop(obj));
  4010. // If we are alive it is valid to keep our superclass and subtype caches alive
  4011. MarkSweep::mark_and_push(k->adr_super());
  4012. + MarkSweep::mark_and_push(k->adr_old_version());
  4013. + MarkSweep::mark_and_push(k->adr_new_version());
  4014. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  4015. MarkSweep::mark_and_push(k->adr_primary_supers()+i);
  4016. MarkSweep::mark_and_push(k->adr_secondary_super_cache());
  4017. @@ -87,6 +89,8 @@
  4018. Klass* k = Klass::cast(klassOop(obj));
  4019. // If we are alive it is valid to keep our superclass and subtype caches alive
  4020. PSParallelCompact::mark_and_push(cm, k->adr_super());
  4021. + PSParallelCompact::mark_and_push(cm, k->adr_old_version());
  4022. + PSParallelCompact::mark_and_push(cm, k->adr_new_version());
  4023. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  4024. PSParallelCompact::mark_and_push(cm, k->adr_primary_supers()+i);
  4025. PSParallelCompact::mark_and_push(cm, k->adr_secondary_super_cache());
  4026. @@ -106,6 +110,8 @@
  4027. int size = oop_size(obj);
  4028. Klass* k = Klass::cast(klassOop(obj));
  4029. blk->do_oop(k->adr_super());
  4030. + blk->do_oop(k->adr_old_version());
  4031. + blk->do_oop(k->adr_new_version());
  4032. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  4033. blk->do_oop(k->adr_primary_supers()+i);
  4034. blk->do_oop(k->adr_secondary_super_cache());
  4035. @@ -134,6 +140,10 @@
  4036. oop* adr;
  4037. adr = k->adr_super();
  4038. if (mr.contains(adr)) blk->do_oop(adr);
  4039. + adr = k->adr_old_version();
  4040. + if (mr.contains(adr)) blk->do_oop(adr);
  4041. + adr = k->adr_new_version();
  4042. + if (mr.contains(adr)) blk->do_oop(adr);
  4043. for (juint i = 0; i < Klass::primary_super_limit(); i++) {
  4044. adr = k->adr_primary_supers()+i;
  4045. if (mr.contains(adr)) blk->do_oop(adr);
  4046. @@ -147,6 +157,8 @@
  4047. // The following are "weak links" in the perm gen and are
  4048. // treated specially in a later phase of a perm gen collection.
  4049. assert(oop(k)->is_perm(), "should be in perm");
  4050. + assert(oop(k->adr_old_version())->is_perm(), "should be in perm");
  4051. + assert(oop(k->adr_new_version())->is_perm(), "should be in perm");
  4052. assert(oop(k->adr_subklass())->is_perm(), "should be in perm");
  4053. assert(oop(k->adr_next_sibling())->is_perm(), "should be in perm");
  4054. if (blk->should_remember_klasses()
  4055. @@ -167,6 +179,8 @@
  4056. Klass* k = Klass::cast(klassOop(obj));
  4057. MarkSweep::adjust_pointer(k->adr_super());
  4058. + MarkSweep::adjust_pointer(k->adr_new_version());
  4059. + MarkSweep::adjust_pointer(k->adr_old_version());
  4060. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  4061. MarkSweep::adjust_pointer(k->adr_primary_supers()+i);
  4062. MarkSweep::adjust_pointer(k->adr_secondary_super_cache());
  4063. diff --git a/src/share/vm/oops/klassOop.hpp b/src/share/vm/oops/klassOop.hpp
  4064. index f212fc5..9731a9c 100644
  4065. --- a/src/share/vm/oops/klassOop.hpp
  4066. +++ b/src/share/vm/oops/klassOop.hpp
  4067. @@ -41,8 +41,10 @@
  4068. // returns the Klass part containing dispatching behavior
  4069. Klass* klass_part() const { return (Klass*)((address)this + sizeof(klassOopDesc)); }
  4070. - // Convenience wrapper
  4071. + // Convenience wrappers
  4072. inline oop java_mirror() const;
  4073. + inline klassOop old_version() const;
  4074. + inline klassOop new_version() const;
  4075. private:
  4076. // These have no implementation since klassOop should never be accessed in this fashion
  4077. diff --git a/src/share/vm/oops/klassVtable.cpp b/src/share/vm/oops/klassVtable.cpp
  4078. index ff22444..8d39611 100644
  4079. --- a/src/share/vm/oops/klassVtable.cpp
  4080. +++ b/src/share/vm/oops/klassVtable.cpp
  4081. @@ -97,7 +97,8 @@
  4082. vtable_length = Universe::base_vtable_size();
  4083. }
  4084. - if (super == NULL && !Universe::is_bootstrapping() &&
  4085. + // (tw) TODO: Check if we can relax the condition on a fixed base vtable size
  4086. + /*if (super == NULL && !Universe::is_bootstrapping() &&
  4087. vtable_length != Universe::base_vtable_size()) {
  4088. // Someone is attempting to redefine java.lang.Object incorrectly. The
  4089. // only way this should happen is from
  4090. @@ -107,9 +108,9 @@
  4091. vtable_length = Universe::base_vtable_size();
  4092. }
  4093. assert(super != NULL || vtable_length == Universe::base_vtable_size(),
  4094. - "bad vtable size for class Object");
  4095. + "bad vtable size for class Object");*/
  4096. assert(vtable_length % vtableEntry::size() == 0, "bad vtable length");
  4097. - assert(vtable_length >= Universe::base_vtable_size(), "vtable too small");
  4098. + //assert(vtable_length >= Universe::base_vtable_size(), "vtable too small");
  4099. }
  4100. int klassVtable::index_of(methodOop m, int len) const {
  4101. @@ -676,20 +677,6 @@
  4102. }
  4103. }
  4104. return true;
  4105. -}
  4106. -
  4107. -void klassVtable::dump_vtable() {
  4108. - tty->print_cr("vtable dump --");
  4109. - for (int i = 0; i < length(); i++) {
  4110. - methodOop m = unchecked_method_at(i);
  4111. - if (m != NULL) {
  4112. - tty->print(" (%5d) ", i);
  4113. - m->access_flags().print_on(tty);
  4114. - tty->print(" -- ");
  4115. - m->print_name(tty);
  4116. - tty->cr();
  4117. - }
  4118. - }
  4119. }
  4120. // CDS/RedefineClasses support - clear vtables so they can be reinitialized
  4121. @@ -1262,6 +1249,7 @@
  4122. void klassVtable::verify_against(outputStream* st, klassVtable* vt, int index) {
  4123. vtableEntry* vte = &vt->table()[index];
  4124. + if (vte->method() == NULL || table()[index].method() == NULL) return;
  4125. if (vte->method()->name() != table()[index].method()->name() ||
  4126. vte->method()->signature() != table()[index].method()->signature()) {
  4127. fatal("mismatched name/signature of vtable entries");
  4128. @@ -1281,6 +1269,8 @@
  4129. void vtableEntry::verify(klassVtable* vt, outputStream* st) {
  4130. NOT_PRODUCT(FlagSetting fs(IgnoreLockingAssertions, true));
  4131. + // (tw) TODO: Check: Does not hold?
  4132. + if (method() != NULL) {
  4133. assert(method() != NULL, "must have set method");
  4134. method()->verify();
  4135. // we sub_type, because it could be a miranda method
  4136. @@ -1288,7 +1278,13 @@
  4137. #ifndef PRODUCT
  4138. print();
  4139. #endif
  4140. - fatal(err_msg("vtableEntry " PTR_FORMAT ": method is from subclass", this));
  4141. + klassOop first_klass = vt->klass()();
  4142. + klassOop second_klass = method()->method_holder();
  4143. + // (tw) the following fatal does not work for old versions of classes
  4144. + if (first_klass->klass_part()->is_newest_version()) {
  4145. + //fatal1("vtableEntry %#lx: method is from subclass", this);
  4146. + }
  4147. + }
  4148. }
  4149. }
  4150. @@ -1296,7 +1292,7 @@
  4151. void vtableEntry::print() {
  4152. ResourceMark rm;
  4153. - tty->print("vtableEntry %s: ", method()->name()->as_C_string());
  4154. + tty->print("vtableEntry %s: ", (method() == NULL) ? "null" : method()->name()->as_C_string());
  4155. if (Verbose) {
  4156. tty->print("m %#lx ", (address)method());
  4157. }
  4158. @@ -1363,6 +1359,33 @@
  4159. tty->print_cr("%6d bytes total", total);
  4160. }
  4161. +bool klassVtable::check_no_old_entries() {
  4162. + // Check that there really is no entry
  4163. + for (int i = 0; i < length(); i++) {
  4164. + methodOop m = unchecked_method_at(i);
  4165. + if (m != NULL) {
  4166. + if (m->is_old() || !m->method_holder()->klass_part()->is_newest_version()) {
  4167. + return false;
  4168. + }
  4169. + }
  4170. + }
  4171. + return true;
  4172. +}
  4173. +
  4174. +void klassVtable::dump_vtable() {
  4175. + tty->print_cr("vtable dump --");
  4176. + for (int i = 0; i < length(); i++) {
  4177. + methodOop m = unchecked_method_at(i);
  4178. + if (m != NULL) {
  4179. + tty->print(" (%5d) ", i);
  4180. + m->access_flags().print_on(tty);
  4181. + tty->print(" -- ");
  4182. + m->print_name(tty);
  4183. + tty->cr();
  4184. + }
  4185. + }
  4186. +}
  4187. +
  4188. int klassItable::_total_classes; // Total no. of classes with itables
  4189. long klassItable::_total_size; // Total no. of bytes used for itables
  4190. diff --git a/src/share/vm/oops/klassVtable.hpp b/src/share/vm/oops/klassVtable.hpp
  4191. index 405b0c7..0c8d2f7 100644
  4192. --- a/src/share/vm/oops/klassVtable.hpp
  4193. +++ b/src/share/vm/oops/klassVtable.hpp
  4194. @@ -100,6 +100,7 @@
  4195. int methods_length, bool * trace_name_printed);
  4196. bool check_no_old_or_obsolete_entries();
  4197. void dump_vtable();
  4198. + bool check_no_old_entries();
  4199. // Garbage collection
  4200. void oop_follow_contents();
  4201. diff --git a/src/share/vm/oops/methodKlass.cpp b/src/share/vm/oops/methodKlass.cpp
  4202. index 75d0b09..f1b7d2f 100644
  4203. --- a/src/share/vm/oops/methodKlass.cpp
  4204. +++ b/src/share/vm/oops/methodKlass.cpp
  4205. @@ -93,6 +93,10 @@
  4206. m->set_adapter_entry(NULL);
  4207. m->clear_code(); // from_c/from_i get set to c2i/i2i
  4208. + m->set_forward_method(NULL);
  4209. + m->set_new_version(NULL);
  4210. + m->set_old_version(NULL);
  4211. +
  4212. if (access_flags.is_native()) {
  4213. m->clear_native_function();
  4214. m->set_signature_handler(NULL);
  4215. @@ -122,6 +126,9 @@
  4216. // Performance tweak: We skip iterating over the klass pointer since we
  4217. // know that Universe::methodKlassObj never moves.
  4218. MarkSweep::mark_and_push(m->adr_constMethod());
  4219. + MarkSweep::mark_and_push(m->adr_forward_method());
  4220. + MarkSweep::mark_and_push(m->adr_new_version());
  4221. + MarkSweep::mark_and_push(m->adr_old_version());
  4222. if (m->method_data() != NULL) {
  4223. MarkSweep::mark_and_push(m->adr_method_data());
  4224. }
  4225. @@ -135,6 +142,9 @@
  4226. // Performance tweak: We skip iterating over the klass pointer since we
  4227. // know that Universe::methodKlassObj never moves.
  4228. PSParallelCompact::mark_and_push(cm, m->adr_constMethod());
  4229. + PSParallelCompact::mark_and_push(cm, m->adr_forward_method());
  4230. + PSParallelCompact::mark_and_push(cm, m->adr_new_version());
  4231. + PSParallelCompact::mark_and_push(cm, m->adr_old_version());
  4232. #ifdef COMPILER2
  4233. if (m->method_data() != NULL) {
  4234. PSParallelCompact::mark_and_push(cm, m->adr_method_data());
  4235. @@ -152,6 +162,9 @@
  4236. // Performance tweak: We skip iterating over the klass pointer since we
  4237. // know that Universe::methodKlassObj never moves
  4238. blk->do_oop(m->adr_constMethod());
  4239. + blk->do_oop(m->adr_forward_method());
  4240. + blk->do_oop(m->adr_new_version());
  4241. + blk->do_oop(m->adr_old_version());
  4242. if (m->method_data() != NULL) {
  4243. blk->do_oop(m->adr_method_data());
  4244. }
  4245. @@ -170,6 +183,12 @@
  4246. oop* adr;
  4247. adr = m->adr_constMethod();
  4248. if (mr.contains(adr)) blk->do_oop(adr);
  4249. + adr = m->adr_new_version();
  4250. + if (mr.contains(adr)) blk->do_oop(adr);
  4251. + adr = m->adr_forward_method();
  4252. + if (mr.contains(adr)) blk->do_oop(adr);
  4253. + adr = m->adr_old_version();
  4254. + if (mr.contains(adr)) blk->do_oop(adr);
  4255. if (m->method_data() != NULL) {
  4256. adr = m->adr_method_data();
  4257. if (mr.contains(adr)) blk->do_oop(adr);
  4258. @@ -187,6 +206,9 @@
  4259. // Performance tweak: We skip iterating over the klass pointer since we
  4260. // know that Universe::methodKlassObj never moves.
  4261. MarkSweep::adjust_pointer(m->adr_constMethod());
  4262. + MarkSweep::adjust_pointer(m->adr_forward_method());
  4263. + MarkSweep::adjust_pointer(m->adr_new_version());
  4264. + MarkSweep::adjust_pointer(m->adr_old_version());
  4265. if (m->method_data() != NULL) {
  4266. MarkSweep::adjust_pointer(m->adr_method_data());
  4267. }
  4268. @@ -202,6 +224,9 @@
  4269. assert(obj->is_method(), "should be method");
  4270. methodOop m = methodOop(obj);
  4271. PSParallelCompact::adjust_pointer(m->adr_constMethod());
  4272. + PSParallelCompact::adjust_pointer(m->adr_forward_method());
  4273. + PSParallelCompact::adjust_pointer(m->adr_new_version());
  4274. + PSParallelCompact::adjust_pointer(m->adr_old_version());
  4275. #ifdef COMPILER2
  4276. if (m->method_data() != NULL) {
  4277. PSParallelCompact::adjust_pointer(m->adr_method_data());
  4278. @@ -222,7 +247,18 @@
  4279. methodOop m = methodOop(obj);
  4280. // get the effect of PrintOopAddress, always, for methods:
  4281. st->print_cr(" - this oop: "INTPTR_FORMAT, (intptr_t)m);
  4282. - st->print (" - method holder: "); m->method_holder()->print_value_on(st); st->cr();
  4283. + st->print (" - method holder: "); m->method_holder()->print_value_on(st);
  4284. +
  4285. + if (m->method_holder()->klass_part()->new_version() != NULL) {
  4286. + st->print(" (old)");
  4287. + }
  4288. + st->cr();
  4289. +
  4290. + st->print_cr(" - is obsolete: %d", (int)(m->is_obsolete()));
  4291. + st->print_cr(" - is old: %d", (int)(m->is_old()));
  4292. + st->print_cr(" - new version: "INTPTR_FORMAT" ", (address)(m->new_version()));
  4293. + st->print_cr(" - old version: "INTPTR_FORMAT" ", (address)(m->old_version()));
  4294. + st->print_cr(" - holder revision: %d", m->method_holder()->klass_part()->revision_number());
  4295. st->print (" - constants: "INTPTR_FORMAT" ", (address)m->constants());
  4296. m->constants()->print_value_on(st); st->cr();
  4297. st->print (" - access: 0x%x ", m->access_flags().as_int()); m->access_flags().print_on(st); st->cr();
  4298. diff --git a/src/share/vm/oops/methodOop.cpp b/src/share/vm/oops/methodOop.cpp
  4299. index 4f59d3a..5cdf147 100644
  4300. --- a/src/share/vm/oops/methodOop.cpp
  4301. +++ b/src/share/vm/oops/methodOop.cpp
  4302. @@ -328,6 +328,70 @@
  4303. }
  4304. +bool methodOopDesc::is_in_code_section(int bci) {
  4305. + // There is no table => every bci is in the code section table.
  4306. + if (!constMethod()->has_code_section_table()) return true;
  4307. +
  4308. + constMethodOop m = constMethod();
  4309. + for (int i = 0; i < m->code_section_entries(); ++i) {
  4310. + u2 new_index = m->code_section_new_index_at(i);
  4311. + u2 length = m->code_section_length_at(i);
  4312. + if (bci >= new_index && bci < new_index + length) {
  4313. + // We are in a specified code section.
  4314. + return true;
  4315. + }
  4316. + }
  4317. +
  4318. + return false;
  4319. +}
  4320. +
  4321. +int methodOopDesc::calculate_forward_bci(int bci, methodOop new_method) {
  4322. + int original_bci = -1;
  4323. + if (constMethod()->has_code_section_table()) {
  4324. + assert(is_in_code_section(bci), "can only forward in section");
  4325. + // First calculate back to original bci.
  4326. + constMethodOop m = constMethod();
  4327. + for (int i = 0; i < m->code_section_entries(); ++i) {
  4328. + u2 new_index = m->code_section_new_index_at(i);
  4329. + u2 original_index = m->code_section_original_index_at(i);
  4330. + u2 length = m->code_section_length_at(i);
  4331. + if (bci >= new_index && bci < new_index + length) {
  4332. + // We are in a specified code section.
  4333. + original_bci = bci - new_index + original_index;
  4334. + break;
  4335. + }
  4336. + }
  4337. + assert (original_bci != -1, "must have been in code section");
  4338. + } else {
  4339. + // No code sections specified => we are in an original method.
  4340. + original_bci = bci;
  4341. + }
  4342. +
  4343. + // We know the original bci => match to new method.
  4344. + int new_bci = -1;
  4345. + if (new_method->constMethod()->has_code_section_table()) {
  4346. + // Map to new bci.
  4347. + constMethodOop m = new_method->constMethod();
  4348. + for (int i = 0; i < m->code_section_entries(); ++i) {
  4349. + u2 new_index = m->code_section_new_index_at(i);
  4350. + u2 original_index = m->code_section_original_index_at(i);
  4351. + u2 length = m->code_section_length_at(i);
  4352. + if (original_bci >= original_index && original_bci < original_index + length) {
  4353. + new_bci = original_bci - original_index + new_index;
  4354. + break;
  4355. + }
  4356. + }
  4357. + assert (new_bci != -1, "must have found new code section");
  4358. +
  4359. + } else {
  4360. + // We are in an original method.
  4361. + new_bci = original_bci;
  4362. + }
  4363. +
  4364. + return new_bci;
  4365. +}
  4366. +
  4367. +
  4368. int methodOopDesc::extra_stack_words() {
  4369. // not an inline function, to avoid a header dependency on Interpreter
  4370. return extra_stack_entries() * Interpreter::stackElementSize;
  4371. @@ -1061,6 +1125,9 @@
  4372. // Reset correct method/const method, method size, and parameter info
  4373. newm->set_constMethod(newcm);
  4374. + newm->set_forward_method(newm->forward_method());
  4375. + newm->set_new_version(newm->new_version());
  4376. + newm->set_old_version(newm->old_version());
  4377. newm->constMethod()->set_code_size(new_code_length);
  4378. newm->constMethod()->set_constMethod_size(new_const_method_size);
  4379. newm->set_method_size(new_method_size);
  4380. diff --git a/src/share/vm/oops/methodOop.hpp b/src/share/vm/oops/methodOop.hpp
  4381. index 486e106..11e52bb 100644
  4382. --- a/src/share/vm/oops/methodOop.hpp
  4383. +++ b/src/share/vm/oops/methodOop.hpp
  4384. @@ -114,6 +114,11 @@
  4385. AccessFlags _access_flags; // Access flags
  4386. int _vtable_index; // vtable index of this method (see VtableIndexFlag)
  4387. // note: can have vtables with >2**16 elements (because of inheritance)
  4388. + // (tw) Newer version of method available?
  4389. + methodOop _forward_method;
  4390. + methodOop _new_version;
  4391. + methodOop _old_version;
  4392. +
  4393. #ifdef CC_INTERP
  4394. int _result_index; // C++ interpreter needs for converting results to/from stack
  4395. #endif
  4396. @@ -174,6 +179,32 @@
  4397. Symbol* name() const { return constants()->symbol_at(name_index()); }
  4398. int name_index() const { return constMethod()->name_index(); }
  4399. void set_name_index(int index) { constMethod()->set_name_index(index); }
  4400. +
  4401. + methodOop forward_method() const {return _forward_method; }
  4402. + void set_forward_method(methodOop m) { _forward_method = m; }
  4403. + bool has_forward_method() const { return forward_method() != NULL; }
  4404. + methodOop new_version() const {return _new_version; }
  4405. + void set_new_version(methodOop m) { _new_version = m; }
  4406. + methodOop newest_version() { if(_new_version == NULL) return this; else return new_version()->newest_version(); }
  4407. +
  4408. + methodOop old_version() const {return _old_version; };
  4409. + void set_old_version(methodOop m) {
  4410. + if (m == NULL) {
  4411. + _old_version = NULL;
  4412. + return;
  4413. + }
  4414. +
  4415. + assert(_old_version == NULL, "may only be set once");
  4416. + assert(this->code_size() == m->code_size(), "must have same code length");
  4417. + _old_version = m;
  4418. + }
  4419. +
  4420. + methodOop oldest_version() const {
  4421. + if(_old_version == NULL) return (methodOop)this;
  4422. + else {
  4423. + return old_version()->oldest_version();
  4424. + }
  4425. + }
  4426. // signature
  4427. Symbol* signature() const { return constants()->symbol_at(signature_index()); }
  4428. @@ -670,6 +701,10 @@
  4429. // Inline cache support
  4430. void cleanup_inline_caches();
  4431. + // (tw) Method forwarding support.
  4432. + bool is_in_code_section(int bci);
  4433. + int calculate_forward_bci(int bci, methodOop new_method);
  4434. +
  4435. // Find if klass for method is loaded
  4436. bool is_klass_loaded_by_klass_index(int klass_index) const;
  4437. bool is_klass_loaded(int refinfo_index, bool must_be_resolved = false) const;
  4438. @@ -734,6 +769,9 @@
  4439. // Garbage collection support
  4440. oop* adr_constMethod() const { return (oop*)&_constMethod; }
  4441. + oop* adr_forward_method() const { return (oop*)&_forward_method; }
  4442. + oop* adr_new_version() const { return (oop*)&_new_version; }
  4443. + oop* adr_old_version() const { return (oop*)&_old_version; }
  4444. oop* adr_method_data() const { return (oop*)&_method_data; }
  4445. };
  4446. diff --git a/src/share/vm/oops/oop.hpp b/src/share/vm/oops/oop.hpp
  4447. index 5982c88..4873fca 100644
  4448. --- a/src/share/vm/oops/oop.hpp
  4449. +++ b/src/share/vm/oops/oop.hpp
  4450. @@ -95,6 +95,7 @@
  4451. narrowOop* compressed_klass_addr();
  4452. void set_klass(klassOop k);
  4453. + void set_klass_no_check(klassOop k);
  4454. // For klass field compression
  4455. int klass_gap() const;
  4456. @@ -135,6 +136,7 @@
  4457. bool is_array() const;
  4458. bool is_objArray() const;
  4459. bool is_klass() const;
  4460. + bool is_instanceKlass() const;
  4461. bool is_thread() const;
  4462. bool is_method() const;
  4463. bool is_constMethod() const;
  4464. diff --git a/src/share/vm/oops/oop.inline.hpp b/src/share/vm/oops/oop.inline.hpp
  4465. index f4eb2f7..0acb346 100644
  4466. --- a/src/share/vm/oops/oop.inline.hpp
  4467. +++ b/src/share/vm/oops/oop.inline.hpp
  4468. @@ -123,6 +123,14 @@
  4469. }
  4470. }
  4471. +inline void oopDesc::set_klass_no_check(klassOop k) {
  4472. + if (UseCompressedOops) {
  4473. + oop_store_without_check(compressed_klass_addr(), (oop)k);
  4474. + } else {
  4475. + oop_store_without_check(klass_addr(), (oop) k);
  4476. + }
  4477. +}
  4478. +
  4479. inline int oopDesc::klass_gap() const {
  4480. return *(int*)(((intptr_t)this) + klass_gap_offset_in_bytes());
  4481. }
  4482. @@ -156,6 +164,7 @@
  4483. inline bool oopDesc::is_typeArray() const { return blueprint()->oop_is_typeArray(); }
  4484. inline bool oopDesc::is_javaArray() const { return blueprint()->oop_is_javaArray(); }
  4485. inline bool oopDesc::is_klass() const { return blueprint()->oop_is_klass(); }
  4486. +inline bool oopDesc::is_instanceKlass() const { return blueprint()->oop_is_instanceKlass(); }
  4487. inline bool oopDesc::is_thread() const { return blueprint()->oop_is_thread(); }
  4488. inline bool oopDesc::is_method() const { return blueprint()->oop_is_method(); }
  4489. inline bool oopDesc::is_constMethod() const { return blueprint()->oop_is_constMethod(); }
  4490. diff --git a/src/share/vm/prims/jni.cpp b/src/share/vm/prims/jni.cpp
  4491. index 50e1263..701ed74 100644
  4492. --- a/src/share/vm/prims/jni.cpp
  4493. +++ b/src/share/vm/prims/jni.cpp
  4494. @@ -406,7 +406,7 @@
  4495. }
  4496. }
  4497. klassOop k = SystemDictionary::resolve_from_stream(class_name, class_loader,
  4498. - Handle(), &st, true,
  4499. + Handle(), &st, true, KlassHandle(),
  4500. CHECK_NULL);
  4501. if (TraceClassResolution && k != NULL) {
  4502. diff --git a/src/share/vm/prims/jvm.cpp b/src/share/vm/prims/jvm.cpp
  4503. index ccd09f6..ef3f024 100644
  4504. --- a/src/share/vm/prims/jvm.cpp
  4505. +++ b/src/share/vm/prims/jvm.cpp
  4506. @@ -932,7 +932,7 @@
  4507. Handle protection_domain (THREAD, JNIHandles::resolve(pd));
  4508. klassOop k = SystemDictionary::resolve_from_stream(class_name, class_loader,
  4509. protection_domain, &st,
  4510. - verify != 0,
  4511. + verify != 0, KlassHandle(),
  4512. CHECK_NULL);
  4513. if (TraceClassResolution && k != NULL) {
  4514. diff --git a/src/share/vm/prims/jvmtiEnv.cpp b/src/share/vm/prims/jvmtiEnv.cpp
  4515. index 4ac6b82..30b8e84 100644
  4516. --- a/src/share/vm/prims/jvmtiEnv.cpp
  4517. +++ b/src/share/vm/prims/jvmtiEnv.cpp
  4518. @@ -290,7 +290,10 @@
  4519. class_definitions[index].klass = jcls;
  4520. }
  4521. VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_retransform);
  4522. - VMThread::execute(&op);
  4523. + {
  4524. + MutexLocker sd_mutex(RedefineClasses_lock);
  4525. + VMThread::execute(&op);
  4526. + }
  4527. return (op.check_error());
  4528. } /* end RetransformClasses */
  4529. @@ -299,9 +302,12 @@
  4530. // class_definitions - pre-checked for NULL
  4531. jvmtiError
  4532. JvmtiEnv::RedefineClasses(jint class_count, const jvmtiClassDefinition* class_definitions) {
  4533. -//TODO: add locking
  4534. +
  4535. VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_redefine);
  4536. - VMThread::execute(&op);
  4537. + {
  4538. + MutexLocker sd_mutex(RedefineClasses_lock);
  4539. + VMThread::execute(&op);
  4540. + }
  4541. return (op.check_error());
  4542. } /* end RedefineClasses */
  4543. diff --git a/src/share/vm/prims/jvmtiExport.cpp b/src/share/vm/prims/jvmtiExport.cpp
  4544. index ec8ede3..2bd5983 100644
  4545. --- a/src/share/vm/prims/jvmtiExport.cpp
  4546. +++ b/src/share/vm/prims/jvmtiExport.cpp
  4547. @@ -2296,7 +2296,7 @@
  4548. // iterate over any code blob descriptors collected and post a
  4549. // DYNAMIC_CODE_GENERATED event to the profiler.
  4550. JvmtiDynamicCodeEventCollector::~JvmtiDynamicCodeEventCollector() {
  4551. - assert(!JavaThread::current()->owns_locks(), "all locks must be released to post deferred events");
  4552. + assert(!JavaThread::current()->owns_locks_but_redefine_classes_lock(), "all locks must be released to post deferred events");
  4553. // iterate over any code blob descriptors that we collected
  4554. if (_code_blobs != NULL) {
  4555. for (int i=0; i<_code_blobs->length(); i++) {
  4556. diff --git a/src/share/vm/prims/jvmtiImpl.cpp b/src/share/vm/prims/jvmtiImpl.cpp
  4557. index d3fa140..f4f8b57 100644
  4558. --- a/src/share/vm/prims/jvmtiImpl.cpp
  4559. +++ b/src/share/vm/prims/jvmtiImpl.cpp
  4560. @@ -286,6 +286,8 @@
  4561. void JvmtiBreakpoint::each_method_version_do(method_action meth_act) {
  4562. ((methodOopDesc*)_method->*meth_act)(_bci);
  4563. + // DCEVM: TODO: Check how we can implement this differently here!
  4564. +
  4565. // add/remove breakpoint to/from versions of the method that
  4566. // are EMCP. Directly or transitively obsolete methods are
  4567. // not saved in the PreviousVersionInfo.
  4568. diff --git a/src/share/vm/prims/jvmtiRedefineClasses.cpp b/src/share/vm/prims/jvmtiRedefineClasses.cpp
  4569. index 606be1c..ef4f380 100644
  4570. --- a/src/share/vm/prims/jvmtiRedefineClasses.cpp
  4571. +++ b/src/share/vm/prims/jvmtiRedefineClasses.cpp
  4572. @@ -1,5 +1,5 @@
  4573. /*
  4574. - * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
  4575. + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  4576. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4577. *
  4578. * This code is free software; you can redistribute it and/or modify it
  4579. @@ -30,581 +30,637 @@
  4580. #include "interpreter/rewriter.hpp"
  4581. #include "memory/gcLocker.hpp"
  4582. #include "memory/universe.inline.hpp"
  4583. -#include "oops/fieldStreams.hpp"
  4584. +#include "memory/cardTableRS.hpp"
  4585. #include "oops/klassVtable.hpp"
  4586. +#include "oops/fieldStreams.hpp"
  4587. #include "prims/jvmtiImpl.hpp"
  4588. #include "prims/jvmtiRedefineClasses.hpp"
  4589. +#include "prims/jvmtiClassFileReconstituter.hpp"
  4590. #include "prims/methodComparator.hpp"
  4591. -#include "prims/methodHandles.hpp"
  4592. #include "runtime/deoptimization.hpp"
  4593. #include "runtime/relocator.hpp"
  4594. #include "utilities/bitMap.inline.hpp"
  4595. +#include "compiler/compileBroker.hpp"
  4596. objArrayOop VM_RedefineClasses::_old_methods = NULL;
  4597. objArrayOop VM_RedefineClasses::_new_methods = NULL;
  4598. -methodOop* VM_RedefineClasses::_matching_old_methods = NULL;
  4599. -methodOop* VM_RedefineClasses::_matching_new_methods = NULL;
  4600. -methodOop* VM_RedefineClasses::_deleted_methods = NULL;
  4601. -methodOop* VM_RedefineClasses::_added_methods = NULL;
  4602. +int* VM_RedefineClasses::_matching_old_methods = NULL;
  4603. +int* VM_RedefineClasses::_matching_new_methods = NULL;
  4604. +int* VM_RedefineClasses::_deleted_methods = NULL;
  4605. +int* VM_RedefineClasses::_added_methods = NULL;
  4606. int VM_RedefineClasses::_matching_methods_length = 0;
  4607. int VM_RedefineClasses::_deleted_methods_length = 0;
  4608. int VM_RedefineClasses::_added_methods_length = 0;
  4609. klassOop VM_RedefineClasses::_the_class_oop = NULL;
  4610. +// Holds the revision number of the current class redefinition
  4611. +int VM_RedefineClasses::_revision_number = -1;
  4612. -VM_RedefineClasses::VM_RedefineClasses(jint class_count,
  4613. - const jvmtiClassDefinition *class_defs,
  4614. - JvmtiClassLoadKind class_load_kind) {
  4615. +VM_RedefineClasses::VM_RedefineClasses(jint class_count, const jvmtiClassDefinition *class_defs, JvmtiClassLoadKind class_load_kind)
  4616. + : VM_GC_Operation(Universe::heap()->total_full_collections(), GCCause::_jvmti_force_gc) {
  4617. + RC_TIMER_START(_timer_total);
  4618. _class_count = class_count;
  4619. _class_defs = class_defs;
  4620. _class_load_kind = class_load_kind;
  4621. - _res = JVMTI_ERROR_NONE;
  4622. + _updated_oops = NULL;
  4623. + _result = JVMTI_ERROR_NONE;
  4624. }
  4625. -bool VM_RedefineClasses::doit_prologue() {
  4626. - if (_class_count == 0) {
  4627. - _res = JVMTI_ERROR_NONE;
  4628. - return false;
  4629. +VM_RedefineClasses::~VM_RedefineClasses() {
  4630. + {
  4631. + MonitorLockerEx ml(RedefinitionSync_lock);
  4632. + Threads::set_wait_at_instrumentation_entry(false);
  4633. + ml.notify_all();
  4634. }
  4635. - if (_class_defs == NULL) {
  4636. - _res = JVMTI_ERROR_NULL_POINTER;
  4637. - return false;
  4638. +
  4639. + unlock_threads();
  4640. + RC_TIMER_STOP(_timer_total);
  4641. +
  4642. + if (TimeRedefineClasses) {
  4643. + tty->print_cr("Timing Prologue: %d", _timer_prologue.milliseconds());
  4644. + tty->print_cr("Timing Class Loading: %d", _timer_class_loading.milliseconds());
  4645. + tty->print_cr("Timing Waiting for Lock: %d", _timer_wait_for_locks.milliseconds());
  4646. + tty->print_cr("Timing Class Linking: %d", _timer_class_linking.milliseconds());
  4647. + tty->print_cr("Timing Check Type: %d", _timer_check_type.milliseconds());
  4648. + tty->print_cr("Timing Prepare Redefinition: %d", _timer_prepare_redefinition.milliseconds());
  4649. + tty->print_cr("Timing Redefinition GC: %d", _timer_redefinition.milliseconds());
  4650. + tty->print_cr("Timing Epilogue: %d", _timer_vm_op_epilogue.milliseconds());
  4651. + tty->print_cr("------------------------------------------------------------------");
  4652. + tty->print_cr("Total Time: %d", _timer_total.milliseconds());
  4653. }
  4654. - for (int i = 0; i < _class_count; i++) {
  4655. - if (_class_defs[i].klass == NULL) {
  4656. - _res = JVMTI_ERROR_INVALID_CLASS;
  4657. - return false;
  4658. - }
  4659. - if (_class_defs[i].class_byte_count == 0) {
  4660. - _res = JVMTI_ERROR_INVALID_CLASS_FORMAT;
  4661. - return false;
  4662. - }
  4663. - if (_class_defs[i].class_bytes == NULL) {
  4664. - _res = JVMTI_ERROR_NULL_POINTER;
  4665. - return false;
  4666. +}
  4667. +
  4668. +// Searches for all affected classes and performs a sorting such that a supertype is always before a subtype.
  4669. +jvmtiError VM_RedefineClasses::find_sorted_affected_classes(GrowableArray<instanceKlassHandle> *all_affected_klasses) {
  4670. +
  4671. + // Create array with all classes for which the redefine command was given
  4672. + GrowableArray<instanceKlassHandle> klasses_to_redefine;
  4673. + for (int i=0; i<_class_count; i++) {
  4674. + oop mirror = JNIHandles::resolve_non_null(_class_defs[i].klass);
  4675. + instanceKlassHandle klass_handle(Thread::current(), java_lang_Class::as_klassOop(mirror));
  4676. + klasses_to_redefine.append(klass_handle);
  4677. + assert(klass_handle->new_version() == NULL, "Must be new class");
  4678. + }
  4679. +
  4680. + // Find classes not directly redefined, but affected by a redefinition (because one of its supertypes is redefined)
  4681. + GrowableArray<instanceKlassHandle> affected_classes;
  4682. + FindAffectedKlassesClosure closure(&klasses_to_redefine, &affected_classes);
  4683. +
  4684. + // Trace affected classes
  4685. + if (RC_TRACE_ENABLED(0x00000001)) {
  4686. + RC_TRACE(0x00000001, ("Klasses affected: %d",
  4687. + affected_classes.length()));
  4688. + for (int i=0; i<affected_classes.length(); i++) {
  4689. + RC_TRACE(0x00000001, ("%s",
  4690. + affected_classes.at(i)->name()->as_C_string()));
  4691. }
  4692. }
  4693. - // Start timer after all the sanity checks; not quite accurate, but
  4694. - // better than adding a bunch of stop() calls.
  4695. - RC_TIMER_START(_timer_vm_op_prologue);
  4696. + // Add the array of affected classes and the array of redefined classes to get a list of all classes that need a redefinition
  4697. + all_affected_klasses->appendAll(&klasses_to_redefine);
  4698. + all_affected_klasses->appendAll(&affected_classes);
  4699. +
  4700. + // Sort the affected klasses such that a supertype is always on a smaller array index than its subtype.
  4701. + jvmtiError result = do_topological_class_sorting(_class_defs, _class_count, &affected_classes, all_affected_klasses, Thread::current());
  4702. + if (RC_TRACE_ENABLED(0x00000001)) {
  4703. + RC_TRACE(0x00000001, ("Redefine order: "));
  4704. + for (int i=0; i<all_affected_klasses->length(); i++) {
  4705. + RC_TRACE(0x00000001, ("%s",
  4706. + all_affected_klasses->at(i)->name()->as_C_string()));
  4707. + }
  4708. + }
  4709. +
  4710. + return result;
  4711. +}
  4712. +
  4713. +// Searches for the class bytes of the given class and returns them as a byte array.
  4714. +jvmtiError VM_RedefineClasses::find_class_bytes(instanceKlassHandle the_class, const unsigned char **class_bytes, jint *class_byte_count, jboolean *not_changed) {
  4715. +
  4716. + *not_changed = false;
  4717. +
  4718. + // Search for the index in the redefinition array that corresponds to the current class
  4719. + int j;
  4720. + for (j=0; j<_class_count; j++) {
  4721. + oop mirror = JNIHandles::resolve_non_null(_class_defs[j].klass);
  4722. + klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
  4723. + if (the_class_oop == the_class()) {
  4724. + break;
  4725. + }
  4726. + }
  4727. +
  4728. + if (j == _class_count) {
  4729. +
  4730. + *not_changed = true;
  4731. +
  4732. + // Redefine with same bytecodes. This is a class that is only indirectly affected by redefinition,
  4733. + // so the user did not specify a different bytecode for that class.
  4734. +
  4735. + if (the_class->get_cached_class_file_bytes() == NULL) {
  4736. + // not cached, we need to reconstitute the class file from VM representation
  4737. + constantPoolHandle constants(Thread::current(), the_class->constants());
  4738. + ObjectLocker ol(constants, Thread::current()); // lock constant pool while we query it
  4739. +
  4740. + JvmtiClassFileReconstituter reconstituter(the_class);
  4741. + if (reconstituter.get_error() != JVMTI_ERROR_NONE) {
  4742. + return reconstituter.get_error();
  4743. + }
  4744. +
  4745. + *class_byte_count = (jint)reconstituter.class_file_size();
  4746. + *class_bytes = (unsigned char*)reconstituter.class_file_bytes();
  4747. +
  4748. + } else {
  4749. +
  4750. + // it is cached, get it from the cache
  4751. + *class_byte_count = the_class->get_cached_class_file_len();
  4752. + *class_bytes = the_class->get_cached_class_file_bytes();
  4753. + }
  4754. +
  4755. + } else {
  4756. +
  4757. + // Redefine with bytecodes at index j
  4758. + *class_bytes = _class_defs[j].class_bytes;
  4759. + *class_byte_count = _class_defs[j].class_byte_count;
  4760. + }
  4761. +
  4762. + return JVMTI_ERROR_NONE;
  4763. +}
  4764. +
  4765. +// Prologue of the VM operation, called on the Java thread in parallel to normal program execution
  4766. +bool VM_RedefineClasses::doit_prologue() {
  4767. +
  4768. + _revision_number++;
  4769. + RC_TRACE(0x00000001, ("Redefinition with revision number %d started!", _revision_number));
  4770. +
  4771. + assert(Thread::current()->is_Java_thread(), "must be Java thread");
  4772. + RC_TIMER_START(_timer_prologue);
  4773. +
  4774. + if (!check_arguments()) {
  4775. + RC_TIMER_STOP(_timer_prologue);
  4776. + return false;
  4777. + }
  4778. // We first load new class versions in the prologue, because somewhere down the
  4779. // call chain it is required that the current thread is a Java thread.
  4780. - _res = load_new_class_versions(Thread::current());
  4781. - if (_res != JVMTI_ERROR_NONE) {
  4782. - // Free os::malloc allocated memory in load_new_class_version.
  4783. - os::free(_scratch_classes);
  4784. - RC_TIMER_STOP(_timer_vm_op_prologue);
  4785. + _new_classes = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<instanceKlassHandle>(5, true);
  4786. + _result = load_new_class_versions(Thread::current());
  4787. +
  4788. + RC_TRACE(0x00000001, ("Loaded new class versions!"));
  4789. + if (_result != JVMTI_ERROR_NONE) {
  4790. + RC_TRACE(0x00000001, ("error occured: %d!", _result));
  4791. + delete _new_classes;
  4792. + _new_classes = NULL;
  4793. + RC_TIMER_STOP(_timer_prologue);
  4794. return false;
  4795. }
  4796. - RC_TIMER_STOP(_timer_vm_op_prologue);
  4797. + RC_TRACE(0x00000001, ("nearly finished"));
  4798. + VM_GC_Operation::doit_prologue();
  4799. + RC_TIMER_STOP(_timer_prologue);
  4800. + RC_TRACE(0x00000001, ("doit_prologue finished!"));
  4801. return true;
  4802. }
  4803. -void VM_RedefineClasses::doit() {
  4804. - Thread *thread = Thread::current();
  4805. +// Checks basic properties of the arguments of the redefinition command.
  4806. +bool VM_RedefineClasses::check_arguments() {
  4807. - if (UseSharedSpaces) {
  4808. - // Sharing is enabled so we remap the shared readonly space to
  4809. - // shared readwrite, private just in case we need to redefine
  4810. - // a shared class. We do the remap during the doit() phase of
  4811. - // the safepoint to be safer.
  4812. - if (!CompactingPermGenGen::remap_shared_readonly_as_readwrite()) {
  4813. - RC_TRACE_WITH_THREAD(0x00000001, thread,
  4814. - ("failed to remap shared readonly space to readwrite, private"));
  4815. - _res = JVMTI_ERROR_INTERNAL;
  4816. - return;
  4817. - }
  4818. - }
  4819. -
  4820. + if (_class_count == 0) RC_ABORT(JVMTI_ERROR_NONE);
  4821. + if (_class_defs == NULL) RC_ABORT(JVMTI_ERROR_NULL_POINTER);
  4822. for (int i = 0; i < _class_count; i++) {
  4823. - redefine_single_class(_class_defs[i].klass, _scratch_classes[i], thread);
  4824. + if (_class_defs[i].klass == NULL) RC_ABORT(JVMTI_ERROR_INVALID_CLASS);
  4825. + if (_class_defs[i].class_byte_count == 0) RC_ABORT(JVMTI_ERROR_INVALID_CLASS_FORMAT);
  4826. + if (_class_defs[i].class_bytes == NULL) RC_ABORT(JVMTI_ERROR_NULL_POINTER);
  4827. }
  4828. - // Disable any dependent concurrent compilations
  4829. - SystemDictionary::notice_modification();
  4830. - // Set flag indicating that some invariants are no longer true.
  4831. - // See jvmtiExport.hpp for detailed explanation.
  4832. - JvmtiExport::set_has_redefined_a_class();
  4833. -
  4834. -// check_class() is optionally called for product bits, but is
  4835. -// always called for non-product bits.
  4836. -#ifdef PRODUCT
  4837. - if (RC_TRACE_ENABLED(0x00004000)) {
  4838. -#endif
  4839. - RC_TRACE_WITH_THREAD(0x00004000, thread, ("calling check_class"));
  4840. - SystemDictionary::classes_do(check_class, thread);
  4841. -#ifdef PRODUCT
  4842. - }
  4843. -#endif
  4844. -}
  4845. -
  4846. -void VM_RedefineClasses::doit_epilogue() {
  4847. - // Free os::malloc allocated memory.
  4848. - // The memory allocated in redefine will be free'ed in next VM operation.
  4849. - os::free(_scratch_classes);
  4850. -
  4851. - if (RC_TRACE_ENABLED(0x00000004)) {
  4852. - // Used to have separate timers for "doit" and "all", but the timer
  4853. - // overhead skewed the measurements.
  4854. - jlong doit_time = _timer_rsc_phase1.milliseconds() +
  4855. - _timer_rsc_phase2.milliseconds();
  4856. - jlong all_time = _timer_vm_op_prologue.milliseconds() + doit_time;
  4857. -
  4858. - RC_TRACE(0x00000004, ("vm_op: all=" UINT64_FORMAT
  4859. - " prologue=" UINT64_FORMAT " doit=" UINT64_FORMAT, all_time,
  4860. - _timer_vm_op_prologue.milliseconds(), doit_time));
  4861. - RC_TRACE(0x00000004,
  4862. - ("redefine_single_class: phase1=" UINT64_FORMAT " phase2=" UINT64_FORMAT,
  4863. - _timer_rsc_phase1.milliseconds(), _timer_rsc_phase2.milliseconds()));
  4864. - }
  4865. -}
  4866. -
  4867. -bool VM_RedefineClasses::is_modifiable_class(oop klass_mirror) {
  4868. - // classes for primitives cannot be redefined
  4869. - if (java_lang_Class::is_primitive(klass_mirror)) {
  4870. - return false;
  4871. - }
  4872. - klassOop the_class_oop = java_lang_Class::as_klassOop(klass_mirror);
  4873. - // classes for arrays cannot be redefined
  4874. - if (the_class_oop == NULL || !Klass::cast(the_class_oop)->oop_is_instance()) {
  4875. - return false;
  4876. - }
  4877. return true;
  4878. }
  4879. -// Append the current entry at scratch_i in scratch_cp to *merge_cp_p
  4880. -// where the end of *merge_cp_p is specified by *merge_cp_length_p. For
  4881. -// direct CP entries, there is just the current entry to append. For
  4882. -// indirect and double-indirect CP entries, there are zero or more
  4883. -// referenced CP entries along with the current entry to append.
  4884. -// Indirect and double-indirect CP entries are handled by recursive
  4885. -// calls to append_entry() as needed. The referenced CP entries are
  4886. -// always appended to *merge_cp_p before the referee CP entry. These
  4887. -// referenced CP entries may already exist in *merge_cp_p in which case
  4888. -// there is nothing extra to append and only the current entry is
  4889. -// appended.
  4890. -void VM_RedefineClasses::append_entry(constantPoolHandle scratch_cp,
  4891. - int scratch_i, constantPoolHandle *merge_cp_p, int *merge_cp_length_p,
  4892. - TRAPS) {
  4893. +jvmtiError VM_RedefineClasses::check_exception() const {
  4894. + Thread* THREAD = Thread::current();
  4895. + if (HAS_PENDING_EXCEPTION) {
  4896. - // append is different depending on entry tag type
  4897. - switch (scratch_cp->tag_at(scratch_i).value()) {
  4898. + Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  4899. + RC_TRACE(0x00000001, ("parse_stream exception: '%s'",
  4900. + ex_name->as_C_string()));
  4901. + if (TraceRedefineClasses >= 1) {
  4902. + java_lang_Throwable::print(PENDING_EXCEPTION, tty);
  4903. + tty->print_cr("");
  4904. + }
  4905. + CLEAR_PENDING_EXCEPTION;
  4906. - // The old verifier is implemented outside the VM. It loads classes,
  4907. - // but does not resolve constant pool entries directly so we never
  4908. - // see Class entries here with the old verifier. Similarly the old
  4909. - // verifier does not like Class entries in the input constant pool.
  4910. - // The split-verifier is implemented in the VM so it can optionally
  4911. - // and directly resolve constant pool entries to load classes. The
  4912. - // split-verifier can accept either Class entries or UnresolvedClass
  4913. - // entries in the input constant pool. We revert the appended copy
  4914. - // back to UnresolvedClass so that either verifier will be happy
  4915. - // with the constant pool entry.
  4916. - case JVM_CONSTANT_Class:
  4917. - {
  4918. - // revert the copy to JVM_CONSTANT_UnresolvedClass
  4919. - (*merge_cp_p)->unresolved_klass_at_put(*merge_cp_length_p,
  4920. - scratch_cp->klass_name_at(scratch_i));
  4921. -
  4922. - if (scratch_i != *merge_cp_length_p) {
  4923. - // The new entry in *merge_cp_p is at a different index than
  4924. - // the new entry in scratch_cp so we need to map the index values.
  4925. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  4926. - }
  4927. - (*merge_cp_length_p)++;
  4928. - } break;
  4929. -
  4930. - // these are direct CP entries so they can be directly appended,
  4931. - // but double and long take two constant pool entries
  4932. - case JVM_CONSTANT_Double: // fall through
  4933. - case JVM_CONSTANT_Long:
  4934. - {
  4935. - constantPoolOopDesc::copy_entry_to(scratch_cp, scratch_i, *merge_cp_p, *merge_cp_length_p,
  4936. - THREAD);
  4937. -
  4938. - if (scratch_i != *merge_cp_length_p) {
  4939. - // The new entry in *merge_cp_p is at a different index than
  4940. - // the new entry in scratch_cp so we need to map the index values.
  4941. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  4942. - }
  4943. - (*merge_cp_length_p) += 2;
  4944. - } break;
  4945. -
  4946. - // these are direct CP entries so they can be directly appended
  4947. - case JVM_CONSTANT_Float: // fall through
  4948. - case JVM_CONSTANT_Integer: // fall through
  4949. - case JVM_CONSTANT_Utf8: // fall through
  4950. -
  4951. - // This was an indirect CP entry, but it has been changed into
  4952. - // an interned string so this entry can be directly appended.
  4953. - case JVM_CONSTANT_String: // fall through
  4954. -
  4955. - // These were indirect CP entries, but they have been changed into
  4956. - // Symbol*s so these entries can be directly appended.
  4957. - case JVM_CONSTANT_UnresolvedClass: // fall through
  4958. - case JVM_CONSTANT_UnresolvedString:
  4959. - {
  4960. - constantPoolOopDesc::copy_entry_to(scratch_cp, scratch_i, *merge_cp_p, *merge_cp_length_p,
  4961. - THREAD);
  4962. -
  4963. - if (scratch_i != *merge_cp_length_p) {
  4964. - // The new entry in *merge_cp_p is at a different index than
  4965. - // the new entry in scratch_cp so we need to map the index values.
  4966. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  4967. - }
  4968. - (*merge_cp_length_p)++;
  4969. - } break;
  4970. -
  4971. - // this is an indirect CP entry so it needs special handling
  4972. - case JVM_CONSTANT_NameAndType:
  4973. - {
  4974. - int name_ref_i = scratch_cp->name_ref_index_at(scratch_i);
  4975. - int new_name_ref_i = find_or_append_indirect_entry(scratch_cp, name_ref_i, merge_cp_p,
  4976. - merge_cp_length_p, THREAD);
  4977. -
  4978. - int signature_ref_i = scratch_cp->signature_ref_index_at(scratch_i);
  4979. - int new_signature_ref_i = find_or_append_indirect_entry(scratch_cp, signature_ref_i,
  4980. - merge_cp_p, merge_cp_length_p,
  4981. - THREAD);
  4982. -
  4983. - // If the referenced entries already exist in *merge_cp_p, then
  4984. - // both new_name_ref_i and new_signature_ref_i will both be 0.
  4985. - // In that case, all we are appending is the current entry.
  4986. - if (new_name_ref_i != name_ref_i) {
  4987. - RC_TRACE(0x00080000,
  4988. - ("NameAndType entry@%d name_ref_index change: %d to %d",
  4989. - *merge_cp_length_p, name_ref_i, new_name_ref_i));
  4990. - }
  4991. - if (new_signature_ref_i != signature_ref_i) {
  4992. - RC_TRACE(0x00080000,
  4993. - ("NameAndType entry@%d signature_ref_index change: %d to %d",
  4994. - *merge_cp_length_p, signature_ref_i, new_signature_ref_i));
  4995. - }
  4996. -
  4997. - (*merge_cp_p)->name_and_type_at_put(*merge_cp_length_p,
  4998. - new_name_ref_i, new_signature_ref_i);
  4999. - if (scratch_i != *merge_cp_length_p) {
  5000. - // The new entry in *merge_cp_p is at a different index than
  5001. - // the new entry in scratch_cp so we need to map the index values.
  5002. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5003. - }
  5004. - (*merge_cp_length_p)++;
  5005. - } break;
  5006. -
  5007. - // this is a double-indirect CP entry so it needs special handling
  5008. - case JVM_CONSTANT_Fieldref: // fall through
  5009. - case JVM_CONSTANT_InterfaceMethodref: // fall through
  5010. - case JVM_CONSTANT_Methodref:
  5011. - {
  5012. - int klass_ref_i = scratch_cp->uncached_klass_ref_index_at(scratch_i);
  5013. - int new_klass_ref_i = find_or_append_indirect_entry(scratch_cp, klass_ref_i,
  5014. - merge_cp_p, merge_cp_length_p, THREAD);
  5015. - int name_and_type_ref_i = scratch_cp->uncached_name_and_type_ref_index_at(scratch_i);
  5016. - int new_name_and_type_ref_i = find_or_append_indirect_entry(scratch_cp, name_and_type_ref_i,
  5017. - merge_cp_p, merge_cp_length_p, THREAD);
  5018. -
  5019. - const char *entry_name;
  5020. - switch (scratch_cp->tag_at(scratch_i).value()) {
  5021. - case JVM_CONSTANT_Fieldref:
  5022. - entry_name = "Fieldref";
  5023. - (*merge_cp_p)->field_at_put(*merge_cp_length_p, new_klass_ref_i,
  5024. - new_name_and_type_ref_i);
  5025. - break;
  5026. - case JVM_CONSTANT_InterfaceMethodref:
  5027. - entry_name = "IFMethodref";
  5028. - (*merge_cp_p)->interface_method_at_put(*merge_cp_length_p,
  5029. - new_klass_ref_i, new_name_and_type_ref_i);
  5030. - break;
  5031. - case JVM_CONSTANT_Methodref:
  5032. - entry_name = "Methodref";
  5033. - (*merge_cp_p)->method_at_put(*merge_cp_length_p, new_klass_ref_i,
  5034. - new_name_and_type_ref_i);
  5035. - break;
  5036. - default:
  5037. - guarantee(false, "bad switch");
  5038. - break;
  5039. - }
  5040. -
  5041. - if (klass_ref_i != new_klass_ref_i) {
  5042. - RC_TRACE(0x00080000, ("%s entry@%d class_index changed: %d to %d",
  5043. - entry_name, *merge_cp_length_p, klass_ref_i, new_klass_ref_i));
  5044. - }
  5045. - if (name_and_type_ref_i != new_name_and_type_ref_i) {
  5046. - RC_TRACE(0x00080000,
  5047. - ("%s entry@%d name_and_type_index changed: %d to %d",
  5048. - entry_name, *merge_cp_length_p, name_and_type_ref_i,
  5049. - new_name_and_type_ref_i));
  5050. - }
  5051. -
  5052. - if (scratch_i != *merge_cp_length_p) {
  5053. - // The new entry in *merge_cp_p is at a different index than
  5054. - // the new entry in scratch_cp so we need to map the index values.
  5055. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5056. - }
  5057. - (*merge_cp_length_p)++;
  5058. - } break;
  5059. -
  5060. - // this is an indirect CP entry so it needs special handling
  5061. - case JVM_CONSTANT_MethodType:
  5062. - {
  5063. - int ref_i = scratch_cp->method_type_index_at(scratch_i);
  5064. - int new_ref_i = find_or_append_indirect_entry(scratch_cp, ref_i, merge_cp_p,
  5065. - merge_cp_length_p, THREAD);
  5066. - if (new_ref_i != ref_i) {
  5067. - RC_TRACE(0x00080000,
  5068. - ("MethodType entry@%d ref_index change: %d to %d",
  5069. - *merge_cp_length_p, ref_i, new_ref_i));
  5070. - }
  5071. - (*merge_cp_p)->method_type_index_at_put(*merge_cp_length_p, new_ref_i);
  5072. - if (scratch_i != *merge_cp_length_p) {
  5073. - // The new entry in *merge_cp_p is at a different index than
  5074. - // the new entry in scratch_cp so we need to map the index values.
  5075. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5076. - }
  5077. - (*merge_cp_length_p)++;
  5078. - } break;
  5079. -
  5080. - // this is an indirect CP entry so it needs special handling
  5081. - case JVM_CONSTANT_MethodHandle:
  5082. - {
  5083. - int ref_kind = scratch_cp->method_handle_ref_kind_at(scratch_i);
  5084. - int ref_i = scratch_cp->method_handle_index_at(scratch_i);
  5085. - int new_ref_i = find_or_append_indirect_entry(scratch_cp, ref_i, merge_cp_p,
  5086. - merge_cp_length_p, THREAD);
  5087. - if (new_ref_i != ref_i) {
  5088. - RC_TRACE(0x00080000,
  5089. - ("MethodHandle entry@%d ref_index change: %d to %d",
  5090. - *merge_cp_length_p, ref_i, new_ref_i));
  5091. - }
  5092. - (*merge_cp_p)->method_handle_index_at_put(*merge_cp_length_p, ref_kind, new_ref_i);
  5093. - if (scratch_i != *merge_cp_length_p) {
  5094. - // The new entry in *merge_cp_p is at a different index than
  5095. - // the new entry in scratch_cp so we need to map the index values.
  5096. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5097. - }
  5098. - (*merge_cp_length_p)++;
  5099. - } break;
  5100. -
  5101. - // this is an indirect CP entry so it needs special handling
  5102. - case JVM_CONSTANT_InvokeDynamic:
  5103. - {
  5104. - // Index of the bootstrap specifier in the operands array
  5105. - int old_bs_i = scratch_cp->invoke_dynamic_bootstrap_specifier_index(scratch_i);
  5106. - int new_bs_i = find_or_append_operand(scratch_cp, old_bs_i, merge_cp_p,
  5107. - merge_cp_length_p, THREAD);
  5108. - // The bootstrap method NameAndType_info index
  5109. - int old_ref_i = scratch_cp->invoke_dynamic_name_and_type_ref_index_at(scratch_i);
  5110. - int new_ref_i = find_or_append_indirect_entry(scratch_cp, old_ref_i, merge_cp_p,
  5111. - merge_cp_length_p, THREAD);
  5112. - if (new_bs_i != old_bs_i) {
  5113. - RC_TRACE(0x00080000,
  5114. - ("InvokeDynamic entry@%d bootstrap_method_attr_index change: %d to %d",
  5115. - *merge_cp_length_p, old_bs_i, new_bs_i));
  5116. - }
  5117. - if (new_ref_i != old_ref_i) {
  5118. - RC_TRACE(0x00080000,
  5119. - ("InvokeDynamic entry@%d name_and_type_index change: %d to %d",
  5120. - *merge_cp_length_p, old_ref_i, new_ref_i));
  5121. - }
  5122. -
  5123. - (*merge_cp_p)->invoke_dynamic_at_put(*merge_cp_length_p, new_bs_i, new_ref_i);
  5124. - if (scratch_i != *merge_cp_length_p) {
  5125. - // The new entry in *merge_cp_p is at a different index than
  5126. - // the new entry in scratch_cp so we need to map the index values.
  5127. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5128. - }
  5129. - (*merge_cp_length_p)++;
  5130. - } break;
  5131. -
  5132. - // At this stage, Class or UnresolvedClass could be here, but not
  5133. - // ClassIndex
  5134. - case JVM_CONSTANT_ClassIndex: // fall through
  5135. -
  5136. - // Invalid is used as the tag for the second constant pool entry
  5137. - // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should
  5138. - // not be seen by itself.
  5139. - case JVM_CONSTANT_Invalid: // fall through
  5140. -
  5141. - // At this stage, String or UnresolvedString could be here, but not
  5142. - // StringIndex
  5143. - case JVM_CONSTANT_StringIndex: // fall through
  5144. -
  5145. - // At this stage JVM_CONSTANT_UnresolvedClassInError should not be
  5146. - // here
  5147. - case JVM_CONSTANT_UnresolvedClassInError: // fall through
  5148. -
  5149. - default:
  5150. - {
  5151. - // leave a breadcrumb
  5152. - jbyte bad_value = scratch_cp->tag_at(scratch_i).value();
  5153. - ShouldNotReachHere();
  5154. - } break;
  5155. - } // end switch tag value
  5156. -} // end append_entry()
  5157. -
  5158. -
  5159. -int VM_RedefineClasses::find_or_append_indirect_entry(constantPoolHandle scratch_cp,
  5160. - int ref_i, constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS) {
  5161. -
  5162. - int new_ref_i = ref_i;
  5163. - bool match = (ref_i < *merge_cp_length_p) &&
  5164. - scratch_cp->compare_entry_to(ref_i, *merge_cp_p, ref_i, THREAD);
  5165. -
  5166. - if (!match) {
  5167. - // forward reference in *merge_cp_p or not a direct match
  5168. - int found_i = scratch_cp->find_matching_entry(ref_i, *merge_cp_p, THREAD);
  5169. - if (found_i != 0) {
  5170. - guarantee(found_i != ref_i, "compare_entry_to() and find_matching_entry() do not agree");
  5171. - // Found a matching entry somewhere else in *merge_cp_p so just need a mapping entry.
  5172. - new_ref_i = found_i;
  5173. - map_index(scratch_cp, ref_i, found_i);
  5174. + if (ex_name == vmSymbols::java_lang_UnsupportedClassVersionError()) {
  5175. + return JVMTI_ERROR_UNSUPPORTED_VERSION;
  5176. + } else if (ex_name == vmSymbols::java_lang_ClassFormatError()) {
  5177. + return JVMTI_ERROR_INVALID_CLASS_FORMAT;
  5178. + } else if (ex_name == vmSymbols::java_lang_ClassCircularityError()) {
  5179. + return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  5180. + } else if (ex_name == vmSymbols::java_lang_NoClassDefFoundError()) {
  5181. + // The message will be "XXX (wrong name: YYY)"
  5182. + return JVMTI_ERROR_NAMES_DONT_MATCH;
  5183. + } else if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  5184. + return JVMTI_ERROR_OUT_OF_MEMORY;
  5185. } else {
  5186. - // no match found so we have to append this entry to *merge_cp_p
  5187. - append_entry(scratch_cp, ref_i, merge_cp_p, merge_cp_length_p, THREAD);
  5188. - // The above call to append_entry() can only append one entry
  5189. - // so the post call query of *merge_cp_length_p is only for
  5190. - // the sake of consistency.
  5191. - new_ref_i = *merge_cp_length_p - 1;
  5192. + // Just in case more exceptions can be thrown..
  5193. + return JVMTI_ERROR_FAILS_VERIFICATION;
  5194. }
  5195. }
  5196. - return new_ref_i;
  5197. -} // end find_or_append_indirect_entry()
  5198. -
  5199. -
  5200. -// Append a bootstrap specifier into the merge_cp operands that is semantically equal
  5201. -// to the scratch_cp operands bootstrap specifier passed by the old_bs_i index.
  5202. -// Recursively append new merge_cp entries referenced by the new bootstrap specifier.
  5203. -void VM_RedefineClasses::append_operand(constantPoolHandle scratch_cp, int old_bs_i,
  5204. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS) {
  5205. -
  5206. - int old_ref_i = scratch_cp->operand_bootstrap_method_ref_index_at(old_bs_i);
  5207. - int new_ref_i = find_or_append_indirect_entry(scratch_cp, old_ref_i, merge_cp_p,
  5208. - merge_cp_length_p, THREAD);
  5209. - if (new_ref_i != old_ref_i) {
  5210. - RC_TRACE(0x00080000,
  5211. - ("operands entry@%d bootstrap method ref_index change: %d to %d",
  5212. - _operands_cur_length, old_ref_i, new_ref_i));
  5213. - }
  5214. -
  5215. - typeArrayOop merge_ops = (*merge_cp_p)->operands();
  5216. - int new_bs_i = _operands_cur_length;
  5217. - // We have _operands_cur_length == 0 when the merge_cp operands is empty yet.
  5218. - // However, the operand_offset_at(0) was set in the extend_operands() call.
  5219. - int new_base = (new_bs_i == 0) ? (*merge_cp_p)->operand_offset_at(0)
  5220. - : (*merge_cp_p)->operand_next_offset_at(new_bs_i - 1);
  5221. - int argc = scratch_cp->operand_argument_count_at(old_bs_i);
  5222. -
  5223. - constantPoolOopDesc::operand_offset_at_put(merge_ops, _operands_cur_length, new_base);
  5224. - merge_ops->short_at_put(new_base++, new_ref_i);
  5225. - merge_ops->short_at_put(new_base++, argc);
  5226. -
  5227. - for (int i = 0; i < argc; i++) {
  5228. - int old_arg_ref_i = scratch_cp->operand_argument_index_at(old_bs_i, i);
  5229. - int new_arg_ref_i = find_or_append_indirect_entry(scratch_cp, old_arg_ref_i, merge_cp_p,
  5230. - merge_cp_length_p, THREAD);
  5231. - merge_ops->short_at_put(new_base++, new_arg_ref_i);
  5232. - if (new_arg_ref_i != old_arg_ref_i) {
  5233. - RC_TRACE(0x00080000,
  5234. - ("operands entry@%d bootstrap method argument ref_index change: %d to %d",
  5235. - _operands_cur_length, old_arg_ref_i, new_arg_ref_i));
  5236. - }
  5237. - }
  5238. - if (old_bs_i != _operands_cur_length) {
  5239. - // The bootstrap specifier in *merge_cp_p is at a different index than
  5240. - // that in scratch_cp so we need to map the index values.
  5241. - map_operand_index(old_bs_i, new_bs_i);
  5242. - }
  5243. - _operands_cur_length++;
  5244. -} // end append_operand()
  5245. -
  5246. -
  5247. -int VM_RedefineClasses::find_or_append_operand(constantPoolHandle scratch_cp,
  5248. - int old_bs_i, constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS) {
  5249. -
  5250. - int new_bs_i = old_bs_i; // bootstrap specifier index
  5251. - bool match = (old_bs_i < _operands_cur_length) &&
  5252. - scratch_cp->compare_operand_to(old_bs_i, *merge_cp_p, old_bs_i, THREAD);
  5253. -
  5254. - if (!match) {
  5255. - // forward reference in *merge_cp_p or not a direct match
  5256. - int found_i = scratch_cp->find_matching_operand(old_bs_i, *merge_cp_p,
  5257. - _operands_cur_length, THREAD);
  5258. - if (found_i != -1) {
  5259. - guarantee(found_i != old_bs_i, "compare_operand_to() and find_matching_operand() disagree");
  5260. - // found a matching operand somewhere else in *merge_cp_p so just need a mapping
  5261. - new_bs_i = found_i;
  5262. - map_operand_index(old_bs_i, found_i);
  5263. - } else {
  5264. - // no match found so we have to append this bootstrap specifier to *merge_cp_p
  5265. - append_operand(scratch_cp, old_bs_i, merge_cp_p, merge_cp_length_p, THREAD);
  5266. - new_bs_i = _operands_cur_length - 1;
  5267. - }
  5268. - }
  5269. - return new_bs_i;
  5270. -} // end find_or_append_operand()
  5271. -
  5272. -
  5273. -void VM_RedefineClasses::finalize_operands_merge(constantPoolHandle merge_cp, TRAPS) {
  5274. - if (merge_cp->operands() == NULL) {
  5275. - return;
  5276. - }
  5277. - // Shrink the merge_cp operands
  5278. - merge_cp->shrink_operands(_operands_cur_length, CHECK);
  5279. -
  5280. - if (RC_TRACE_ENABLED(0x00040000)) {
  5281. - // don't want to loop unless we are tracing
  5282. - int count = 0;
  5283. - for (int i = 1; i < _operands_index_map_p->length(); i++) {
  5284. - int value = _operands_index_map_p->at(i);
  5285. - if (value != -1) {
  5286. - RC_TRACE_WITH_THREAD(0x00040000, THREAD,
  5287. - ("operands_index_map[%d]: old=%d new=%d", count, i, value));
  5288. - count++;
  5289. - }
  5290. - }
  5291. - }
  5292. - // Clean-up
  5293. - _operands_index_map_p = NULL;
  5294. - _operands_cur_length = 0;
  5295. - _operands_index_map_count = 0;
  5296. -} // end finalize_operands_merge()
  5297. -
  5298. -
  5299. -void VM_RedefineClasses::swap_all_method_annotations(int i, int j, instanceKlassHandle scratch_class) {
  5300. - typeArrayOop save;
  5301. -
  5302. - save = scratch_class->get_method_annotations_of(i);
  5303. - scratch_class->set_method_annotations_of(i, scratch_class->get_method_annotations_of(j));
  5304. - scratch_class->set_method_annotations_of(j, save);
  5305. -
  5306. - save = scratch_class->get_method_parameter_annotations_of(i);
  5307. - scratch_class->set_method_parameter_annotations_of(i, scratch_class->get_method_parameter_annotations_of(j));
  5308. - scratch_class->set_method_parameter_annotations_of(j, save);
  5309. -
  5310. - save = scratch_class->get_method_default_annotations_of(i);
  5311. - scratch_class->set_method_default_annotations_of(i, scratch_class->get_method_default_annotations_of(j));
  5312. - scratch_class->set_method_default_annotations_of(j, save);
  5313. + return JVMTI_ERROR_NONE;
  5314. }
  5315. +// Loads all new class versions and stores the instanceKlass handles in an array.
  5316. +jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) {
  5317. -jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions(
  5318. - instanceKlassHandle the_class,
  5319. - instanceKlassHandle scratch_class) {
  5320. + ResourceMark rm(THREAD);
  5321. +
  5322. + RC_TRACE(0x00000001, ("==================================================================="));
  5323. + RC_TRACE(0x00000001, ("load new class versions (%d)",
  5324. + _class_count));
  5325. +
  5326. + // Retrieve an array of all classes that need to be redefined
  5327. + GrowableArray<instanceKlassHandle> all_affected_klasses;
  5328. + jvmtiError err = find_sorted_affected_classes(&all_affected_klasses);
  5329. + if (err != JVMTI_ERROR_NONE) {
  5330. + RC_TRACE(0x00000001, ("Error finding sorted affected classes: %d",
  5331. + (int)err));
  5332. + return err;
  5333. + }
  5334. +
  5335. +
  5336. + JvmtiThreadState *state = JvmtiThreadState::state_for(JavaThread::current());
  5337. +
  5338. + _max_redefinition_flags = Klass::NoRedefinition;
  5339. + jvmtiError result = JVMTI_ERROR_NONE;
  5340. +
  5341. + for (int i=0; i<all_affected_klasses.length(); i++) {
  5342. + RC_TRACE(0x00000002, ("Processing affected class %d of %d",
  5343. + i+1, all_affected_klasses.length()));
  5344. +
  5345. + instanceKlassHandle the_class = all_affected_klasses.at(i);
  5346. + RC_TRACE(0x00000002, ("name=%s",
  5347. + the_class->name()->as_C_string()));
  5348. +
  5349. + the_class->link_class(THREAD);
  5350. + result = check_exception();
  5351. + if (result != JVMTI_ERROR_NONE) break;
  5352. +
  5353. + // Find new class bytes
  5354. + const unsigned char* class_bytes;
  5355. + jint class_byte_count;
  5356. + jvmtiError error;
  5357. + jboolean not_changed;
  5358. + if ((error = find_class_bytes(the_class, &class_bytes, &class_byte_count, &not_changed)) != JVMTI_ERROR_NONE) {
  5359. + RC_TRACE(0x00000001, ("Error finding class bytes: %d",
  5360. + (int)error));
  5361. + result = error;
  5362. + break;
  5363. + }
  5364. + assert(class_bytes != NULL && class_byte_count != 0, "Class bytes defined at this point!");
  5365. +
  5366. +
  5367. + // Set redefined class handle in JvmtiThreadState class.
  5368. + // This redefined class is sent to agent event handler for class file
  5369. + // load hook event.
  5370. + state->set_class_being_redefined(&the_class, _class_load_kind);
  5371. +
  5372. + RC_TRACE(0x00000002, ("Before resolving from stream"));
  5373. +
  5374. + RC_TIMER_STOP(_timer_prologue);
  5375. + RC_TIMER_START(_timer_class_loading);
  5376. +
  5377. +
  5378. + // Parse the stream.
  5379. + Handle the_class_loader(THREAD, the_class->class_loader());
  5380. + Handle protection_domain(THREAD, the_class->protection_domain());
  5381. + Symbol* the_class_sym = the_class->name();
  5382. + ClassFileStream st((u1*) class_bytes, class_byte_count, (char *)"__VM_RedefineClasses__");
  5383. + instanceKlassHandle new_class(THREAD, SystemDictionary::resolve_from_stream(the_class_sym,
  5384. + the_class_loader,
  5385. + protection_domain,
  5386. + &st,
  5387. + true,
  5388. + the_class,
  5389. + THREAD));
  5390. +
  5391. + not_changed = false;
  5392. +
  5393. + RC_TIMER_STOP(_timer_class_loading);
  5394. + RC_TIMER_START(_timer_prologue);
  5395. +
  5396. + RC_TRACE(0x00000002, ("After resolving class from stream!"));
  5397. + // Clear class_being_redefined just to be sure.
  5398. + state->clear_class_being_redefined();
  5399. +
  5400. + result = check_exception();
  5401. + if (result != JVMTI_ERROR_NONE) break;
  5402. +
  5403. +#ifdef ASSERT
  5404. +
  5405. + assert(new_class() != NULL, "Class could not be loaded!");
  5406. + assert(new_class() != the_class(), "must be different");
  5407. + assert(new_class->new_version() == NULL && new_class->old_version() != NULL, "");
  5408. +
  5409. +
  5410. + objArrayOop k_interfaces = new_class->local_interfaces();
  5411. + for (int j=0; j<k_interfaces->length(); j++) {
  5412. + assert(((klassOop)k_interfaces->obj_at(j))->klass_part()->is_newest_version(), "just checking");
  5413. + }
  5414. +
  5415. + if (!THREAD->is_Compiler_thread()) {
  5416. +
  5417. + RC_TRACE(0x00000002, ("name=%s loader="INTPTR_FORMAT" protection_domain="INTPTR_FORMAT" ",
  5418. + the_class->name()->as_C_string(),
  5419. + (address)(the_class->class_loader()),
  5420. + (address)(the_class->protection_domain())));
  5421. + // If we are on the compiler thread, we must not try to resolve a class.
  5422. + klassOop systemLookup = SystemDictionary::resolve_or_null(the_class->name(), the_class->class_loader(), the_class->protection_domain(), THREAD);
  5423. +
  5424. + if (systemLookup != NULL) {
  5425. + assert(systemLookup == new_class->old_version(), "Old class must be in system dictionary!");
  5426. +
  5427. +
  5428. + Klass *subklass = new_class()->klass_part()->subklass();
  5429. + while (subklass != NULL) {
  5430. + assert(subklass->new_version() == NULL, "Most recent version of class!");
  5431. + subklass = subklass->next_sibling();
  5432. + }
  5433. + } else {
  5434. + // This can happen for reflection generated classes.. ?
  5435. + CLEAR_PENDING_EXCEPTION;
  5436. + }
  5437. + }
  5438. +
  5439. +#endif
  5440. +
  5441. + if (RC_TRACE_ENABLED(0x00000001)) {
  5442. + if (new_class->layout_helper() != the_class->layout_helper()) {
  5443. + RC_TRACE(0x00000001, ("Instance size change for class %s: new=%d old=%d",
  5444. + new_class->name()->as_C_string(),
  5445. + new_class->layout_helper(),
  5446. + the_class->layout_helper()));
  5447. + }
  5448. + }
  5449. +
  5450. + // Set the new version of the class
  5451. + new_class->set_revision_number(_revision_number);
  5452. + new_class->set_redefinition_index(i);
  5453. + the_class->set_new_version(new_class());
  5454. + _new_classes->append(new_class);
  5455. +
  5456. + assert(new_class->new_version() == NULL, "");
  5457. +
  5458. + int redefinition_flags = Klass::NoRedefinition;
  5459. +
  5460. + if (not_changed) {
  5461. + redefinition_flags = Klass::NoRedefinition;
  5462. + } else if (AllowAdvancedClassRedefinition) {
  5463. + redefinition_flags = calculate_redefinition_flags(new_class);
  5464. + } else {
  5465. + jvmtiError allowed = check_redefinition_allowed(new_class);
  5466. + if (allowed != JVMTI_ERROR_NONE) {
  5467. + RC_TRACE(0x00000001, ("Error redefinition not allowed!"));
  5468. + result = allowed;
  5469. + break;
  5470. + }
  5471. + redefinition_flags = Klass::ModifyClass;
  5472. + }
  5473. +
  5474. + if (new_class->super() != NULL) {
  5475. + redefinition_flags = redefinition_flags | new_class->super()->klass_part()->redefinition_flags();
  5476. + }
  5477. +
  5478. + for (int j=0; j<new_class->local_interfaces()->length(); j++) {
  5479. + redefinition_flags = redefinition_flags | ((klassOop)new_class->local_interfaces()->obj_at(j))->klass_part()->redefinition_flags();
  5480. + }
  5481. +
  5482. + new_class->set_redefinition_flags(redefinition_flags);
  5483. +
  5484. + _max_redefinition_flags = _max_redefinition_flags | redefinition_flags;
  5485. +
  5486. + if ((redefinition_flags & Klass::ModifyInstances) != 0) {
  5487. + // TODO: Check if watch access flags of static fields are updated correctly.
  5488. + calculate_instance_update_information(_new_classes->at(i)());
  5489. + } else {
  5490. + assert(new_class->layout_helper() >> 1 == new_class->old_version()->klass_part()->layout_helper() >> 1, "must be equal");
  5491. + assert(new_class->fields()->length() == ((instanceKlass*)new_class->old_version()->klass_part())->fields()->length(), "must be equal");
  5492. +
  5493. + fieldDescriptor fd_new;
  5494. + fieldDescriptor fd_old;
  5495. + for (JavaFieldStream fs(new_class); !fs.done(); fs.next()) {
  5496. + fd_new.initialize(new_class(), fs.index());
  5497. + fd_old.initialize(new_class->old_version(), fs.index());
  5498. + transfer_special_access_flags(&fd_old, &fd_new);
  5499. + }
  5500. + }
  5501. +
  5502. + if (RC_TRACE_ENABLED(0x00000008)) {
  5503. + if (new_class->super() != NULL) {
  5504. + RC_TRACE(0x00000008, ("Super class is %s",
  5505. + new_class->super()->klass_part()->name()->as_C_string()));
  5506. + }
  5507. + }
  5508. +
  5509. +#ifdef ASSERT
  5510. + assert(new_class->super() == NULL || new_class->super()->klass_part()->new_version() == NULL, "Super klass must be newest version!");
  5511. +
  5512. + the_class->vtable()->verify(tty);
  5513. + new_class->vtable()->verify(tty);
  5514. +#endif
  5515. +
  5516. + RC_TRACE(0x00000002, ("Verification done!"));
  5517. +
  5518. + if (i == all_affected_klasses.length() - 1) {
  5519. +
  5520. + // This was the last class processed => check if additional classes have been loaded in the meantime
  5521. +
  5522. + RC_TIMER_STOP(_timer_prologue);
  5523. + lock_threads();
  5524. + RC_TIMER_START(_timer_prologue);
  5525. +
  5526. + for (int j=0; j<all_affected_klasses.length(); j++) {
  5527. +
  5528. + klassOop initial_klass = all_affected_klasses.at(j)();
  5529. + Klass *initial_subklass = initial_klass->klass_part()->subklass();
  5530. + Klass *cur_klass = initial_subklass;
  5531. + while(cur_klass != NULL) {
  5532. +
  5533. + if(cur_klass->oop_is_instance() && cur_klass->is_newest_version()) {
  5534. + instanceKlassHandle handle(THREAD, cur_klass->as_klassOop());
  5535. + if (!all_affected_klasses.contains(handle)) {
  5536. +
  5537. + int k = i + 1;
  5538. + for (; k<all_affected_klasses.length(); k++) {
  5539. + if (all_affected_klasses.at(k)->is_subtype_of(cur_klass->as_klassOop())) {
  5540. + break;
  5541. + }
  5542. + }
  5543. + all_affected_klasses.insert_before(k, handle);
  5544. + RC_TRACE(0x00000002, ("Adding newly loaded class to affected classes: %s",
  5545. + cur_klass->name()->as_C_string()));
  5546. + }
  5547. + }
  5548. +
  5549. + cur_klass = cur_klass->next_sibling();
  5550. + }
  5551. + }
  5552. +
  5553. + int new_count = all_affected_klasses.length() - 1 - i;
  5554. + if (new_count != 0) {
  5555. +
  5556. + unlock_threads();
  5557. + RC_TRACE(0x00000001, ("Found new number of affected classes: %d",
  5558. + new_count));
  5559. + }
  5560. + }
  5561. + }
  5562. +
  5563. + if (result != JVMTI_ERROR_NONE) {
  5564. + rollback();
  5565. + return result;
  5566. + }
  5567. +
  5568. + RC_TIMER_STOP(_timer_prologue);
  5569. + RC_TIMER_START(_timer_class_linking);
  5570. + // Link and verify new classes _after_ all classes have been updated in the system dictionary!
  5571. + for (int i=0; i<all_affected_klasses.length(); i++) {
  5572. + instanceKlassHandle the_class = all_affected_klasses.at(i);
  5573. + instanceKlassHandle new_class(the_class->new_version());
  5574. +
  5575. + RC_TRACE(0x00000002, ("Linking class %d/%d %s",
  5576. + i,
  5577. + all_affected_klasses.length(),
  5578. + the_class->name()->as_C_string()));
  5579. + new_class->link_class(THREAD);
  5580. +
  5581. + result = check_exception();
  5582. + if (result != JVMTI_ERROR_NONE) break;
  5583. + }
  5584. + RC_TIMER_STOP(_timer_class_linking);
  5585. + RC_TIMER_START(_timer_prologue);
  5586. +
  5587. + if (result != JVMTI_ERROR_NONE) {
  5588. + rollback();
  5589. + return result;
  5590. + }
  5591. +
  5592. + RC_TRACE(0x00000002, ("All classes loaded!"));
  5593. +
  5594. +#ifdef ASSERT
  5595. + for (int i=0; i<all_affected_klasses.length(); i++) {
  5596. + instanceKlassHandle the_class = all_affected_klasses.at(i);
  5597. + assert(the_class->new_version() != NULL, "Must have been redefined");
  5598. + instanceKlassHandle new_version = instanceKlassHandle(THREAD, the_class->new_version());
  5599. + assert(new_version->new_version() == NULL, "Must be newest version");
  5600. +
  5601. + if (!(new_version->super() == NULL || new_version->super()->klass_part()->new_version() == NULL)) {
  5602. + new_version()->print();
  5603. + new_version->super()->print();
  5604. + }
  5605. + assert(new_version->super() == NULL || new_version->super()->klass_part()->new_version() == NULL, "Super class must be newest version");
  5606. + }
  5607. +
  5608. + SystemDictionary::classes_do(check_class, THREAD);
  5609. +
  5610. +#endif
  5611. +
  5612. + RC_TRACE(0x00000001, ("Finished verification!"));
  5613. + return JVMTI_ERROR_NONE;
  5614. +}
  5615. +
  5616. +void VM_RedefineClasses::lock_threads() {
  5617. +
  5618. + RC_TIMER_START(_timer_wait_for_locks);
  5619. +
  5620. +
  5621. + JavaThread *javaThread = Threads::first();
  5622. + while (javaThread != NULL) {
  5623. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  5624. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  5625. + compilerThread->set_should_bailout(true);
  5626. + }
  5627. + javaThread = javaThread->next();
  5628. + }
  5629. +
  5630. + int cnt = 0;
  5631. + javaThread = Threads::first();
  5632. + while (javaThread != NULL) {
  5633. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  5634. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  5635. + compilerThread->compilation_mutex()->lock();
  5636. + cnt++;
  5637. + }
  5638. + javaThread = javaThread->next();
  5639. + }
  5640. +
  5641. + RC_TRACE(0x00000002, ("Locked %d compiler threads", cnt));
  5642. +
  5643. + cnt = 0;
  5644. + javaThread = Threads::first();
  5645. + while (javaThread != NULL) {
  5646. + if (javaThread != Thread::current()) {
  5647. + javaThread->redefine_classes_mutex()->lock();
  5648. + }
  5649. + javaThread = javaThread->next();
  5650. + }
  5651. +
  5652. +
  5653. + RC_TRACE(0x00000002, ("Locked %d threads", cnt));
  5654. +
  5655. + RC_TIMER_STOP(_timer_wait_for_locks);
  5656. +}
  5657. +
  5658. +void VM_RedefineClasses::unlock_threads() {
  5659. +
  5660. + int cnt = 0;
  5661. + JavaThread *javaThread = Threads::first();
  5662. + Thread *thread = Thread::current();
  5663. + while (javaThread != NULL) {
  5664. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  5665. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  5666. + if (compilerThread->compilation_mutex()->owned_by_self()) {
  5667. + compilerThread->compilation_mutex()->unlock();
  5668. + cnt++;
  5669. + }
  5670. + }
  5671. + javaThread = javaThread->next();
  5672. + }
  5673. +
  5674. + RC_TRACE(0x00000002, ("Unlocked %d compiler threads", cnt));
  5675. +
  5676. + cnt = 0;
  5677. + javaThread = Threads::first();
  5678. + while (javaThread != NULL) {
  5679. + if (javaThread != Thread::current()) {
  5680. + if (javaThread->redefine_classes_mutex()->owned_by_self()) {
  5681. + javaThread->redefine_classes_mutex()->unlock();
  5682. + }
  5683. + }
  5684. + javaThread = javaThread->next();
  5685. + }
  5686. +
  5687. + RC_TRACE(0x00000002, ("Unlocked %d threads", cnt));
  5688. +}
  5689. +
  5690. +jvmtiError VM_RedefineClasses::check_redefinition_allowed(instanceKlassHandle scratch_class) {
  5691. +
  5692. +
  5693. +
  5694. + // Compatibility mode => check for unsupported modification
  5695. +
  5696. +
  5697. + assert(scratch_class->old_version() != NULL, "must have old version");
  5698. + instanceKlassHandle the_class(scratch_class->old_version());
  5699. +
  5700. int i;
  5701. // Check superclasses, or rather their names, since superclasses themselves can be
  5702. // requested to replace.
  5703. // Check for NULL superclass first since this might be java.lang.Object
  5704. if (the_class->super() != scratch_class->super() &&
  5705. - (the_class->super() == NULL || scratch_class->super() == NULL ||
  5706. - Klass::cast(the_class->super())->name() !=
  5707. - Klass::cast(scratch_class->super())->name())) {
  5708. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  5709. + (the_class->super() == NULL || scratch_class->super() == NULL ||
  5710. + Klass::cast(the_class->super())->name() !=
  5711. + Klass::cast(scratch_class->super())->name())) {
  5712. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  5713. }
  5714. // Check if the number, names and order of directly implemented interfaces are the same.
  5715. @@ -622,8 +678,8 @@
  5716. }
  5717. for (i = 0; i < n_intfs; i++) {
  5718. if (Klass::cast((klassOop) k_interfaces->obj_at(i))->name() !=
  5719. - Klass::cast((klassOop) k_new_interfaces->obj_at(i))->name()) {
  5720. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  5721. + Klass::cast((klassOop) k_new_interfaces->obj_at(i))->name()) {
  5722. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  5723. }
  5724. }
  5725. @@ -772,12 +828,8 @@
  5726. idnum_owner->set_method_idnum(new_num);
  5727. }
  5728. k_new_method->set_method_idnum(old_num);
  5729. - swap_all_method_annotations(old_num, new_num, scratch_class);
  5730. }
  5731. }
  5732. - RC_TRACE(0x00008000, ("Method matched: new: %s [%d] == old: %s [%d]",
  5733. - k_new_method->name_and_sig_as_C_string(), ni,
  5734. - k_old_method->name_and_sig_as_C_string(), oi));
  5735. // advance to next pair of methods
  5736. ++oi;
  5737. ++ni;
  5738. @@ -786,11 +838,11 @@
  5739. // method added, see if it is OK
  5740. new_flags = (jushort) k_new_method->access_flags().get_flags();
  5741. if ((new_flags & JVM_ACC_PRIVATE) == 0
  5742. - // hack: private should be treated as final, but alas
  5743. - || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5744. - ) {
  5745. - // new methods must be private
  5746. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED;
  5747. + // hack: private should be treated as final, but alas
  5748. + || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5749. + ) {
  5750. + // new methods must be private
  5751. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED;
  5752. }
  5753. {
  5754. u2 num = the_class->next_method_idnum();
  5755. @@ -805,24 +857,19 @@
  5756. idnum_owner->set_method_idnum(new_num);
  5757. }
  5758. k_new_method->set_method_idnum(num);
  5759. - swap_all_method_annotations(new_num, num, scratch_class);
  5760. }
  5761. - RC_TRACE(0x00008000, ("Method added: new: %s [%d]",
  5762. - k_new_method->name_and_sig_as_C_string(), ni));
  5763. ++ni; // advance to next new method
  5764. break;
  5765. case deleted:
  5766. // method deleted, see if it is OK
  5767. old_flags = (jushort) k_old_method->access_flags().get_flags();
  5768. if ((old_flags & JVM_ACC_PRIVATE) == 0
  5769. - // hack: private should be treated as final, but alas
  5770. - || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5771. - ) {
  5772. - // deleted methods must be private
  5773. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED;
  5774. + // hack: private should be treated as final, but alas
  5775. + || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5776. + ) {
  5777. + // deleted methods must be private
  5778. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED;
  5779. }
  5780. - RC_TRACE(0x00008000, ("Method deleted: old: %s [%d]",
  5781. - k_old_method->name_and_sig_as_C_string(), oi));
  5782. ++oi; // advance to next old method
  5783. break;
  5784. default:
  5785. @@ -833,2120 +880,2265 @@
  5786. return JVMTI_ERROR_NONE;
  5787. }
  5788. +int VM_RedefineClasses::calculate_redefinition_flags(instanceKlassHandle new_class) {
  5789. -// Find new constant pool index value for old constant pool index value
  5790. -// by seaching the index map. Returns zero (0) if there is no mapped
  5791. -// value for the old constant pool index.
  5792. -int VM_RedefineClasses::find_new_index(int old_index) {
  5793. - if (_index_map_count == 0) {
  5794. - // map is empty so nothing can be found
  5795. - return 0;
  5796. + int result = Klass::NoRedefinition;
  5797. +
  5798. +
  5799. +
  5800. + RC_TRACE(0x00000002, ("Comparing different class versions of class %s",
  5801. + new_class->name()->as_C_string()));
  5802. +
  5803. + assert(new_class->old_version() != NULL, "must have old version");
  5804. + instanceKlassHandle the_class(new_class->old_version());
  5805. +
  5806. + // Check whether class is in the error init state.
  5807. + if (the_class->is_in_error_state()) {
  5808. + // TBD #5057930: special error code is needed in 1.6
  5809. + //result = Klass::union_redefinition_level(result, Klass::Invalid);
  5810. }
  5811. - if (old_index < 1 || old_index >= _index_map_p->length()) {
  5812. - // The old_index is out of range so it is not mapped. This should
  5813. - // not happen in regular constant pool merging use, but it can
  5814. - // happen if a corrupt annotation is processed.
  5815. - return 0;
  5816. - }
  5817. + int i;
  5818. - int value = _index_map_p->at(old_index);
  5819. - if (value == -1) {
  5820. - // the old_index is not mapped
  5821. - return 0;
  5822. - }
  5823. + //////////////////////////////////////////////////////////////////////////////////////////////////////////
  5824. + // Check superclasses
  5825. + assert(new_class->super() == NULL || new_class->super()->klass_part()->is_newest_version(), "");
  5826. + if (the_class->super() != new_class->super()) {
  5827. + // Super class changed
  5828. - return value;
  5829. -} // end find_new_index()
  5830. + klassOop cur_klass = the_class->super();
  5831. + while (cur_klass != NULL) {
  5832. + if (!new_class->is_subclass_of(cur_klass->klass_part()->newest_version())) {
  5833. + RC_TRACE(0x00000002, ("Removed super class %s",
  5834. + cur_klass->klass_part()->name()->as_C_string()));
  5835. + result = result | Klass::RemoveSuperType | Klass::ModifyInstances | Klass::ModifyClass;
  5836. -
  5837. -// Find new bootstrap specifier index value for old bootstrap specifier index
  5838. -// value by seaching the index map. Returns zero (-1) if there is no mapped
  5839. -// value for the old bootstrap specifier index.
  5840. -int VM_RedefineClasses::find_new_operand_index(int old_index) {
  5841. - if (_operands_index_map_count == 0) {
  5842. - // map is empty so nothing can be found
  5843. - return -1;
  5844. - }
  5845. -
  5846. - if (old_index == -1 || old_index >= _operands_index_map_p->length()) {
  5847. - // The old_index is out of range so it is not mapped.
  5848. - // This should not happen in regular constant pool merging use.
  5849. - return -1;
  5850. - }
  5851. -
  5852. - int value = _operands_index_map_p->at(old_index);
  5853. -
  5854. - return value;
  5855. -} // end find_new_operand_index()
  5856. -
  5857. -
  5858. -// Returns true if the current mismatch is due to a resolved/unresolved
  5859. -// class pair. Otherwise, returns false.
  5860. -bool VM_RedefineClasses::is_unresolved_class_mismatch(constantPoolHandle cp1,
  5861. - int index1, constantPoolHandle cp2, int index2) {
  5862. -
  5863. - jbyte t1 = cp1->tag_at(index1).value();
  5864. - if (t1 != JVM_CONSTANT_Class && t1 != JVM_CONSTANT_UnresolvedClass) {
  5865. - return false; // wrong entry type; not our special case
  5866. - }
  5867. -
  5868. - jbyte t2 = cp2->tag_at(index2).value();
  5869. - if (t2 != JVM_CONSTANT_Class && t2 != JVM_CONSTANT_UnresolvedClass) {
  5870. - return false; // wrong entry type; not our special case
  5871. - }
  5872. -
  5873. - if (t1 == t2) {
  5874. - return false; // not a mismatch; not our special case
  5875. - }
  5876. -
  5877. - char *s1 = cp1->klass_name_at(index1)->as_C_string();
  5878. - char *s2 = cp2->klass_name_at(index2)->as_C_string();
  5879. - if (strcmp(s1, s2) != 0) {
  5880. - return false; // strings don't match; not our special case
  5881. - }
  5882. -
  5883. - return true; // made it through the gauntlet; this is our special case
  5884. -} // end is_unresolved_class_mismatch()
  5885. -
  5886. -
  5887. -// Returns true if the current mismatch is due to a resolved/unresolved
  5888. -// string pair. Otherwise, returns false.
  5889. -bool VM_RedefineClasses::is_unresolved_string_mismatch(constantPoolHandle cp1,
  5890. - int index1, constantPoolHandle cp2, int index2) {
  5891. -
  5892. - jbyte t1 = cp1->tag_at(index1).value();
  5893. - if (t1 != JVM_CONSTANT_String && t1 != JVM_CONSTANT_UnresolvedString) {
  5894. - return false; // wrong entry type; not our special case
  5895. - }
  5896. -
  5897. - jbyte t2 = cp2->tag_at(index2).value();
  5898. - if (t2 != JVM_CONSTANT_String && t2 != JVM_CONSTANT_UnresolvedString) {
  5899. - return false; // wrong entry type; not our special case
  5900. - }
  5901. -
  5902. - if (t1 == t2) {
  5903. - return false; // not a mismatch; not our special case
  5904. - }
  5905. -
  5906. - char *s1 = cp1->string_at_noresolve(index1);
  5907. - char *s2 = cp2->string_at_noresolve(index2);
  5908. - if (strcmp(s1, s2) != 0) {
  5909. - return false; // strings don't match; not our special case
  5910. - }
  5911. -
  5912. - return true; // made it through the gauntlet; this is our special case
  5913. -} // end is_unresolved_string_mismatch()
  5914. -
  5915. -
  5916. -jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) {
  5917. - // For consistency allocate memory using os::malloc wrapper.
  5918. - _scratch_classes = (instanceKlassHandle *)
  5919. - os::malloc(sizeof(instanceKlassHandle) * _class_count, mtInternal);
  5920. - if (_scratch_classes == NULL) {
  5921. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5922. - }
  5923. -
  5924. - ResourceMark rm(THREAD);
  5925. -
  5926. - JvmtiThreadState *state = JvmtiThreadState::state_for(JavaThread::current());
  5927. - // state can only be NULL if the current thread is exiting which
  5928. - // should not happen since we're trying to do a RedefineClasses
  5929. - guarantee(state != NULL, "exiting thread calling load_new_class_versions");
  5930. - for (int i = 0; i < _class_count; i++) {
  5931. - oop mirror = JNIHandles::resolve_non_null(_class_defs[i].klass);
  5932. - // classes for primitives cannot be redefined
  5933. - if (!is_modifiable_class(mirror)) {
  5934. - return JVMTI_ERROR_UNMODIFIABLE_CLASS;
  5935. - }
  5936. - klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
  5937. - instanceKlassHandle the_class = instanceKlassHandle(THREAD, the_class_oop);
  5938. - Symbol* the_class_sym = the_class->name();
  5939. -
  5940. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5941. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  5942. - ("loading name=%s kind=%d (avail_mem=" UINT64_FORMAT "K)",
  5943. - the_class->external_name(), _class_load_kind,
  5944. - os::available_memory() >> 10));
  5945. -
  5946. - ClassFileStream st((u1*) _class_defs[i].class_bytes,
  5947. - _class_defs[i].class_byte_count, (char *)"__VM_RedefineClasses__");
  5948. -
  5949. - // Parse the stream.
  5950. - Handle the_class_loader(THREAD, the_class->class_loader());
  5951. - Handle protection_domain(THREAD, the_class->protection_domain());
  5952. - // Set redefined class handle in JvmtiThreadState class.
  5953. - // This redefined class is sent to agent event handler for class file
  5954. - // load hook event.
  5955. - state->set_class_being_redefined(&the_class, _class_load_kind);
  5956. -
  5957. - klassOop k = SystemDictionary::parse_stream(the_class_sym,
  5958. - the_class_loader,
  5959. - protection_domain,
  5960. - &st,
  5961. - THREAD);
  5962. - // Clear class_being_redefined just to be sure.
  5963. - state->clear_class_being_redefined();
  5964. -
  5965. - // TODO: if this is retransform, and nothing changed we can skip it
  5966. -
  5967. - instanceKlassHandle scratch_class (THREAD, k);
  5968. -
  5969. - if (HAS_PENDING_EXCEPTION) {
  5970. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  5971. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5972. - RC_TRACE_WITH_THREAD(0x00000002, THREAD, ("parse_stream exception: '%s'",
  5973. - ex_name->as_C_string()));
  5974. - CLEAR_PENDING_EXCEPTION;
  5975. -
  5976. - if (ex_name == vmSymbols::java_lang_UnsupportedClassVersionError()) {
  5977. - return JVMTI_ERROR_UNSUPPORTED_VERSION;
  5978. - } else if (ex_name == vmSymbols::java_lang_ClassFormatError()) {
  5979. - return JVMTI_ERROR_INVALID_CLASS_FORMAT;
  5980. - } else if (ex_name == vmSymbols::java_lang_ClassCircularityError()) {
  5981. - return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  5982. - } else if (ex_name == vmSymbols::java_lang_NoClassDefFoundError()) {
  5983. - // The message will be "XXX (wrong name: YYY)"
  5984. - return JVMTI_ERROR_NAMES_DONT_MATCH;
  5985. - } else if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  5986. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5987. - } else { // Just in case more exceptions can be thrown..
  5988. - return JVMTI_ERROR_FAILS_VERIFICATION;
  5989. - }
  5990. - }
  5991. -
  5992. - // Ensure class is linked before redefine
  5993. - if (!the_class->is_linked()) {
  5994. - the_class->link_class(THREAD);
  5995. - if (HAS_PENDING_EXCEPTION) {
  5996. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  5997. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5998. - RC_TRACE_WITH_THREAD(0x00000002, THREAD, ("link_class exception: '%s'",
  5999. - ex_name->as_C_string()));
  6000. - CLEAR_PENDING_EXCEPTION;
  6001. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  6002. - return JVMTI_ERROR_OUT_OF_MEMORY;
  6003. - } else {
  6004. - return JVMTI_ERROR_INTERNAL;
  6005. + if (!cur_klass->klass_part()->has_subtype_changed()) {
  6006. + RC_TRACE(0x00000002, ("Subtype changed of class %s",
  6007. + cur_klass->klass_part()->name()->as_C_string()));
  6008. + cur_klass->klass_part()->set_subtype_changed(true);
  6009. }
  6010. }
  6011. +
  6012. + cur_klass = cur_klass->klass_part()->super();
  6013. }
  6014. - // Do the validity checks in compare_and_normalize_class_versions()
  6015. - // before verifying the byte codes. By doing these checks first, we
  6016. - // limit the number of functions that require redirection from
  6017. - // the_class to scratch_class. In particular, we don't have to
  6018. - // modify JNI GetSuperclass() and thus won't change its performance.
  6019. - jvmtiError res = compare_and_normalize_class_versions(the_class,
  6020. - scratch_class);
  6021. - if (res != JVMTI_ERROR_NONE) {
  6022. - return res;
  6023. - }
  6024. -
  6025. - // verify what the caller passed us
  6026. - {
  6027. - // The bug 6214132 caused the verification to fail.
  6028. - // Information about the_class and scratch_class is temporarily
  6029. - // recorded into jvmtiThreadState. This data is used to redirect
  6030. - // the_class to scratch_class in the JVM_* functions called by the
  6031. - // verifier. Please, refer to jvmtiThreadState.hpp for the detailed
  6032. - // description.
  6033. - RedefineVerifyMark rvm(&the_class, &scratch_class, state);
  6034. - Verifier::verify(
  6035. - scratch_class, Verifier::ThrowException, true, THREAD);
  6036. - }
  6037. -
  6038. - if (HAS_PENDING_EXCEPTION) {
  6039. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  6040. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  6041. - RC_TRACE_WITH_THREAD(0x00000002, THREAD,
  6042. - ("verify_byte_codes exception: '%s'", ex_name->as_C_string()));
  6043. - CLEAR_PENDING_EXCEPTION;
  6044. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  6045. - return JVMTI_ERROR_OUT_OF_MEMORY;
  6046. - } else {
  6047. - // tell the caller the bytecodes are bad
  6048. - return JVMTI_ERROR_FAILS_VERIFICATION;
  6049. + cur_klass = new_class->super();
  6050. + while (cur_klass != NULL) {
  6051. + if (!the_class->is_subclass_of(cur_klass->klass_part()->old_version())) {
  6052. + RC_TRACE(0x00000002, ("Added super class %s",
  6053. + cur_klass->klass_part()->name()->as_C_string()));
  6054. + result = result | Klass::ModifyClass | Klass::ModifyInstances;
  6055. }
  6056. - }
  6057. -
  6058. - res = merge_cp_and_rewrite(the_class, scratch_class, THREAD);
  6059. - if (res != JVMTI_ERROR_NONE) {
  6060. - return res;
  6061. - }
  6062. -
  6063. - if (VerifyMergedCPBytecodes) {
  6064. - // verify what we have done during constant pool merging
  6065. - {
  6066. - RedefineVerifyMark rvm(&the_class, &scratch_class, state);
  6067. - Verifier::verify(scratch_class, Verifier::ThrowException, true, THREAD);
  6068. - }
  6069. -
  6070. - if (HAS_PENDING_EXCEPTION) {
  6071. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  6072. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  6073. - RC_TRACE_WITH_THREAD(0x00000002, THREAD,
  6074. - ("verify_byte_codes post merge-CP exception: '%s'",
  6075. - ex_name->as_C_string()));
  6076. - CLEAR_PENDING_EXCEPTION;
  6077. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  6078. - return JVMTI_ERROR_OUT_OF_MEMORY;
  6079. - } else {
  6080. - // tell the caller that constant pool merging screwed up
  6081. - return JVMTI_ERROR_INTERNAL;
  6082. - }
  6083. - }
  6084. - }
  6085. -
  6086. - Rewriter::rewrite(scratch_class, THREAD);
  6087. - if (!HAS_PENDING_EXCEPTION) {
  6088. - Rewriter::relocate_and_link(scratch_class, THREAD);
  6089. - }
  6090. - if (HAS_PENDING_EXCEPTION) {
  6091. - Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  6092. - CLEAR_PENDING_EXCEPTION;
  6093. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  6094. - return JVMTI_ERROR_OUT_OF_MEMORY;
  6095. - } else {
  6096. - return JVMTI_ERROR_INTERNAL;
  6097. - }
  6098. - }
  6099. -
  6100. - _scratch_classes[i] = scratch_class;
  6101. -
  6102. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  6103. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  6104. - ("loaded name=%s (avail_mem=" UINT64_FORMAT "K)",
  6105. - the_class->external_name(), os::available_memory() >> 10));
  6106. - }
  6107. -
  6108. - return JVMTI_ERROR_NONE;
  6109. -}
  6110. -
  6111. -
  6112. -// Map old_index to new_index as needed. scratch_cp is only needed
  6113. -// for RC_TRACE() calls.
  6114. -void VM_RedefineClasses::map_index(constantPoolHandle scratch_cp,
  6115. - int old_index, int new_index) {
  6116. - if (find_new_index(old_index) != 0) {
  6117. - // old_index is already mapped
  6118. - return;
  6119. - }
  6120. -
  6121. - if (old_index == new_index) {
  6122. - // no mapping is needed
  6123. - return;
  6124. - }
  6125. -
  6126. - _index_map_p->at_put(old_index, new_index);
  6127. - _index_map_count++;
  6128. -
  6129. - RC_TRACE(0x00040000, ("mapped tag %d at index %d to %d",
  6130. - scratch_cp->tag_at(old_index).value(), old_index, new_index));
  6131. -} // end map_index()
  6132. -
  6133. -
  6134. -// Map old_index to new_index as needed.
  6135. -void VM_RedefineClasses::map_operand_index(int old_index, int new_index) {
  6136. - if (find_new_operand_index(old_index) != -1) {
  6137. - // old_index is already mapped
  6138. - return;
  6139. - }
  6140. -
  6141. - if (old_index == new_index) {
  6142. - // no mapping is needed
  6143. - return;
  6144. - }
  6145. -
  6146. - _operands_index_map_p->at_put(old_index, new_index);
  6147. - _operands_index_map_count++;
  6148. -
  6149. - RC_TRACE(0x00040000, ("mapped bootstrap specifier at index %d to %d", old_index, new_index));
  6150. -} // end map_index()
  6151. -
  6152. -
  6153. -// Merge old_cp and scratch_cp and return the results of the merge via
  6154. -// merge_cp_p. The number of entries in *merge_cp_p is returned via
  6155. -// merge_cp_length_p. The entries in old_cp occupy the same locations
  6156. -// in *merge_cp_p. Also creates a map of indices from entries in
  6157. -// scratch_cp to the corresponding entry in *merge_cp_p. Index map
  6158. -// entries are only created for entries in scratch_cp that occupy a
  6159. -// different location in *merged_cp_p.
  6160. -bool VM_RedefineClasses::merge_constant_pools(constantPoolHandle old_cp,
  6161. - constantPoolHandle scratch_cp, constantPoolHandle *merge_cp_p,
  6162. - int *merge_cp_length_p, TRAPS) {
  6163. -
  6164. - if (merge_cp_p == NULL) {
  6165. - assert(false, "caller must provide scatch constantPool");
  6166. - return false; // robustness
  6167. - }
  6168. - if (merge_cp_length_p == NULL) {
  6169. - assert(false, "caller must provide scatch CP length");
  6170. - return false; // robustness
  6171. - }
  6172. - // Worst case we need old_cp->length() + scratch_cp()->length(),
  6173. - // but the caller might be smart so make sure we have at least
  6174. - // the minimum.
  6175. - if ((*merge_cp_p)->length() < old_cp->length()) {
  6176. - assert(false, "merge area too small");
  6177. - return false; // robustness
  6178. - }
  6179. -
  6180. - RC_TRACE_WITH_THREAD(0x00010000, THREAD,
  6181. - ("old_cp_len=%d, scratch_cp_len=%d", old_cp->length(),
  6182. - scratch_cp->length()));
  6183. -
  6184. - {
  6185. - // Pass 0:
  6186. - // The old_cp is copied to *merge_cp_p; this means that any code
  6187. - // using old_cp does not have to change. This work looks like a
  6188. - // perfect fit for constantPoolOop::copy_cp_to(), but we need to
  6189. - // handle one special case:
  6190. - // - revert JVM_CONSTANT_Class to JVM_CONSTANT_UnresolvedClass
  6191. - // This will make verification happy.
  6192. -
  6193. - int old_i; // index into old_cp
  6194. -
  6195. - // index zero (0) is not used in constantPools
  6196. - for (old_i = 1; old_i < old_cp->length(); old_i++) {
  6197. - // leave debugging crumb
  6198. - jbyte old_tag = old_cp->tag_at(old_i).value();
  6199. - switch (old_tag) {
  6200. - case JVM_CONSTANT_Class:
  6201. - case JVM_CONSTANT_UnresolvedClass:
  6202. - // revert the copy to JVM_CONSTANT_UnresolvedClass
  6203. - // May be resolving while calling this so do the same for
  6204. - // JVM_CONSTANT_UnresolvedClass (klass_name_at() deals with transition)
  6205. - (*merge_cp_p)->unresolved_klass_at_put(old_i,
  6206. - old_cp->klass_name_at(old_i));
  6207. - break;
  6208. -
  6209. - case JVM_CONSTANT_Double:
  6210. - case JVM_CONSTANT_Long:
  6211. - // just copy the entry to *merge_cp_p, but double and long take
  6212. - // two constant pool entries
  6213. - constantPoolOopDesc::copy_entry_to(old_cp, old_i, *merge_cp_p, old_i, CHECK_0);
  6214. - old_i++;
  6215. - break;
  6216. -
  6217. - default:
  6218. - // just copy the entry to *merge_cp_p
  6219. - constantPoolOopDesc::copy_entry_to(old_cp, old_i, *merge_cp_p, old_i, CHECK_0);
  6220. - break;
  6221. - }
  6222. - } // end for each old_cp entry
  6223. -
  6224. - constantPoolOopDesc::copy_operands(old_cp, *merge_cp_p, CHECK_0);
  6225. - (*merge_cp_p)->extend_operands(scratch_cp, CHECK_0);
  6226. -
  6227. - // We don't need to sanity check that *merge_cp_length_p is within
  6228. - // *merge_cp_p bounds since we have the minimum on-entry check above.
  6229. - (*merge_cp_length_p) = old_i;
  6230. - }
  6231. -
  6232. - // merge_cp_len should be the same as old_cp->length() at this point
  6233. - // so this trace message is really a "warm-and-breathing" message.
  6234. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  6235. - ("after pass 0: merge_cp_len=%d", *merge_cp_length_p));
  6236. -
  6237. - int scratch_i; // index into scratch_cp
  6238. - {
  6239. - // Pass 1a:
  6240. - // Compare scratch_cp entries to the old_cp entries that we have
  6241. - // already copied to *merge_cp_p. In this pass, we are eliminating
  6242. - // exact duplicates (matching entry at same index) so we only
  6243. - // compare entries in the common indice range.
  6244. - int increment = 1;
  6245. - int pass1a_length = MIN2(old_cp->length(), scratch_cp->length());
  6246. - for (scratch_i = 1; scratch_i < pass1a_length; scratch_i += increment) {
  6247. - switch (scratch_cp->tag_at(scratch_i).value()) {
  6248. - case JVM_CONSTANT_Double:
  6249. - case JVM_CONSTANT_Long:
  6250. - // double and long take two constant pool entries
  6251. - increment = 2;
  6252. - break;
  6253. -
  6254. - default:
  6255. - increment = 1;
  6256. - break;
  6257. - }
  6258. -
  6259. - bool match = scratch_cp->compare_entry_to(scratch_i, *merge_cp_p,
  6260. - scratch_i, CHECK_0);
  6261. - if (match) {
  6262. - // found a match at the same index so nothing more to do
  6263. - continue;
  6264. - } else if (is_unresolved_class_mismatch(scratch_cp, scratch_i,
  6265. - *merge_cp_p, scratch_i)) {
  6266. - // The mismatch in compare_entry_to() above is because of a
  6267. - // resolved versus unresolved class entry at the same index
  6268. - // with the same string value. Since Pass 0 reverted any
  6269. - // class entries to unresolved class entries in *merge_cp_p,
  6270. - // we go with the unresolved class entry.
  6271. - continue;
  6272. - } else if (is_unresolved_string_mismatch(scratch_cp, scratch_i,
  6273. - *merge_cp_p, scratch_i)) {
  6274. - // The mismatch in compare_entry_to() above is because of a
  6275. - // resolved versus unresolved string entry at the same index
  6276. - // with the same string value. We can live with whichever
  6277. - // happens to be at scratch_i in *merge_cp_p.
  6278. - continue;
  6279. - }
  6280. -
  6281. - int found_i = scratch_cp->find_matching_entry(scratch_i, *merge_cp_p,
  6282. - CHECK_0);
  6283. - if (found_i != 0) {
  6284. - guarantee(found_i != scratch_i,
  6285. - "compare_entry_to() and find_matching_entry() do not agree");
  6286. -
  6287. - // Found a matching entry somewhere else in *merge_cp_p so
  6288. - // just need a mapping entry.
  6289. - map_index(scratch_cp, scratch_i, found_i);
  6290. - continue;
  6291. - }
  6292. -
  6293. - // The find_matching_entry() call above could fail to find a match
  6294. - // due to a resolved versus unresolved class or string entry situation
  6295. - // like we solved above with the is_unresolved_*_mismatch() calls.
  6296. - // However, we would have to call is_unresolved_*_mismatch() over
  6297. - // all of *merge_cp_p (potentially) and that doesn't seem to be
  6298. - // worth the time.
  6299. -
  6300. - // No match found so we have to append this entry and any unique
  6301. - // referenced entries to *merge_cp_p.
  6302. - append_entry(scratch_cp, scratch_i, merge_cp_p, merge_cp_length_p,
  6303. - CHECK_0);
  6304. + cur_klass = cur_klass->klass_part()->super();
  6305. }
  6306. }
  6307. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  6308. - ("after pass 1a: merge_cp_len=%d, scratch_i=%d, index_map_len=%d",
  6309. - *merge_cp_length_p, scratch_i, _index_map_count));
  6310. + //////////////////////////////////////////////////////////////////////////////////////////////////////////
  6311. + // Check interfaces
  6312. - if (scratch_i < scratch_cp->length()) {
  6313. - // Pass 1b:
  6314. - // old_cp is smaller than scratch_cp so there are entries in
  6315. - // scratch_cp that we have not yet processed. We take care of
  6316. - // those now.
  6317. - int increment = 1;
  6318. - for (; scratch_i < scratch_cp->length(); scratch_i += increment) {
  6319. - switch (scratch_cp->tag_at(scratch_i).value()) {
  6320. - case JVM_CONSTANT_Double:
  6321. - case JVM_CONSTANT_Long:
  6322. - // double and long take two constant pool entries
  6323. - increment = 2;
  6324. - break;
  6325. -
  6326. - default:
  6327. - increment = 1;
  6328. - break;
  6329. + // Interfaces removed?
  6330. + objArrayOop old_interfaces = the_class->transitive_interfaces();
  6331. + for (i = 0; i<old_interfaces->length(); i++) {
  6332. + instanceKlassHandle old_interface((klassOop)old_interfaces->obj_at(i));
  6333. + if (!new_class->implements_interface_any_version(old_interface())) {
  6334. + result = result | Klass::RemoveSuperType | Klass::ModifyClass;
  6335. + RC_TRACE(0x00000002, ("Removed interface %s",
  6336. + old_interface->name()->as_C_string()));
  6337. +
  6338. + if (!old_interface->has_subtype_changed()) {
  6339. + RC_TRACE(0x00000002, ("Subtype changed of interface %s",
  6340. + old_interface->name()->as_C_string()));
  6341. + old_interface->set_subtype_changed(true);
  6342. }
  6343. -
  6344. - int found_i =
  6345. - scratch_cp->find_matching_entry(scratch_i, *merge_cp_p, CHECK_0);
  6346. - if (found_i != 0) {
  6347. - // Found a matching entry somewhere else in *merge_cp_p so
  6348. - // just need a mapping entry.
  6349. - map_index(scratch_cp, scratch_i, found_i);
  6350. - continue;
  6351. - }
  6352. -
  6353. - // No match found so we have to append this entry and any unique
  6354. - // referenced entries to *merge_cp_p.
  6355. - append_entry(scratch_cp, scratch_i, merge_cp_p, merge_cp_length_p,
  6356. - CHECK_0);
  6357. }
  6358. -
  6359. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  6360. - ("after pass 1b: merge_cp_len=%d, scratch_i=%d, index_map_len=%d",
  6361. - *merge_cp_length_p, scratch_i, _index_map_count));
  6362. - }
  6363. - finalize_operands_merge(*merge_cp_p, THREAD);
  6364. -
  6365. - return true;
  6366. -} // end merge_constant_pools()
  6367. -
  6368. -
  6369. -// Merge constant pools between the_class and scratch_class and
  6370. -// potentially rewrite bytecodes in scratch_class to use the merged
  6371. -// constant pool.
  6372. -jvmtiError VM_RedefineClasses::merge_cp_and_rewrite(
  6373. - instanceKlassHandle the_class, instanceKlassHandle scratch_class,
  6374. - TRAPS) {
  6375. - // worst case merged constant pool length is old and new combined
  6376. - int merge_cp_length = the_class->constants()->length()
  6377. - + scratch_class->constants()->length();
  6378. -
  6379. - constantPoolHandle old_cp(THREAD, the_class->constants());
  6380. - constantPoolHandle scratch_cp(THREAD, scratch_class->constants());
  6381. -
  6382. - // Constant pools are not easily reused so we allocate a new one
  6383. - // each time.
  6384. - // merge_cp is created unsafe for concurrent GC processing. It
  6385. - // should be marked safe before discarding it. Even though
  6386. - // garbage, if it crosses a card boundary, it may be scanned
  6387. - // in order to find the start of the first complete object on the card.
  6388. - constantPoolHandle merge_cp(THREAD,
  6389. - oopFactory::new_constantPool(merge_cp_length,
  6390. - oopDesc::IsUnsafeConc,
  6391. - THREAD));
  6392. - int orig_length = old_cp->orig_length();
  6393. - if (orig_length == 0) {
  6394. - // This old_cp is an actual original constant pool. We save
  6395. - // the original length in the merged constant pool so that
  6396. - // merge_constant_pools() can be more efficient. If a constant
  6397. - // pool has a non-zero orig_length() value, then that constant
  6398. - // pool was created by a merge operation in RedefineClasses.
  6399. - merge_cp->set_orig_length(old_cp->length());
  6400. - } else {
  6401. - // This old_cp is a merged constant pool from a previous
  6402. - // RedefineClasses() calls so just copy the orig_length()
  6403. - // value.
  6404. - merge_cp->set_orig_length(old_cp->orig_length());
  6405. }
  6406. - ResourceMark rm(THREAD);
  6407. - _index_map_count = 0;
  6408. - _index_map_p = new intArray(scratch_cp->length(), -1);
  6409. -
  6410. - _operands_cur_length = constantPoolOopDesc::operand_array_length(old_cp->operands());
  6411. - _operands_index_map_count = 0;
  6412. - _operands_index_map_p = new intArray(
  6413. - constantPoolOopDesc::operand_array_length(scratch_cp->operands()), -1);
  6414. -
  6415. - // reference to the cp holder is needed for copy_operands()
  6416. - merge_cp->set_pool_holder(scratch_class());
  6417. - bool result = merge_constant_pools(old_cp, scratch_cp, &merge_cp,
  6418. - &merge_cp_length, THREAD);
  6419. - merge_cp->set_pool_holder(NULL);
  6420. -
  6421. - if (!result) {
  6422. - // The merge can fail due to memory allocation failure or due
  6423. - // to robustness checks.
  6424. - return JVMTI_ERROR_INTERNAL;
  6425. + // Interfaces added?
  6426. + objArrayOop new_interfaces = new_class->transitive_interfaces();
  6427. + for (i = 0; i<new_interfaces->length(); i++) {
  6428. + if (!the_class->implements_interface_any_version((klassOop)new_interfaces->obj_at(i))) {
  6429. + result = result | Klass::ModifyClass;
  6430. + RC_TRACE(0x00000002, ("Added interface %s",
  6431. + ((klassOop)new_interfaces->obj_at(i))->klass_part()->name()->as_C_string()));
  6432. + }
  6433. }
  6434. - RC_TRACE_WITH_THREAD(0x00010000, THREAD,
  6435. - ("merge_cp_len=%d, index_map_len=%d", merge_cp_length, _index_map_count));
  6436. - if (_index_map_count == 0) {
  6437. - // there is nothing to map between the new and merged constant pools
  6438. + // Check whether class modifiers are the same.
  6439. + jushort old_flags = (jushort) the_class->access_flags().get_flags();
  6440. + jushort new_flags = (jushort) new_class->access_flags().get_flags();
  6441. + if (old_flags != new_flags) {
  6442. + // TODO (tw): Can this have any effects?
  6443. + }
  6444. - if (old_cp->length() == scratch_cp->length()) {
  6445. - // The old and new constant pools are the same length and the
  6446. - // index map is empty. This means that the three constant pools
  6447. - // are equivalent (but not the same). Unfortunately, the new
  6448. - // constant pool has not gone through link resolution nor have
  6449. - // the new class bytecodes gone through constant pool cache
  6450. - // rewriting so we can't use the old constant pool with the new
  6451. - // class.
  6452. + // Check if the number, names, types and order of fields declared in these classes
  6453. + // are the same.
  6454. + JavaFieldStream old_fs(the_class);
  6455. + JavaFieldStream new_fs(new_class);
  6456. + for (; !old_fs.done() && !new_fs.done(); old_fs.next(), new_fs.next()) {
  6457. + // access
  6458. + old_flags = old_fs.access_flags().as_short();
  6459. + new_flags = new_fs.access_flags().as_short();
  6460. + if ((old_flags ^ new_flags) & JVM_RECOGNIZED_FIELD_MODIFIERS) {
  6461. + // (tw) Can this have any effects?
  6462. + }
  6463. + // offset
  6464. + if (old_fs.offset() != new_fs.offset()) {
  6465. + result = result | Klass::ModifyInstances;
  6466. + }
  6467. + // name and signature
  6468. + Symbol* name_sym1 = the_class->constants()->symbol_at(old_fs.name_index());
  6469. + Symbol* sig_sym1 = the_class->constants()->symbol_at(old_fs.signature_index());
  6470. + Symbol* name_sym2 = new_class->constants()->symbol_at(new_fs.name_index());
  6471. + Symbol* sig_sym2 = new_class->constants()->symbol_at(new_fs.signature_index());
  6472. + if (name_sym1 != name_sym2 || sig_sym1 != sig_sym2) {
  6473. + result = result | Klass::ModifyInstances;
  6474. + }
  6475. + }
  6476. - merge_cp()->set_is_conc_safe(true);
  6477. - merge_cp = constantPoolHandle(); // toss the merged constant pool
  6478. - } else if (old_cp->length() < scratch_cp->length()) {
  6479. - // The old constant pool has fewer entries than the new constant
  6480. - // pool and the index map is empty. This means the new constant
  6481. - // pool is a superset of the old constant pool. However, the old
  6482. - // class bytecodes have already gone through constant pool cache
  6483. - // rewriting so we can't use the new constant pool with the old
  6484. - // class.
  6485. + if (!old_fs.done() || !new_fs.done()) {
  6486. + result = result | Klass::ModifyInstances;
  6487. + }
  6488. - merge_cp()->set_is_conc_safe(true);
  6489. - merge_cp = constantPoolHandle(); // toss the merged constant pool
  6490. + // Do a parallel walk through the old and new methods. Detect
  6491. + // cases where they match (exist in both), have been added in
  6492. + // the new methods, or have been deleted (exist only in the
  6493. + // old methods). The class file parser places methods in order
  6494. + // by method name, but does not order overloaded methods by
  6495. + // signature. In order to determine what fate befell the methods,
  6496. + // this code places the overloaded new methods that have matching
  6497. + // old methods in the same order as the old methods and places
  6498. + // new overloaded methods at the end of overloaded methods of
  6499. + // that name. The code for this order normalization is adapted
  6500. + // from the algorithm used in instanceKlass::find_method().
  6501. + // Since we are swapping out of order entries as we find them,
  6502. + // we only have to search forward through the overloaded methods.
  6503. + // Methods which are added and have the same name as an existing
  6504. + // method (but different signature) will be put at the end of
  6505. + // the methods with that name, and the name mismatch code will
  6506. + // handle them.
  6507. + objArrayHandle k_old_methods(the_class->methods());
  6508. + objArrayHandle k_new_methods(new_class->methods());
  6509. + int n_old_methods = k_old_methods->length();
  6510. + int n_new_methods = k_new_methods->length();
  6511. +
  6512. + int ni = 0;
  6513. + int oi = 0;
  6514. + while (true) {
  6515. + methodOop k_old_method;
  6516. + methodOop k_new_method;
  6517. + enum { matched, added, deleted, undetermined } method_was = undetermined;
  6518. +
  6519. + if (oi >= n_old_methods) {
  6520. + if (ni >= n_new_methods) {
  6521. + break; // we've looked at everything, done
  6522. + }
  6523. + // New method at the end
  6524. + k_new_method = (methodOop) k_new_methods->obj_at(ni);
  6525. + method_was = added;
  6526. + } else if (ni >= n_new_methods) {
  6527. + // Old method, at the end, is deleted
  6528. + k_old_method = (methodOop) k_old_methods->obj_at(oi);
  6529. + method_was = deleted;
  6530. } else {
  6531. - // The old constant pool has more entries than the new constant
  6532. - // pool and the index map is empty. This means that both the old
  6533. - // and merged constant pools are supersets of the new constant
  6534. - // pool.
  6535. + // There are more methods in both the old and new lists
  6536. + k_old_method = (methodOop) k_old_methods->obj_at(oi);
  6537. + k_new_method = (methodOop) k_new_methods->obj_at(ni);
  6538. + if (k_old_method->name() != k_new_method->name()) {
  6539. + // Methods are sorted by method name, so a mismatch means added
  6540. + // or deleted
  6541. + if (k_old_method->name()->fast_compare(k_new_method->name()) > 0) {
  6542. + method_was = added;
  6543. + } else {
  6544. + method_was = deleted;
  6545. + }
  6546. + } else if (k_old_method->signature() == k_new_method->signature()) {
  6547. + // Both the name and signature match
  6548. + method_was = matched;
  6549. + } else {
  6550. + // The name matches, but the signature doesn't, which means we have to
  6551. + // search forward through the new overloaded methods.
  6552. + int nj; // outside the loop for post-loop check
  6553. + for (nj = ni + 1; nj < n_new_methods; nj++) {
  6554. + methodOop m = (methodOop)k_new_methods->obj_at(nj);
  6555. + if (k_old_method->name() != m->name()) {
  6556. + // reached another method name so no more overloaded methods
  6557. + method_was = deleted;
  6558. + break;
  6559. + }
  6560. + if (k_old_method->signature() == m->signature()) {
  6561. + // found a match so swap the methods
  6562. + k_new_methods->obj_at_put(ni, m);
  6563. + k_new_methods->obj_at_put(nj, k_new_method);
  6564. + k_new_method = m;
  6565. + method_was = matched;
  6566. + break;
  6567. + }
  6568. + }
  6569. - // Replace the new constant pool with a shrunken copy of the
  6570. - // merged constant pool; the previous new constant pool will
  6571. - // get GCed.
  6572. - set_new_constant_pool(scratch_class, merge_cp, merge_cp_length,
  6573. - THREAD);
  6574. - // drop local ref to the merged constant pool
  6575. - merge_cp()->set_is_conc_safe(true);
  6576. - merge_cp = constantPoolHandle();
  6577. - }
  6578. - } else {
  6579. - if (RC_TRACE_ENABLED(0x00040000)) {
  6580. - // don't want to loop unless we are tracing
  6581. - int count = 0;
  6582. - for (int i = 1; i < _index_map_p->length(); i++) {
  6583. - int value = _index_map_p->at(i);
  6584. -
  6585. - if (value != -1) {
  6586. - RC_TRACE_WITH_THREAD(0x00040000, THREAD,
  6587. - ("index_map[%d]: old=%d new=%d", count, i, value));
  6588. - count++;
  6589. + if (nj >= n_new_methods) {
  6590. + // reached the end without a match; so method was deleted
  6591. + method_was = deleted;
  6592. }
  6593. }
  6594. }
  6595. - // We have entries mapped between the new and merged constant pools
  6596. - // so we have to rewrite some constant pool references.
  6597. - if (!rewrite_cp_refs(scratch_class, THREAD)) {
  6598. - return JVMTI_ERROR_INTERNAL;
  6599. + switch (method_was) {
  6600. + case matched:
  6601. + // methods match, be sure modifiers do too
  6602. + old_flags = (jushort) k_old_method->access_flags().get_flags();
  6603. + new_flags = (jushort) k_new_method->access_flags().get_flags();
  6604. + if ((old_flags ^ new_flags) & ~(JVM_ACC_NATIVE)) {
  6605. + // (tw) Can this have any effects? Probably yes on vtables?
  6606. + result = result | Klass::ModifyClass;
  6607. }
  6608. -
  6609. - // Replace the new constant pool with a shrunken copy of the
  6610. - // merged constant pool so now the rewritten bytecodes have
  6611. - // valid references; the previous new constant pool will get
  6612. - // GCed.
  6613. - set_new_constant_pool(scratch_class, merge_cp, merge_cp_length,
  6614. - THREAD);
  6615. - merge_cp()->set_is_conc_safe(true);
  6616. - }
  6617. - assert(old_cp()->is_conc_safe(), "Just checking");
  6618. - assert(scratch_cp()->is_conc_safe(), "Just checking");
  6619. -
  6620. - return JVMTI_ERROR_NONE;
  6621. -} // end merge_cp_and_rewrite()
  6622. -
  6623. -
  6624. -// Rewrite constant pool references in klass scratch_class.
  6625. -bool VM_RedefineClasses::rewrite_cp_refs(instanceKlassHandle scratch_class,
  6626. - TRAPS) {
  6627. -
  6628. - // rewrite constant pool references in the methods:
  6629. - if (!rewrite_cp_refs_in_methods(scratch_class, THREAD)) {
  6630. - // propagate failure back to caller
  6631. - return false;
  6632. - }
  6633. -
  6634. - // rewrite constant pool references in the class_annotations:
  6635. - if (!rewrite_cp_refs_in_class_annotations(scratch_class, THREAD)) {
  6636. - // propagate failure back to caller
  6637. - return false;
  6638. - }
  6639. -
  6640. - // rewrite constant pool references in the fields_annotations:
  6641. - if (!rewrite_cp_refs_in_fields_annotations(scratch_class, THREAD)) {
  6642. - // propagate failure back to caller
  6643. - return false;
  6644. - }
  6645. -
  6646. - // rewrite constant pool references in the methods_annotations:
  6647. - if (!rewrite_cp_refs_in_methods_annotations(scratch_class, THREAD)) {
  6648. - // propagate failure back to caller
  6649. - return false;
  6650. - }
  6651. -
  6652. - // rewrite constant pool references in the methods_parameter_annotations:
  6653. - if (!rewrite_cp_refs_in_methods_parameter_annotations(scratch_class,
  6654. - THREAD)) {
  6655. - // propagate failure back to caller
  6656. - return false;
  6657. - }
  6658. -
  6659. - // rewrite constant pool references in the methods_default_annotations:
  6660. - if (!rewrite_cp_refs_in_methods_default_annotations(scratch_class,
  6661. - THREAD)) {
  6662. - // propagate failure back to caller
  6663. - return false;
  6664. - }
  6665. -
  6666. - return true;
  6667. -} // end rewrite_cp_refs()
  6668. -
  6669. -
  6670. -// Rewrite constant pool references in the methods.
  6671. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods(
  6672. - instanceKlassHandle scratch_class, TRAPS) {
  6673. -
  6674. - objArrayHandle methods(THREAD, scratch_class->methods());
  6675. -
  6676. - if (methods.is_null() || methods->length() == 0) {
  6677. - // no methods so nothing to do
  6678. - return true;
  6679. - }
  6680. -
  6681. - // rewrite constant pool references in the methods:
  6682. - for (int i = methods->length() - 1; i >= 0; i--) {
  6683. - methodHandle method(THREAD, (methodOop)methods->obj_at(i));
  6684. - methodHandle new_method;
  6685. - rewrite_cp_refs_in_method(method, &new_method, CHECK_false);
  6686. - if (!new_method.is_null()) {
  6687. - // the method has been replaced so save the new method version
  6688. - methods->obj_at_put(i, new_method());
  6689. + {
  6690. + u2 new_num = k_new_method->method_idnum();
  6691. + u2 old_num = k_old_method->method_idnum();
  6692. + if (new_num != old_num) {
  6693. + methodOop idnum_owner = new_class->method_with_idnum(old_num);
  6694. + if (idnum_owner != NULL) {
  6695. + // There is already a method assigned this idnum -- switch them
  6696. + idnum_owner->set_method_idnum(new_num);
  6697. + }
  6698. + k_new_method->set_method_idnum(old_num);
  6699. + RC_TRACE(0x00000002, ("swapping idnum of new and old method %d / %d!",
  6700. + new_num,
  6701. + old_num));
  6702. + // swap_all_method_annotations(old_num, new_num, new_class);
  6703. + }
  6704. + }
  6705. + RC_TRACE(0x00008000, ("Method matched: new: %s [%d] == old: %s [%d]",
  6706. + k_new_method->name_and_sig_as_C_string(), ni,
  6707. + k_old_method->name_and_sig_as_C_string(), oi));
  6708. + // advance to next pair of methods
  6709. + ++oi;
  6710. + ++ni;
  6711. + break;
  6712. + case added:
  6713. + // method added, see if it is OK
  6714. + new_flags = (jushort) k_new_method->access_flags().get_flags();
  6715. + if ((new_flags & JVM_ACC_PRIVATE) == 0
  6716. + // hack: private should be treated as final, but alas
  6717. + || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  6718. + ) {
  6719. + // new methods must be private
  6720. + result = result | Klass::ModifyClass;
  6721. + }
  6722. + {
  6723. + u2 num = the_class->next_method_idnum();
  6724. + if (num == constMethodOopDesc::UNSET_IDNUM) {
  6725. + // cannot add any more methods
  6726. + result = result | Klass::ModifyClass;
  6727. + }
  6728. + u2 new_num = k_new_method->method_idnum();
  6729. + methodOop idnum_owner = new_class->method_with_idnum(num);
  6730. + if (idnum_owner != NULL) {
  6731. + // There is already a method assigned this idnum -- switch them
  6732. + idnum_owner->set_method_idnum(new_num);
  6733. + }
  6734. + k_new_method->set_method_idnum(num);
  6735. + //swap_all_method_annotations(new_num, num, new_class);
  6736. + }
  6737. + RC_TRACE(0x00000001, ("Method added: new: %s [%d]",
  6738. + k_new_method->name_and_sig_as_C_string(), ni));
  6739. + ++ni; // advance to next new method
  6740. + break;
  6741. + case deleted:
  6742. + // method deleted, see if it is OK
  6743. + old_flags = (jushort) k_old_method->access_flags().get_flags();
  6744. + if ((old_flags & JVM_ACC_PRIVATE) == 0
  6745. + // hack: private should be treated as final, but alas
  6746. + || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  6747. + ) {
  6748. + // deleted methods must be private
  6749. + result = result | Klass::ModifyClass;
  6750. + }
  6751. + RC_TRACE(0x00000001, ("Method deleted: old: %s [%d]",
  6752. + k_old_method->name_and_sig_as_C_string(), oi));
  6753. + ++oi; // advance to next old method
  6754. + break;
  6755. + default:
  6756. + ShouldNotReachHere();
  6757. }
  6758. }
  6759. - return true;
  6760. + if (new_class()->size() != new_class->old_version()->size()) {
  6761. + result |= Klass::ModifyClassSize;
  6762. + }
  6763. +
  6764. + if (new_class->size_helper() != ((instanceKlass*)(new_class->old_version()->klass_part()))->size_helper()) {
  6765. + result |= Klass::ModifyInstanceSize;
  6766. + }
  6767. +
  6768. + methodHandle instanceTransformerMethod(new_class->find_method(vmSymbols::transformer_name(), vmSymbols::void_method_signature()));
  6769. + if (!instanceTransformerMethod.is_null() && !instanceTransformerMethod->is_static()) {
  6770. + result |= Klass::HasInstanceTransformer;
  6771. + }
  6772. +
  6773. + // (tw) Check method bodies to be able to return NoChange?
  6774. + return result;
  6775. }
  6776. +void VM_RedefineClasses::calculate_instance_update_information(klassOop new_version) {
  6777. -// Rewrite constant pool references in the specific method. This code
  6778. -// was adapted from Rewriter::rewrite_method().
  6779. -void VM_RedefineClasses::rewrite_cp_refs_in_method(methodHandle method,
  6780. - methodHandle *new_method_p, TRAPS) {
  6781. + class UpdateFieldsEvolutionClosure : public FieldEvolutionClosure {
  6782. - *new_method_p = methodHandle(); // default is no new method
  6783. + private:
  6784. - // We cache a pointer to the bytecodes here in code_base. If GC
  6785. - // moves the methodOop, then the bytecodes will also move which
  6786. - // will likely cause a crash. We create a No_Safepoint_Verifier
  6787. - // object to detect whether we pass a possible safepoint in this
  6788. - // code block.
  6789. - No_Safepoint_Verifier nsv;
  6790. + GrowableArray<int> info;
  6791. + int curPosition;
  6792. + bool copy_backwards;
  6793. - // Bytecodes and their length
  6794. - address code_base = method->code_base();
  6795. - int code_length = method->code_size();
  6796. + public:
  6797. - int bc_length;
  6798. - for (int bci = 0; bci < code_length; bci += bc_length) {
  6799. - address bcp = code_base + bci;
  6800. - Bytecodes::Code c = (Bytecodes::Code)(*bcp);
  6801. -
  6802. - bc_length = Bytecodes::length_for(c);
  6803. - if (bc_length == 0) {
  6804. - // More complicated bytecodes report a length of zero so
  6805. - // we have to try again a slightly different way.
  6806. - bc_length = Bytecodes::length_at(method(), bcp);
  6807. + bool does_copy_backwards() {
  6808. + return copy_backwards;
  6809. }
  6810. - assert(bc_length != 0, "impossible bytecode length");
  6811. + UpdateFieldsEvolutionClosure(klassOop klass) {
  6812. - switch (c) {
  6813. - case Bytecodes::_ldc:
  6814. - {
  6815. - int cp_index = *(bcp + 1);
  6816. - int new_index = find_new_index(cp_index);
  6817. + int base_offset = instanceOopDesc::base_offset_in_bytes();
  6818. - if (StressLdcRewrite && new_index == 0) {
  6819. - // If we are stressing ldc -> ldc_w rewriting, then we
  6820. - // always need a new_index value.
  6821. - new_index = cp_index;
  6822. - }
  6823. - if (new_index != 0) {
  6824. - // the original index is mapped so we have more work to do
  6825. - if (!StressLdcRewrite && new_index <= max_jubyte) {
  6826. - // The new value can still use ldc instead of ldc_w
  6827. - // unless we are trying to stress ldc -> ldc_w rewriting
  6828. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  6829. - ("%s@" INTPTR_FORMAT " old=%d, new=%d", Bytecodes::name(c),
  6830. - bcp, cp_index, new_index));
  6831. - *(bcp + 1) = new_index;
  6832. + if (klass->klass_part()->newest_version() == SystemDictionary::Reference_klass()->klass_part()->newest_version()) {
  6833. + base_offset += java_lang_ref_Reference::number_of_fake_oop_fields*size_of_type(T_OBJECT);
  6834. + }
  6835. +
  6836. + info.append(base_offset);
  6837. + info.append(0);
  6838. + curPosition = base_offset;
  6839. + copy_backwards = false;
  6840. + }
  6841. +
  6842. + GrowableArray<int> &finish() {
  6843. + info.append(0);
  6844. + return info;
  6845. + }
  6846. +
  6847. + virtual void do_new_field(fieldDescriptor* fd){
  6848. + int alignment = fd->offset() - curPosition;
  6849. + if (alignment > 0) {
  6850. + // This field was aligned, so we need to make sure that we fill the gap
  6851. + fill(alignment);
  6852. + }
  6853. +
  6854. + int size = size_of_type(fd->field_type());
  6855. + fill(size);
  6856. + }
  6857. +
  6858. + private:
  6859. +
  6860. + void fill(int size) {
  6861. + if (info.length() > 0 && info.at(info.length() - 1) < 0) {
  6862. + (*info.adr_at(info.length() - 1)) -= size;
  6863. + } else {
  6864. + info.append(-size);
  6865. + }
  6866. +
  6867. + curPosition += size;
  6868. + }
  6869. +
  6870. + int size_of_type(BasicType type) {
  6871. + int size = 0;
  6872. + switch(type) {
  6873. + case T_BOOLEAN:
  6874. + size = sizeof(jboolean);
  6875. + break;
  6876. +
  6877. + case T_CHAR:
  6878. + size = (sizeof(jchar));
  6879. + break;
  6880. +
  6881. + case T_FLOAT:
  6882. + size = (sizeof(jfloat));
  6883. + break;
  6884. +
  6885. + case T_DOUBLE:
  6886. + size = (sizeof(jdouble));
  6887. + break;
  6888. +
  6889. + case T_BYTE:
  6890. + size = (sizeof(jbyte));
  6891. + break;
  6892. +
  6893. + case T_SHORT:
  6894. + size = (sizeof(jshort));
  6895. + break;
  6896. +
  6897. + case T_INT:
  6898. + size = (sizeof(jint));
  6899. + break;
  6900. +
  6901. + case T_LONG:
  6902. + size = (sizeof(jlong));
  6903. + break;
  6904. +
  6905. + case T_OBJECT:
  6906. + case T_ARRAY:
  6907. + if (UseCompressedOops) {
  6908. + size = sizeof(narrowOop);
  6909. } else {
  6910. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  6911. - ("%s->ldc_w@" INTPTR_FORMAT " old=%d, new=%d",
  6912. - Bytecodes::name(c), bcp, cp_index, new_index));
  6913. - // the new value needs ldc_w instead of ldc
  6914. - u_char inst_buffer[4]; // max instruction size is 4 bytes
  6915. - bcp = (address)inst_buffer;
  6916. - // construct new instruction sequence
  6917. - *bcp = Bytecodes::_ldc_w;
  6918. - bcp++;
  6919. - // Rewriter::rewrite_method() does not rewrite ldc -> ldc_w.
  6920. - // See comment below for difference between put_Java_u2()
  6921. - // and put_native_u2().
  6922. - Bytes::put_Java_u2(bcp, new_index);
  6923. + size = (sizeof(oop));
  6924. + }
  6925. + break;
  6926. - Relocator rc(method, NULL /* no RelocatorListener needed */);
  6927. - methodHandle m;
  6928. - {
  6929. - Pause_No_Safepoint_Verifier pnsv(&nsv);
  6930. + default:
  6931. + ShouldNotReachHere();
  6932. + }
  6933. - // ldc is 2 bytes and ldc_w is 3 bytes
  6934. - m = rc.insert_space_at(bci, 3, inst_buffer, THREAD);
  6935. - if (m.is_null() || HAS_PENDING_EXCEPTION) {
  6936. - guarantee(false, "insert_space_at() failed");
  6937. + assert(size > 0, "");
  6938. + return size;
  6939. +
  6940. + }
  6941. +
  6942. + public:
  6943. +
  6944. + virtual void do_old_field(fieldDescriptor* fd){}
  6945. +
  6946. + virtual void do_changed_field(fieldDescriptor* old_fd, fieldDescriptor *new_fd){
  6947. +
  6948. + int alignment = new_fd->offset() - curPosition;
  6949. + if (alignment > 0) {
  6950. + // This field was aligned, so we need to make sure that we fill the gap
  6951. + fill(alignment);
  6952. + }
  6953. +
  6954. + assert(old_fd->field_type() == new_fd->field_type(), "");
  6955. + assert(curPosition == new_fd->offset(), "must be correct offset!");
  6956. +
  6957. + int offset = old_fd->offset();
  6958. + int size = size_of_type(old_fd->field_type());
  6959. +
  6960. + int prevEnd = -1;
  6961. + if (info.length() > 0 && info.at(info.length() - 1) > 0) {
  6962. + prevEnd = info.at(info.length() - 2) + info.at(info.length() - 1);
  6963. + }
  6964. +
  6965. + if (prevEnd == offset) {
  6966. + info.at_put(info.length() - 2, info.at(info.length() - 2) + size);
  6967. + } else {
  6968. + info.append(size);
  6969. + info.append(offset);
  6970. + }
  6971. +
  6972. + if (old_fd->offset() < new_fd->offset()) {
  6973. + copy_backwards = true;
  6974. + }
  6975. +
  6976. + transfer_special_access_flags(old_fd, new_fd);
  6977. +
  6978. + curPosition += size;
  6979. + }
  6980. + };
  6981. +
  6982. + UpdateFieldsEvolutionClosure cl(new_version);
  6983. + ((instanceKlass*)new_version->klass_part())->do_fields_evolution(&cl);
  6984. +
  6985. + GrowableArray<int> result = cl.finish();
  6986. + ((instanceKlass*)new_version->klass_part())->store_update_information(result);
  6987. + ((instanceKlass*)new_version->klass_part())->set_copying_backwards(cl.does_copy_backwards());
  6988. +
  6989. + if (RC_TRACE_ENABLED(0x00000002)) {
  6990. + RC_TRACE(0x00000002, ("Instance update information for %s:",
  6991. + new_version->klass_part()->name()->as_C_string()));
  6992. + if (cl.does_copy_backwards()) {
  6993. + RC_TRACE(0x00000002, ("\tDoes copy backwards!"));
  6994. + }
  6995. + for (int i=0; i<result.length(); i++) {
  6996. + int curNum = result.at(i);
  6997. + if (curNum < 0) {
  6998. + RC_TRACE(0x00000002, ("\t%d CLEAN", curNum));
  6999. + } else if (curNum > 0) {
  7000. + RC_TRACE(0x00000002, ("\t%d COPY from %d", curNum, result.at(i + 1)));
  7001. + i++;
  7002. + } else {
  7003. + RC_TRACE(0x00000002, ("\tEND"));
  7004. + }
  7005. + }
  7006. + }
  7007. +}
  7008. +
  7009. +Symbol* VM_RedefineClasses::signature_to_class_name(Symbol* signature) {
  7010. + assert(FieldType::is_obj(signature), "");
  7011. + return SymbolTable::new_symbol(signature->as_C_string() + 1, signature->utf8_length() - 2, Thread::current());
  7012. +}
  7013. +
  7014. +void VM_RedefineClasses::calculate_type_check_information(klassOop klass) {
  7015. + if (klass->klass_part()->is_redefining()) {
  7016. + klass = klass->klass_part()->old_version();
  7017. + }
  7018. +
  7019. + // We found an instance klass!
  7020. + instanceKlass *cur_instance_klass = instanceKlass::cast(klass);
  7021. + GrowableArray< Pair<int, klassOop> > type_check_information;
  7022. +
  7023. + class MyFieldClosure : public FieldClosure {
  7024. +
  7025. + public:
  7026. +
  7027. + GrowableArray< Pair<int, klassOop> > *_arr;
  7028. +
  7029. + MyFieldClosure(GrowableArray< Pair<int, klassOop> > *arr) {
  7030. + _arr = arr;
  7031. + }
  7032. +
  7033. + virtual void do_field(fieldDescriptor* fd) {
  7034. + if (fd->field_type() == T_OBJECT) {
  7035. + Symbol* signature = fd->signature();
  7036. + if (FieldType::is_obj(signature)) {
  7037. + Symbol* name = signature_to_class_name(signature);
  7038. + klassOop field_klass;
  7039. + if (is_field_dangerous(name, fd, field_klass)) {
  7040. + RC_TRACE(0x00000002, ("Found dangerous field %s in klass %s of type %s",
  7041. + fd->name()->as_C_string(),
  7042. + fd->field_holder()->klass_part()->name()->as_C_string(),
  7043. + name->as_C_string()));
  7044. + _arr->append(Pair<int, klassOop>(fd->offset(), field_klass->klass_part()->newest_version()));
  7045. + }
  7046. + }
  7047. +
  7048. + // Array fields can never be a problem!
  7049. + }
  7050. + }
  7051. +
  7052. + bool is_field_dangerous(Symbol* klass_name, fieldDescriptor *fd, klassOop &field_klass) {
  7053. + field_klass = SystemDictionary::find(klass_name, fd->field_holder()->klass_part()->class_loader(),
  7054. + fd->field_holder()->klass_part()->protection_domain(), Thread::current());
  7055. + if(field_klass != NULL) {
  7056. + if (field_klass->klass_part()->is_redefining()) {
  7057. + field_klass = field_klass->klass_part()->old_version();
  7058. + }
  7059. + if (field_klass->klass_part()->has_subtype_changed()) {
  7060. + return true;
  7061. + }
  7062. + }
  7063. + return false;
  7064. + }
  7065. + };
  7066. +
  7067. + MyFieldClosure fieldClosure(&type_check_information);
  7068. + cur_instance_klass->do_nonstatic_fields(&fieldClosure);
  7069. +
  7070. + if (type_check_information.length() > 0) {
  7071. + type_check_information.append(Pair<int, klassOop>(-1, NULL));
  7072. + cur_instance_klass->store_type_check_information(type_check_information);
  7073. + }
  7074. +}
  7075. +
  7076. +bool VM_RedefineClasses::check_field_value_types() {
  7077. +
  7078. + Thread *THREAD = Thread::current();
  7079. + class CheckFieldTypesClosure : public ObjectClosure {
  7080. +
  7081. + private:
  7082. +
  7083. + bool _result;
  7084. +
  7085. + public:
  7086. +
  7087. + CheckFieldTypesClosure() {
  7088. + _result = true;
  7089. + }
  7090. +
  7091. + bool result() { return _result; }
  7092. +
  7093. + virtual void do_object(oop obj) {
  7094. +
  7095. + if (!_result) {
  7096. + return;
  7097. + }
  7098. +
  7099. + if (obj->is_objArray()) {
  7100. +
  7101. + objArrayOop array = objArrayOop(obj);
  7102. +
  7103. + klassOop element_klass = objArrayKlass::cast(array->klass())->element_klass();
  7104. +
  7105. + if (element_klass->klass_part()->has_subtype_changed()) {
  7106. + int length = array->length();
  7107. + for (int i=0; i<length; i++) {
  7108. + oop element = array->obj_at(i);
  7109. + if (element != NULL && element->blueprint()->newest_version()->klass_part()->is_redefining()) {
  7110. + // Check subtype relationship to static type of array
  7111. + if (!element->blueprint()->newest_version()->klass_part()->is_subtype_of(element_klass->klass_part()->newest_version())) {
  7112. + RC_TRACE(0x00000001, ("Array value is INVALID - abort redefinition (static_type=%s, index=%d, dynamic_type=%s)",
  7113. + element_klass->klass_part()->name()->as_C_string(),
  7114. + i,
  7115. + element->blueprint()->name()->as_C_string()));
  7116. + _result = false;
  7117. + break;
  7118. }
  7119. }
  7120. -
  7121. - // return the new method so that the caller can update
  7122. - // the containing class
  7123. - *new_method_p = method = m;
  7124. - // switch our bytecode processing loop from the old method
  7125. - // to the new method
  7126. - code_base = method->code_base();
  7127. - code_length = method->code_size();
  7128. - bcp = code_base + bci;
  7129. - c = (Bytecodes::Code)(*bcp);
  7130. - bc_length = Bytecodes::length_for(c);
  7131. - assert(bc_length != 0, "sanity check");
  7132. - } // end we need ldc_w instead of ldc
  7133. - } // end if there is a mapped index
  7134. - } break;
  7135. -
  7136. - // these bytecodes have a two-byte constant pool index
  7137. - case Bytecodes::_anewarray : // fall through
  7138. - case Bytecodes::_checkcast : // fall through
  7139. - case Bytecodes::_getfield : // fall through
  7140. - case Bytecodes::_getstatic : // fall through
  7141. - case Bytecodes::_instanceof : // fall through
  7142. - case Bytecodes::_invokedynamic : // fall through
  7143. - case Bytecodes::_invokeinterface: // fall through
  7144. - case Bytecodes::_invokespecial : // fall through
  7145. - case Bytecodes::_invokestatic : // fall through
  7146. - case Bytecodes::_invokevirtual : // fall through
  7147. - case Bytecodes::_ldc_w : // fall through
  7148. - case Bytecodes::_ldc2_w : // fall through
  7149. - case Bytecodes::_multianewarray : // fall through
  7150. - case Bytecodes::_new : // fall through
  7151. - case Bytecodes::_putfield : // fall through
  7152. - case Bytecodes::_putstatic :
  7153. - {
  7154. - address p = bcp + 1;
  7155. - int cp_index = Bytes::get_Java_u2(p);
  7156. - int new_index = find_new_index(cp_index);
  7157. - if (new_index != 0) {
  7158. - // the original index is mapped so update w/ new value
  7159. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7160. - ("%s@" INTPTR_FORMAT " old=%d, new=%d", Bytecodes::name(c),
  7161. - bcp, cp_index, new_index));
  7162. - // Rewriter::rewrite_method() uses put_native_u2() in this
  7163. - // situation because it is reusing the constant pool index
  7164. - // location for a native index into the constantPoolCache.
  7165. - // Since we are updating the constant pool index prior to
  7166. - // verification and constantPoolCache initialization, we
  7167. - // need to keep the new index in Java byte order.
  7168. - Bytes::put_Java_u2(p, new_index);
  7169. + }
  7170. }
  7171. - } break;
  7172. +
  7173. + } else {
  7174. + Pair<int, klassOop> *cur = obj->klass()->klass_part()->type_check_information();
  7175. + if (cur != NULL) {
  7176. + // Type check information exists for this oop
  7177. + while ((*cur).left() != -1) {
  7178. + check_field(obj, (*cur).left(), (*cur).right());
  7179. + cur++;
  7180. + }
  7181. + }
  7182. + }
  7183. }
  7184. - } // end for each bytecode
  7185. -} // end rewrite_cp_refs_in_method()
  7186. + void check_field(oop obj, int offset, klassOop static_type) {
  7187. + oop field_value = obj->obj_field(offset);
  7188. + if (field_value != NULL) {
  7189. + // Field is not null
  7190. + if (field_value->klass()->klass_part()->newest_version()->klass_part()->is_subtype_of(static_type)) {
  7191. + // We are OK
  7192. + RC_TRACE(0x00008000, ("Field value is OK (klass=%s, static_type=%s, offset=%d, dynamic_type=%s)",
  7193. + obj->klass()->klass_part()->name()->as_C_string(),
  7194. + static_type->klass_part()->name()->as_C_string(),
  7195. + offset,
  7196. + field_value->klass()->klass_part()->name()->as_C_string()));
  7197. + } else {
  7198. + // Failure!
  7199. + RC_TRACE(0x00000001, ("Field value is INVALID - abort redefinition (klass=%s, static_type=%s, offset=%d, dynamic_type=%s)",
  7200. + obj->klass()->klass_part()->name()->as_C_string(),
  7201. + static_type->klass_part()->name()->as_C_string(),
  7202. + offset,
  7203. + field_value->klass()->klass_part()->name()->as_C_string()));
  7204. + _result = false;
  7205. + }
  7206. + }
  7207. + }
  7208. + };
  7209. -// Rewrite constant pool references in the class_annotations field.
  7210. -bool VM_RedefineClasses::rewrite_cp_refs_in_class_annotations(
  7211. - instanceKlassHandle scratch_class, TRAPS) {
  7212. + CheckFieldTypesClosure myObjectClosure;
  7213. - typeArrayHandle class_annotations(THREAD,
  7214. - scratch_class->class_annotations());
  7215. - if (class_annotations.is_null() || class_annotations->length() == 0) {
  7216. - // no class_annotations so nothing to do
  7217. - return true;
  7218. + // make sure that heap is parsable (fills TLABs with filler objects)
  7219. + Universe::heap()->ensure_parsability(false); // no need to retire TLABs
  7220. +
  7221. + // do the iteration
  7222. + // If this operation encounters a bad object when using CMS,
  7223. + // consider using safe_object_iterate() which avoids perm gen
  7224. + // objects that may contain bad references.
  7225. + Universe::heap()->object_iterate(&myObjectClosure);
  7226. +
  7227. + // when sharing is enabled we must iterate over the shared spaces
  7228. + if (UseSharedSpaces) {
  7229. + GenCollectedHeap* gch = GenCollectedHeap::heap();
  7230. + CompactingPermGenGen* gen = (CompactingPermGenGen*)gch->perm_gen();
  7231. + gen->ro_space()->object_iterate(&myObjectClosure);
  7232. + gen->rw_space()->object_iterate(&myObjectClosure);
  7233. }
  7234. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7235. - ("class_annotations length=%d", class_annotations->length()));
  7236. -
  7237. - int byte_i = 0; // byte index into class_annotations
  7238. - return rewrite_cp_refs_in_annotations_typeArray(class_annotations, byte_i,
  7239. - THREAD);
  7240. + return myObjectClosure.result();
  7241. }
  7242. -
  7243. -// Rewrite constant pool references in an annotations typeArray. This
  7244. -// "structure" is adapted from the RuntimeVisibleAnnotations_attribute
  7245. -// that is described in section 4.8.15 of the 2nd-edition of the VM spec:
  7246. -//
  7247. -// annotations_typeArray {
  7248. -// u2 num_annotations;
  7249. -// annotation annotations[num_annotations];
  7250. -// }
  7251. -//
  7252. -bool VM_RedefineClasses::rewrite_cp_refs_in_annotations_typeArray(
  7253. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  7254. -
  7255. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  7256. - // not enough room for num_annotations field
  7257. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7258. - ("length() is too small for num_annotations field"));
  7259. - return false;
  7260. +void VM_RedefineClasses::clear_type_check_information(klassOop k) {
  7261. + if (k->klass_part()->is_redefining()) {
  7262. + k = k->klass_part()->old_version();
  7263. }
  7264. - u2 num_annotations = Bytes::get_Java_u2((address)
  7265. - annotations_typeArray->byte_at_addr(byte_i_ref));
  7266. - byte_i_ref += 2;
  7267. -
  7268. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7269. - ("num_annotations=%d", num_annotations));
  7270. -
  7271. - int calc_num_annotations = 0;
  7272. - for (; calc_num_annotations < num_annotations; calc_num_annotations++) {
  7273. - if (!rewrite_cp_refs_in_annotation_struct(annotations_typeArray,
  7274. - byte_i_ref, THREAD)) {
  7275. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7276. - ("bad annotation_struct at %d", calc_num_annotations));
  7277. - // propagate failure back to caller
  7278. - return false;
  7279. - }
  7280. - }
  7281. - assert(num_annotations == calc_num_annotations, "sanity check");
  7282. -
  7283. - return true;
  7284. -} // end rewrite_cp_refs_in_annotations_typeArray()
  7285. -
  7286. -
  7287. -// Rewrite constant pool references in the annotation struct portion of
  7288. -// an annotations_typeArray. This "structure" is from section 4.8.15 of
  7289. -// the 2nd-edition of the VM spec:
  7290. -//
  7291. -// struct annotation {
  7292. -// u2 type_index;
  7293. -// u2 num_element_value_pairs;
  7294. -// {
  7295. -// u2 element_name_index;
  7296. -// element_value value;
  7297. -// } element_value_pairs[num_element_value_pairs];
  7298. -// }
  7299. -//
  7300. -bool VM_RedefineClasses::rewrite_cp_refs_in_annotation_struct(
  7301. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  7302. - if ((byte_i_ref + 2 + 2) > annotations_typeArray->length()) {
  7303. - // not enough room for smallest annotation_struct
  7304. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7305. - ("length() is too small for annotation_struct"));
  7306. - return false;
  7307. - }
  7308. -
  7309. - u2 type_index = rewrite_cp_ref_in_annotation_data(annotations_typeArray,
  7310. - byte_i_ref, "mapped old type_index=%d", THREAD);
  7311. -
  7312. - u2 num_element_value_pairs = Bytes::get_Java_u2((address)
  7313. - annotations_typeArray->byte_at_addr(
  7314. - byte_i_ref));
  7315. - byte_i_ref += 2;
  7316. -
  7317. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7318. - ("type_index=%d num_element_value_pairs=%d", type_index,
  7319. - num_element_value_pairs));
  7320. -
  7321. - int calc_num_element_value_pairs = 0;
  7322. - for (; calc_num_element_value_pairs < num_element_value_pairs;
  7323. - calc_num_element_value_pairs++) {
  7324. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  7325. - // not enough room for another element_name_index, let alone
  7326. - // the rest of another component
  7327. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7328. - ("length() is too small for element_name_index"));
  7329. - return false;
  7330. - }
  7331. -
  7332. - u2 element_name_index = rewrite_cp_ref_in_annotation_data(
  7333. - annotations_typeArray, byte_i_ref,
  7334. - "mapped old element_name_index=%d", THREAD);
  7335. -
  7336. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7337. - ("element_name_index=%d", element_name_index));
  7338. -
  7339. - if (!rewrite_cp_refs_in_element_value(annotations_typeArray,
  7340. - byte_i_ref, THREAD)) {
  7341. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7342. - ("bad element_value at %d", calc_num_element_value_pairs));
  7343. - // propagate failure back to caller
  7344. - return false;
  7345. - }
  7346. - } // end for each component
  7347. - assert(num_element_value_pairs == calc_num_element_value_pairs,
  7348. - "sanity check");
  7349. -
  7350. - return true;
  7351. -} // end rewrite_cp_refs_in_annotation_struct()
  7352. -
  7353. -
  7354. -// Rewrite a constant pool reference at the current position in
  7355. -// annotations_typeArray if needed. Returns the original constant
  7356. -// pool reference if a rewrite was not needed or the new constant
  7357. -// pool reference if a rewrite was needed.
  7358. -u2 VM_RedefineClasses::rewrite_cp_ref_in_annotation_data(
  7359. - typeArrayHandle annotations_typeArray, int &byte_i_ref,
  7360. - const char * trace_mesg, TRAPS) {
  7361. -
  7362. - address cp_index_addr = (address)
  7363. - annotations_typeArray->byte_at_addr(byte_i_ref);
  7364. - u2 old_cp_index = Bytes::get_Java_u2(cp_index_addr);
  7365. - u2 new_cp_index = find_new_index(old_cp_index);
  7366. - if (new_cp_index != 0) {
  7367. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, (trace_mesg, old_cp_index));
  7368. - Bytes::put_Java_u2(cp_index_addr, new_cp_index);
  7369. - old_cp_index = new_cp_index;
  7370. - }
  7371. - byte_i_ref += 2;
  7372. - return old_cp_index;
  7373. + // We found an instance klass!
  7374. + instanceKlass *cur_instance_klass = instanceKlass::cast(k);
  7375. + cur_instance_klass->clear_type_check_information();
  7376. }
  7377. +void VM_RedefineClasses::update_active_methods() {
  7378. -// Rewrite constant pool references in the element_value portion of an
  7379. -// annotations_typeArray. This "structure" is from section 4.8.15.1 of
  7380. -// the 2nd-edition of the VM spec:
  7381. -//
  7382. -// struct element_value {
  7383. -// u1 tag;
  7384. -// union {
  7385. -// u2 const_value_index;
  7386. -// {
  7387. -// u2 type_name_index;
  7388. -// u2 const_name_index;
  7389. -// } enum_const_value;
  7390. -// u2 class_info_index;
  7391. -// annotation annotation_value;
  7392. -// struct {
  7393. -// u2 num_values;
  7394. -// element_value values[num_values];
  7395. -// } array_value;
  7396. -// } value;
  7397. -// }
  7398. -//
  7399. -bool VM_RedefineClasses::rewrite_cp_refs_in_element_value(
  7400. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  7401. + RC_TRACE(0x00000002, ("Updating active methods"));
  7402. + JavaThread *java_thread = Threads::first();
  7403. + while (java_thread != NULL) {
  7404. - if ((byte_i_ref + 1) > annotations_typeArray->length()) {
  7405. - // not enough room for a tag let alone the rest of an element_value
  7406. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7407. - ("length() is too small for a tag"));
  7408. + int stack_depth = 0;
  7409. + if (java_thread->has_last_Java_frame()) {
  7410. +
  7411. + RC_TRACE(0x0000000400, ("checking stack of Java thread %s", java_thread->name()));
  7412. +
  7413. + // vframes are resource allocated
  7414. + Thread* current_thread = Thread::current();
  7415. + ResourceMark rm(current_thread);
  7416. + HandleMark hm(current_thread);
  7417. +
  7418. + RegisterMap reg_map(java_thread);
  7419. + frame f = java_thread->last_frame();
  7420. + vframe* vf = vframe::new_vframe(&f, &reg_map, java_thread);
  7421. + frame* last_entry_frame = NULL;
  7422. +
  7423. + while (vf != NULL) {
  7424. + if (vf->is_java_frame()) {
  7425. + // java frame (interpreted, compiled, ...)
  7426. + javaVFrame *jvf = javaVFrame::cast(vf);
  7427. +
  7428. + if (!(jvf->method()->is_native())) {
  7429. + int bci = jvf->bci();
  7430. + RC_TRACE(0x00000400, ("found method: %s / bci=%d", jvf->method()->name()->as_C_string(), bci));
  7431. + ResourceMark rm(Thread::current());
  7432. + HandleMark hm;
  7433. + instanceKlassHandle klass(jvf->method()->method_holder());
  7434. +
  7435. + if (jvf->method()->new_version() != NULL && jvf->is_interpreted_frame()) {
  7436. +
  7437. +
  7438. + RC_TRACE(0x00000002, ("Found method that should just be updated to the newest version %s",
  7439. + jvf->method()->name_and_sig_as_C_string()));
  7440. +
  7441. + if (RC_TRACE_ENABLED(0x01000000)) {
  7442. + int code_size = jvf->method()->code_size();
  7443. + char *code_base_old = (char*)jvf->method()->code_base();
  7444. + char *code_base_new = (char*)jvf->method()->new_version()->code_base();
  7445. + for (int i=0; i<code_size; i++) {
  7446. + tty->print_cr("old=%d new=%d", *code_base_old++, *code_base_new++);
  7447. + }
  7448. + jvf->method()->print_codes_on(tty);
  7449. + jvf->method()->new_version()->print_codes_on(tty);
  7450. + }
  7451. +
  7452. + assert(jvf->is_interpreted_frame(), "Every frame must be interpreted!");
  7453. + interpretedVFrame *iframe = (interpretedVFrame *)jvf;
  7454. +
  7455. +
  7456. + if (RC_TRACE_ENABLED(0x01000000)) {
  7457. + constantPoolCacheOop cp_old = jvf->method()->constants()->cache();
  7458. + tty->print_cr("old cp");
  7459. + for (int i=0; i<cp_old->length(); i++) {
  7460. + cp_old->entry_at(i)->print(tty, i);
  7461. + }
  7462. + constantPoolCacheOop cp_new = jvf->method()->new_version()->constants()->cache();
  7463. + tty->print_cr("new cp");
  7464. + for (int i=0; i<cp_new->length(); i++) {
  7465. + cp_new->entry_at(i)->print(tty, i);
  7466. + }
  7467. + }
  7468. +
  7469. + iframe->set_method(jvf->method()->new_version(), bci);
  7470. + RC_TRACE(0x00000002, ("Updated method to newer version"));
  7471. + assert(jvf->method()->new_version() == NULL, "must be latest version");
  7472. +
  7473. + }
  7474. + }
  7475. + }
  7476. + vf = vf->sender();
  7477. + }
  7478. + }
  7479. +
  7480. + // Advance to next thread
  7481. + java_thread = java_thread->next();
  7482. + }
  7483. +}
  7484. +
  7485. +void VM_RedefineClasses::method_forwarding() {
  7486. +
  7487. + int forwarding_count = 0;
  7488. + JavaThread *java_thread = Threads::first();
  7489. + while (java_thread != NULL) {
  7490. +
  7491. + int stack_depth = 0;
  7492. + if (java_thread->has_last_Java_frame()) {
  7493. +
  7494. + RC_TRACE(0x00000400, ("checking stack of Java thread %s", java_thread->name()));
  7495. +
  7496. + // vframes are resource allocated
  7497. + Thread* current_thread = Thread::current();
  7498. + ResourceMark rm(current_thread);
  7499. + HandleMark hm(current_thread);
  7500. +
  7501. + RegisterMap reg_map(java_thread);
  7502. + frame f = java_thread->last_frame();
  7503. + vframe* vf = vframe::new_vframe(&f, &reg_map, java_thread);
  7504. + frame* last_entry_frame = NULL;
  7505. +
  7506. + while (vf != NULL) {
  7507. + if (vf->is_java_frame()) {
  7508. + // java frame (interpreted, compiled, ...)
  7509. + javaVFrame *jvf = javaVFrame::cast(vf);
  7510. +
  7511. + if (!(jvf->method()->is_native())) {
  7512. + RC_TRACE(0x00008000, ("found method: %s",
  7513. + jvf->method()->name()->as_C_string()));
  7514. + ResourceMark rm(Thread::current());
  7515. + HandleMark hm;
  7516. + instanceKlassHandle klass(jvf->method()->method_holder());
  7517. + methodOop m = jvf->method();
  7518. + int bci = jvf->bci();
  7519. + RC_TRACE(0x00008000, ("klass redef %d",
  7520. + klass->is_redefining()));
  7521. +
  7522. + if (klass->new_version() != NULL && m->new_version() == NULL) {
  7523. + RC_TRACE(0x00008000, ("found potential forwarding method: %s",
  7524. + m->name()->as_C_string()));
  7525. +
  7526. + klassOop new_klass = klass->newest_version();
  7527. + methodOop new_method = new_klass->klass_part()->lookup_method(m->name(), m->signature());
  7528. + RC_TRACE(0x00000002, ("%d %d",
  7529. + new_method,
  7530. + new_method->constMethod()->has_code_section_table()));
  7531. +
  7532. + if (new_method != NULL && new_method->constMethod()->has_code_section_table()) {
  7533. + RC_TRACE(0x00008000, ("found code section table for method: %s",
  7534. + new_method->name()->as_C_string()));
  7535. + m->set_forward_method(new_method);
  7536. + if (new_method->max_locals() != m->max_locals()) {
  7537. + tty->print_cr("new_m max locals: %d old_m max locals: %d", new_method->max_locals(), m->max_locals());
  7538. + }
  7539. + assert(new_method->max_locals() == m->max_locals(), "number of locals must match");
  7540. + assert(new_method->max_stack() == m->max_stack(), "number of stack values must match");
  7541. + if (jvf->is_interpreted_frame()) {
  7542. + if (m->is_in_code_section(bci)) {
  7543. + // We must transfer now and cannot delay until next NOP.
  7544. + int new_bci = m->calculate_forward_bci(bci, new_method);
  7545. + interpretedVFrame* iframe = interpretedVFrame::cast(jvf);
  7546. + RC_TRACE(0x00000002, ("Transferring execution of %s to new method old_bci=%d new_bci=%d",
  7547. + new_method->name()->as_C_string(),
  7548. + bci,
  7549. + new_bci));
  7550. + iframe->set_method(new_method, new_bci);
  7551. + } else {
  7552. + RC_TRACE(0x00000002, ("Delaying method forwarding of %s because %d is not in a code section",
  7553. + new_method->name()->as_C_string(),
  7554. + bci));
  7555. + }
  7556. + } else {
  7557. + RC_TRACE(0x00000002, ("Delaying method forwarding of %s because method is compiled",
  7558. + new_method->name()->as_C_string()));
  7559. + }
  7560. + }
  7561. + }
  7562. + }
  7563. + }
  7564. + vf = vf->sender();
  7565. + }
  7566. + }
  7567. +
  7568. + // Advance to next thread
  7569. + java_thread = java_thread->next();
  7570. + }
  7571. +
  7572. + RC_TRACE(0x00000001, ("Method forwarding applied to %d methods",
  7573. + forwarding_count));
  7574. +}
  7575. +
  7576. +bool VM_RedefineClasses::check_method_stacks() {
  7577. +
  7578. + JavaThread *java_thread = Threads::first();
  7579. + while (java_thread != NULL) {
  7580. +
  7581. + int stack_depth = 0;
  7582. + if (java_thread->has_last_Java_frame()) {
  7583. +
  7584. + RC_TRACE(0x00000400, ("checking stack of Java thread %s", java_thread->name()));
  7585. +
  7586. + // vframes are resource allocated
  7587. + Thread* current_thread = Thread::current();
  7588. + ResourceMark rm(current_thread);
  7589. + HandleMark hm(current_thread);
  7590. +
  7591. + RegisterMap reg_map(java_thread);
  7592. + frame f = java_thread->last_frame();
  7593. + vframe* vf = vframe::new_vframe(&f, &reg_map, java_thread);
  7594. + frame* last_entry_frame = NULL;
  7595. +
  7596. + while (vf != NULL) {
  7597. + if (vf->is_java_frame()) {
  7598. + // java frame (interpreted, compiled, ...)
  7599. + javaVFrame *jvf = javaVFrame::cast(vf);
  7600. +
  7601. + if (!(jvf->method()->is_native())) {
  7602. + RC_TRACE(0x00000400, ("found method: %s", jvf->method()->name()->as_C_string()));
  7603. + ResourceMark rm(Thread::current());
  7604. + HandleMark hm;
  7605. + instanceKlassHandle klass(jvf->method()->method_holder());
  7606. +
  7607. + StackValueCollection *locals = jvf->locals();
  7608. + const size_t message_buffer_len = klass->name()->utf8_length() + 1024;
  7609. + char* message_buffer = NEW_RESOURCE_ARRAY(char, message_buffer_len);
  7610. +
  7611. + for (int i=0; i<locals->size(); i++) {
  7612. + StackValue *stack_value = locals->at(i);
  7613. + if (stack_value->type() == T_OBJECT) {
  7614. + Handle obj = stack_value->get_obj();
  7615. + if (!obj.is_null() && obj->klass()->klass_part()->newest_version()->klass_part()->check_redefinition_flag(Klass::RemoveSuperType)) {
  7616. +
  7617. + // OK, so this is a possible failure => check local variable table, if it could be OK.
  7618. + bool result = false;
  7619. + methodOop method = jvf->method();
  7620. + if (method->has_localvariable_table()) {
  7621. + LocalVariableTableElement *elem = jvf->method()->localvariable_table_start();
  7622. + for (int j=0; j<method->localvariable_table_length(); j++) {
  7623. +
  7624. + if (elem->slot == i) {
  7625. +
  7626. + // Matching index found
  7627. +
  7628. + if (elem->start_bci <= jvf->bci() && elem->start_bci + elem->length > jvf->bci()) {
  7629. +
  7630. + // Also in range!!
  7631. + Symbol* signature = jvf->method()->constants()->symbol_at(elem->descriptor_cp_index);
  7632. + Symbol* klass_name = signature_to_class_name(signature);
  7633. +
  7634. + 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();
  7635. + klassOop cur = obj->klass()->klass_part()->newest_version();
  7636. +
  7637. + // Field is not null
  7638. + if (cur->klass_part()->newest_version()->klass_part()->is_subtype_of(local_klass)) {
  7639. + // We are OK
  7640. + RC_TRACE(0x00008000, ("Local variable value is OK (local_klass=%s, cur_klass=%s)",
  7641. + local_klass->klass_part()->name()->as_C_string(), cur->klass_part()->name()->as_C_string()));
  7642. + result = true;
  7643. + } else {
  7644. + // Failure!
  7645. + RC_TRACE(0x00000001, ("Local variable value is INVALID - abort redefinition (local_klass=%s, cur_klass=%s)",
  7646. + local_klass->klass_part()->name()->as_C_string(),
  7647. + cur->klass_part()->name()->as_C_string()));
  7648. + return false;
  7649. + }
  7650. + }
  7651. + }
  7652. +
  7653. + elem++;
  7654. + }
  7655. + } else {
  7656. + RC_TRACE(0x00000002, ("Method %s does not have a local variable table => abort",
  7657. + method->name_and_sig_as_C_string()));
  7658. + }
  7659. +
  7660. + if (!result) {
  7661. + return false;
  7662. + }
  7663. +
  7664. + RC_TRACE(0x00008000, ("Verifying class %s",
  7665. + jvf->method()->method_holder()->klass_part()->name()->as_C_string()));
  7666. +
  7667. + Symbol* exception_name;
  7668. + const size_t message_buffer_len = klass->name()->utf8_length() + 1024;
  7669. + char* message_buffer = NEW_RESOURCE_ARRAY(char, message_buffer_len);
  7670. +
  7671. + Thread::current()->set_pretend_new_universe(true);
  7672. + ClassVerifier split_verifier(klass, Thread::current());
  7673. + split_verifier.verify_method(jvf->method(), Thread::current());
  7674. + exception_name = split_verifier.result();
  7675. + Thread::current()->set_pretend_new_universe(false);
  7676. +
  7677. + if (exception_name != NULL) {
  7678. +
  7679. + RC_TRACE(0x00000001, ("Verification of class %s failed",
  7680. + jvf->method()->method_holder()->klass_part()->name()->as_C_string()));
  7681. + RC_TRACE(0x00000001, ("Exception: %s",
  7682. + exception_name->as_C_string()));
  7683. + RC_TRACE(0x00000001, ("Message: %s",
  7684. + message_buffer));
  7685. + Thread::current()->clear_pending_exception();
  7686. + return false;
  7687. + }
  7688. +
  7689. + }
  7690. + }
  7691. + }
  7692. + }
  7693. + }
  7694. + vf = vf->sender();
  7695. + }
  7696. + }
  7697. +
  7698. + // Advance to next thread
  7699. + java_thread = java_thread->next();
  7700. + }
  7701. +
  7702. + return true;
  7703. +}
  7704. +
  7705. +bool VM_RedefineClasses::check_method(methodOop method) {
  7706. +
  7707. +
  7708. + return true;
  7709. +}
  7710. +
  7711. +// Warning: destroys redefinition level values of klasses.
  7712. +bool VM_RedefineClasses::check_loaded_methods() {
  7713. +
  7714. + class CheckLoadedMethodsClosure : public ObjectClosure {
  7715. +
  7716. + private:
  7717. +
  7718. + bool _result;
  7719. + GrowableArray<klassOop> *_dangerous_klasses;
  7720. +
  7721. + public:
  7722. + CheckLoadedMethodsClosure(GrowableArray<klassOop> *dangerous_klasses) {
  7723. + _result = true;
  7724. + _dangerous_klasses = dangerous_klasses;
  7725. + }
  7726. +
  7727. + bool result() {
  7728. + return _result;
  7729. + }
  7730. +
  7731. + bool is_class_dangerous(klassOop k) {
  7732. + return k->klass_part()->newest_version()->klass_part()->check_redefinition_flag(Klass::RemoveSuperType);
  7733. + }
  7734. +
  7735. + bool can_be_affected(instanceKlass *klass) {
  7736. +
  7737. + constantPoolOop cp = klass->constants();
  7738. +
  7739. + Thread *THREAD = Thread::current();
  7740. + klassOop k;
  7741. + Symbol* symbol;
  7742. +
  7743. + for (int i=1; i<cp->length(); i++) {
  7744. + jbyte tag = cp->tag_at(i).value();
  7745. + switch(tag) {
  7746. + case JVM_CONSTANT_Long:
  7747. + case JVM_CONSTANT_Double:
  7748. + i++;
  7749. + break;
  7750. +
  7751. + case JVM_CONSTANT_Utf8:
  7752. + case JVM_CONSTANT_Unicode:
  7753. + case JVM_CONSTANT_Integer:
  7754. + case JVM_CONSTANT_Float:
  7755. + case JVM_CONSTANT_String:
  7756. + case JVM_CONSTANT_Fieldref:
  7757. + case JVM_CONSTANT_Methodref:
  7758. + case JVM_CONSTANT_InterfaceMethodref:
  7759. + case JVM_CONSTANT_ClassIndex:
  7760. + case JVM_CONSTANT_UnresolvedString:
  7761. + case JVM_CONSTANT_StringIndex:
  7762. + case JVM_CONSTANT_UnresolvedClassInError:
  7763. + case JVM_CONSTANT_Object:
  7764. + // do nothing
  7765. + break;
  7766. +
  7767. + case JVM_CONSTANT_Class:
  7768. + k = cp->klass_at(i, CHECK_(true));
  7769. + if (is_class_dangerous(k)) {
  7770. + RC_TRACE(0x00000002, ("Class %s is potentially affected, because at cp[%d] references class %s",
  7771. + klass->name()->as_C_string(),
  7772. + i,
  7773. + k->klass_part()->name()->as_C_string()));
  7774. + return true;
  7775. + }
  7776. + break;
  7777. +
  7778. + case JVM_CONSTANT_NameAndType:
  7779. + symbol = cp->symbol_at(cp->signature_ref_index_at(i));
  7780. + if (symbol->byte_at(0) == '(') {
  7781. + // This must be a method
  7782. + SignatureStream signatureStream(symbol);
  7783. + while (true) {
  7784. +
  7785. + if (signatureStream.is_array()) {
  7786. + Symbol* cur_signature = signatureStream.as_symbol(Thread::current());
  7787. + if (is_type_signature_dangerous(cur_signature)) {
  7788. + return true;
  7789. + }
  7790. + } else if (signatureStream.is_object()) {
  7791. + if (is_symbol_dangerous(signatureStream.as_symbol(Thread::current()))) {
  7792. + return true;
  7793. + }
  7794. + }
  7795. +
  7796. + if (signatureStream.at_return_type()) {
  7797. + break;
  7798. + }
  7799. +
  7800. + signatureStream.next();
  7801. + }
  7802. +
  7803. + } else if (is_type_signature_dangerous(symbol)) {
  7804. + return true;
  7805. + }
  7806. + break;
  7807. +
  7808. + case JVM_CONSTANT_UnresolvedClass:
  7809. + symbol = cp->unresolved_klass_at(i);
  7810. + if (is_symbol_dangerous(symbol)) {
  7811. + return true;
  7812. + }
  7813. + break;
  7814. +
  7815. + default:
  7816. + ShouldNotReachHere();
  7817. + }
  7818. + }
  7819. +
  7820. + return false;
  7821. + }
  7822. +
  7823. + bool is_type_signature_dangerous(Symbol* signature) {
  7824. + // This must be a field type
  7825. + if (FieldType::is_obj(signature)) {
  7826. + Symbol* name = signature_to_class_name(signature);
  7827. + if (is_symbol_dangerous(name)) {
  7828. + return true;
  7829. + }
  7830. + } else if (FieldType::is_array(signature)) {
  7831. + //jint dimension;
  7832. + //Symbol* object_key;
  7833. + FieldArrayInfo fd;
  7834. + FieldType::get_array_info(signature, fd, Thread::current());
  7835. + if (is_symbol_dangerous(fd.object_key())) {
  7836. + return true;
  7837. + }
  7838. + }
  7839. + return false;
  7840. + }
  7841. +
  7842. + bool is_symbol_dangerous(Symbol* symbol) {
  7843. + for (int i=0; i<_dangerous_klasses->length(); i++) {
  7844. + if(_dangerous_klasses->at(i)->klass_part()->name() == symbol) {
  7845. + RC_TRACE(0x00000002, ("Found constant pool index %d references class %s",
  7846. + i,
  7847. + symbol->as_C_string()));
  7848. + return true;
  7849. + }
  7850. + }
  7851. + return false;
  7852. + }
  7853. +
  7854. + virtual void do_object(oop obj) {
  7855. +
  7856. + if (!_result) return;
  7857. +
  7858. + klassOop klassObj = (klassOop)obj;
  7859. + Thread *THREAD = Thread::current();
  7860. +
  7861. + // We found an instance klass!
  7862. + instanceKlass *klass = instanceKlass::cast(klassObj);
  7863. + instanceKlassHandle handle(klassObj);
  7864. +
  7865. + RC_TRACE(0x00000400, ("Check if verification is necessary for class %s major_version=%d", handle->name()->as_C_string(), handle->major_version()));
  7866. +
  7867. + if (!can_be_affected(klass)) {
  7868. + RC_TRACE(0x00000400, ("Skipping verification of class %s major_version=%d", handle->name()->as_C_string(), handle->major_version()));
  7869. + return;
  7870. + }
  7871. +
  7872. + if (handle->major_version() < Verifier::STACKMAP_ATTRIBUTE_MAJOR_VERSION) {
  7873. + RC_TRACE(0x00000001, ("Failing because cannot verify class %s major_version=%d", handle->name()->as_C_string(), handle->major_version()));
  7874. + _result = false;
  7875. + return;
  7876. + }
  7877. +
  7878. + RC_TRACE(0x00000001, ("Verifying class %s", handle->name()->as_C_string()));
  7879. +
  7880. + if (!Verifier::verify(handle, Verifier::NoException, true, false, Thread::current())) {
  7881. +
  7882. + RC_TRACE(0x00000001, ("Verification of class %s failed", handle->name()->as_C_string()));
  7883. + //Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  7884. + //RC_TRACE(0x00000002, ("exception when verifying class: '%s'", ex_name->as_C_string());
  7885. + //PENDING_EXCEPTION->print();
  7886. + CLEAR_PENDING_EXCEPTION;
  7887. + _result = false;
  7888. + }
  7889. +
  7890. + /*int method_count = klass->methods()->length();
  7891. + for (int i=0; i<method_count; i++) {
  7892. + methodOop cur_method = (methodOop)klass->methods()->obj_at(i);
  7893. + if (!check_method(cur_method)) {
  7894. + RC_TRACE(0x00000001, ("Failed to verify consistency of method %s of klass %s", cur_method->name()->as_C_string(), klass->name()->as_C_string());
  7895. + }
  7896. + }*/
  7897. + }
  7898. + };
  7899. +
  7900. + // TODO: Check bytecodes in case of interface => class or class => interface etc..
  7901. +
  7902. + GrowableArray<klassOop> dangerous_klasses;
  7903. + for (int i=0; i<_new_classes->length(); i++) {
  7904. + instanceKlassHandle handle = _new_classes->at(i);
  7905. + if (handle->check_redefinition_flag(Klass::RemoveSuperType)) {
  7906. + dangerous_klasses.append(handle());
  7907. + }
  7908. + }
  7909. +
  7910. + CheckLoadedMethodsClosure checkLoadedMethodsClosure(&dangerous_klasses);
  7911. + Thread::current()->set_pretend_new_universe(true);
  7912. + SystemDictionary::classes_do(&checkLoadedMethodsClosure);
  7913. + Thread::current()->set_pretend_new_universe(false);
  7914. +
  7915. +
  7916. + return checkLoadedMethodsClosure.result();
  7917. +}
  7918. +
  7919. +bool VM_RedefineClasses::check_type_consistency() {
  7920. +
  7921. + Universe::set_verify_in_progress(true);
  7922. +
  7923. + SystemDictionary::classes_do(calculate_type_check_information);
  7924. + bool result = check_field_value_types();
  7925. + SystemDictionary::classes_do(clear_type_check_information);
  7926. + if (!result) {
  7927. + RC_TRACE(0x00000001, ("Aborting redefinition because of wrong field or array element value!"));
  7928. + Universe::set_verify_in_progress(false);
  7929. return false;
  7930. }
  7931. - u1 tag = annotations_typeArray->byte_at(byte_i_ref);
  7932. - byte_i_ref++;
  7933. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("tag='%c'", tag));
  7934. + result = check_method_stacks();
  7935. + if (!result) {
  7936. + RC_TRACE(0x00000001, ("Aborting redefinition because of wrong value on the stack"));
  7937. + Universe::set_verify_in_progress(false);
  7938. + return false;
  7939. + }
  7940. - switch (tag) {
  7941. - // These BaseType tag values are from Table 4.2 in VM spec:
  7942. - case 'B': // byte
  7943. - case 'C': // char
  7944. - case 'D': // double
  7945. - case 'F': // float
  7946. - case 'I': // int
  7947. - case 'J': // long
  7948. - case 'S': // short
  7949. - case 'Z': // boolean
  7950. + result = check_loaded_methods();
  7951. + if (!result) {
  7952. + RC_TRACE(0x00000001, ("Aborting redefinition because of wrong loaded method"));
  7953. + Universe::set_verify_in_progress(false);
  7954. + return false;
  7955. + }
  7956. - // The remaining tag values are from Table 4.8 in the 2nd-edition of
  7957. - // the VM spec:
  7958. - case 's':
  7959. - {
  7960. - // For the above tag values (including the BaseType values),
  7961. - // value.const_value_index is right union field.
  7962. + RC_TRACE(0x00000001, ("Verification passed => hierarchy change is valid!"));
  7963. + Universe::set_verify_in_progress(false);
  7964. + return true;
  7965. +}
  7966. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  7967. - // not enough room for a const_value_index
  7968. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7969. - ("length() is too small for a const_value_index"));
  7970. - return false;
  7971. +void VM_RedefineClasses::rollback() {
  7972. + RC_TRACE(0x00000001, ("Rolling back redefinition!"));
  7973. + SystemDictionary::rollback_redefinition();
  7974. +
  7975. + RC_TRACE(0x00000001, ("After rolling back system dictionary!"));
  7976. + for (int i=0; i<_new_classes->length(); i++) {
  7977. + SystemDictionary::remove_from_hierarchy(_new_classes->at(i));
  7978. + }
  7979. +
  7980. + for (int i=0; i<_new_classes->length(); i++) {
  7981. + instanceKlassHandle new_class = _new_classes->at(i);
  7982. + new_class->set_redefining(false);
  7983. + new_class->old_version()->klass_part()->set_new_version(NULL);
  7984. + new_class->set_old_version(NULL);
  7985. + }
  7986. +
  7987. +}
  7988. +
  7989. +template <class T> void VM_RedefineClasses::do_oop_work(T* p) {
  7990. + T heap_oop = oopDesc::load_heap_oop(p);
  7991. + if (!oopDesc::is_null(heap_oop)) {
  7992. + oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
  7993. + if (obj->is_instanceKlass()) {
  7994. + klassOop klass = (klassOop)obj;
  7995. + // DCEVM: note: can overwrite owner of old_klass constants pool with new_klass, so we need to fix it back later
  7996. + if (klass->new_version() != NULL && klass->new_version()->klass_part()->is_redefining()) {
  7997. + obj = klass->klass_part()->new_version();
  7998. + oopDesc::encode_store_heap_oop_not_null(p, obj);
  7999. }
  8000. + } else if (obj->blueprint()->newest_version() == SystemDictionary::Class_klass()->klass_part()->newest_version()) {
  8001. + // update references to java.lang.Class to point to newest version. Only update references to non-primitive
  8002. + // java.lang.Class instances.
  8003. + klassOop klass_oop = java_lang_Class::as_klassOop(obj);
  8004. + if (klass_oop != NULL) {
  8005. + if (klass_oop->new_version() != NULL && klass_oop->new_version()->klass_part()->is_redefining()) {
  8006. + obj = klass_oop->new_version()->java_mirror();
  8007. + } else if (klass_oop->klass_part()->is_redefining()) {
  8008. + obj = klass_oop->java_mirror();
  8009. + }
  8010. + oopDesc::encode_store_heap_oop_not_null(p, obj);
  8011. - u2 const_value_index = rewrite_cp_ref_in_annotation_data(
  8012. - annotations_typeArray, byte_i_ref,
  8013. - "mapped old const_value_index=%d", THREAD);
  8014. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8015. - ("const_value_index=%d", const_value_index));
  8016. - } break;
  8017. -
  8018. - case 'e':
  8019. - {
  8020. - // for the above tag value, value.enum_const_value is right union field
  8021. -
  8022. - if ((byte_i_ref + 4) > annotations_typeArray->length()) {
  8023. - // not enough room for a enum_const_value
  8024. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8025. - ("length() is too small for a enum_const_value"));
  8026. - return false;
  8027. - }
  8028. -
  8029. - u2 type_name_index = rewrite_cp_ref_in_annotation_data(
  8030. - annotations_typeArray, byte_i_ref,
  8031. - "mapped old type_name_index=%d", THREAD);
  8032. -
  8033. - u2 const_name_index = rewrite_cp_ref_in_annotation_data(
  8034. - annotations_typeArray, byte_i_ref,
  8035. - "mapped old const_name_index=%d", THREAD);
  8036. -
  8037. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8038. - ("type_name_index=%d const_name_index=%d", type_name_index,
  8039. - const_name_index));
  8040. - } break;
  8041. -
  8042. - case 'c':
  8043. - {
  8044. - // for the above tag value, value.class_info_index is right union field
  8045. -
  8046. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  8047. - // not enough room for a class_info_index
  8048. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8049. - ("length() is too small for a class_info_index"));
  8050. - return false;
  8051. - }
  8052. -
  8053. - u2 class_info_index = rewrite_cp_ref_in_annotation_data(
  8054. - annotations_typeArray, byte_i_ref,
  8055. - "mapped old class_info_index=%d", THREAD);
  8056. -
  8057. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8058. - ("class_info_index=%d", class_info_index));
  8059. - } break;
  8060. -
  8061. - case '@':
  8062. - // For the above tag value, value.attr_value is the right union
  8063. - // field. This is a nested annotation.
  8064. - if (!rewrite_cp_refs_in_annotation_struct(annotations_typeArray,
  8065. - byte_i_ref, THREAD)) {
  8066. - // propagate failure back to caller
  8067. - return false;
  8068. - }
  8069. - break;
  8070. -
  8071. - case '[':
  8072. - {
  8073. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  8074. - // not enough room for a num_values field
  8075. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8076. - ("length() is too small for a num_values field"));
  8077. - return false;
  8078. - }
  8079. -
  8080. - // For the above tag value, value.array_value is the right union
  8081. - // field. This is an array of nested element_value.
  8082. - u2 num_values = Bytes::get_Java_u2((address)
  8083. - annotations_typeArray->byte_at_addr(byte_i_ref));
  8084. - byte_i_ref += 2;
  8085. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("num_values=%d", num_values));
  8086. -
  8087. - int calc_num_values = 0;
  8088. - for (; calc_num_values < num_values; calc_num_values++) {
  8089. - if (!rewrite_cp_refs_in_element_value(
  8090. - annotations_typeArray, byte_i_ref, THREAD)) {
  8091. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8092. - ("bad nested element_value at %d", calc_num_values));
  8093. - // propagate failure back to caller
  8094. - return false;
  8095. + // FIXME: DCEVM: better implementation?
  8096. + // Starting from JDK 7 java_mirror can be kept in the regular heap. Therefore, it is possible
  8097. + // that new java_mirror is in the young generation whereas p is in tenured generation. In that
  8098. + // case we need to run write barrier to make sure card table is properly updated. This will
  8099. + // allow JVM to detect reference in tenured generation properly during young generation GC.
  8100. + if (Universe::heap()->is_in_reserved(p)) {
  8101. + if (GenCollectedHeap::heap()->is_in_young(obj)) {
  8102. + GenRemSet* rs = GenCollectedHeap::heap()->rem_set();
  8103. + assert(rs->rs_kind() == GenRemSet::CardTable, "Wrong rem set kind.");
  8104. + CardTableRS* _rs = (CardTableRS*)rs;
  8105. + _rs->inline_write_ref_field_gc(p, obj);
  8106. + }
  8107. }
  8108. }
  8109. - assert(num_values == calc_num_values, "sanity check");
  8110. - } break;
  8111. -
  8112. - default:
  8113. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("bad tag=0x%x", tag));
  8114. - return false;
  8115. - } // end decode tag field
  8116. -
  8117. - return true;
  8118. -} // end rewrite_cp_refs_in_element_value()
  8119. -
  8120. -
  8121. -// Rewrite constant pool references in a fields_annotations field.
  8122. -bool VM_RedefineClasses::rewrite_cp_refs_in_fields_annotations(
  8123. - instanceKlassHandle scratch_class, TRAPS) {
  8124. -
  8125. - objArrayHandle fields_annotations(THREAD,
  8126. - scratch_class->fields_annotations());
  8127. -
  8128. - if (fields_annotations.is_null() || fields_annotations->length() == 0) {
  8129. - // no fields_annotations so nothing to do
  8130. - return true;
  8131. - }
  8132. -
  8133. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8134. - ("fields_annotations length=%d", fields_annotations->length()));
  8135. -
  8136. - for (int i = 0; i < fields_annotations->length(); i++) {
  8137. - typeArrayHandle field_annotations(THREAD,
  8138. - (typeArrayOop)fields_annotations->obj_at(i));
  8139. - if (field_annotations.is_null() || field_annotations->length() == 0) {
  8140. - // this field does not have any annotations so skip it
  8141. - continue;
  8142. - }
  8143. -
  8144. - int byte_i = 0; // byte index into field_annotations
  8145. - if (!rewrite_cp_refs_in_annotations_typeArray(field_annotations, byte_i,
  8146. - THREAD)) {
  8147. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8148. - ("bad field_annotations at %d", i));
  8149. - // propagate failure back to caller
  8150. - return false;
  8151. }
  8152. }
  8153. +}
  8154. - return true;
  8155. -} // end rewrite_cp_refs_in_fields_annotations()
  8156. +void VM_RedefineClasses::swap_marks(oop first, oop second) {
  8157. + markOop first_mark = first->mark();
  8158. + markOop second_mark = second->mark();
  8159. + first->set_mark(second_mark);
  8160. + second->set_mark(first_mark);
  8161. +}
  8162. +void VM_RedefineClasses::doit() {
  8163. + Thread *thread = Thread::current();
  8164. -// Rewrite constant pool references in a methods_annotations field.
  8165. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_annotations(
  8166. - instanceKlassHandle scratch_class, TRAPS) {
  8167. + RC_TRACE(0x00000001, ("Entering doit!"));
  8168. - objArrayHandle methods_annotations(THREAD,
  8169. - scratch_class->methods_annotations());
  8170. - if (methods_annotations.is_null() || methods_annotations->length() == 0) {
  8171. - // no methods_annotations so nothing to do
  8172. - return true;
  8173. - }
  8174. + if ((_max_redefinition_flags & Klass::RemoveSuperType) != 0) {
  8175. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8176. - ("methods_annotations length=%d", methods_annotations->length()));
  8177. + RC_TIMER_START(_timer_check_type);
  8178. - for (int i = 0; i < methods_annotations->length(); i++) {
  8179. - typeArrayHandle method_annotations(THREAD,
  8180. - (typeArrayOop)methods_annotations->obj_at(i));
  8181. - if (method_annotations.is_null() || method_annotations->length() == 0) {
  8182. - // this method does not have any annotations so skip it
  8183. - continue;
  8184. - }
  8185. -
  8186. - int byte_i = 0; // byte index into method_annotations
  8187. - if (!rewrite_cp_refs_in_annotations_typeArray(method_annotations, byte_i,
  8188. - THREAD)) {
  8189. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8190. - ("bad method_annotations at %d", i));
  8191. - // propagate failure back to caller
  8192. - return false;
  8193. - }
  8194. - }
  8195. -
  8196. - return true;
  8197. -} // end rewrite_cp_refs_in_methods_annotations()
  8198. -
  8199. -
  8200. -// Rewrite constant pool references in a methods_parameter_annotations
  8201. -// field. This "structure" is adapted from the
  8202. -// RuntimeVisibleParameterAnnotations_attribute described in section
  8203. -// 4.8.17 of the 2nd-edition of the VM spec:
  8204. -//
  8205. -// methods_parameter_annotations_typeArray {
  8206. -// u1 num_parameters;
  8207. -// {
  8208. -// u2 num_annotations;
  8209. -// annotation annotations[num_annotations];
  8210. -// } parameter_annotations[num_parameters];
  8211. -// }
  8212. -//
  8213. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_parameter_annotations(
  8214. - instanceKlassHandle scratch_class, TRAPS) {
  8215. -
  8216. - objArrayHandle methods_parameter_annotations(THREAD,
  8217. - scratch_class->methods_parameter_annotations());
  8218. -
  8219. - if (methods_parameter_annotations.is_null()
  8220. - || methods_parameter_annotations->length() == 0) {
  8221. - // no methods_parameter_annotations so nothing to do
  8222. - return true;
  8223. - }
  8224. -
  8225. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8226. - ("methods_parameter_annotations length=%d",
  8227. - methods_parameter_annotations->length()));
  8228. -
  8229. - for (int i = 0; i < methods_parameter_annotations->length(); i++) {
  8230. - typeArrayHandle method_parameter_annotations(THREAD,
  8231. - (typeArrayOop)methods_parameter_annotations->obj_at(i));
  8232. - if (method_parameter_annotations.is_null()
  8233. - || method_parameter_annotations->length() == 0) {
  8234. - // this method does not have any parameter annotations so skip it
  8235. - continue;
  8236. - }
  8237. -
  8238. - if (method_parameter_annotations->length() < 1) {
  8239. - // not enough room for a num_parameters field
  8240. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8241. - ("length() is too small for a num_parameters field at %d", i));
  8242. - return false;
  8243. - }
  8244. -
  8245. - int byte_i = 0; // byte index into method_parameter_annotations
  8246. -
  8247. - u1 num_parameters = method_parameter_annotations->byte_at(byte_i);
  8248. - byte_i++;
  8249. -
  8250. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8251. - ("num_parameters=%d", num_parameters));
  8252. -
  8253. - int calc_num_parameters = 0;
  8254. - for (; calc_num_parameters < num_parameters; calc_num_parameters++) {
  8255. - if (!rewrite_cp_refs_in_annotations_typeArray(
  8256. - method_parameter_annotations, byte_i, THREAD)) {
  8257. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8258. - ("bad method_parameter_annotations at %d", calc_num_parameters));
  8259. - // propagate failure back to caller
  8260. - return false;
  8261. - }
  8262. - }
  8263. - assert(num_parameters == calc_num_parameters, "sanity check");
  8264. - }
  8265. -
  8266. - return true;
  8267. -} // end rewrite_cp_refs_in_methods_parameter_annotations()
  8268. -
  8269. -
  8270. -// Rewrite constant pool references in a methods_default_annotations
  8271. -// field. This "structure" is adapted from the AnnotationDefault_attribute
  8272. -// that is described in section 4.8.19 of the 2nd-edition of the VM spec:
  8273. -//
  8274. -// methods_default_annotations_typeArray {
  8275. -// element_value default_value;
  8276. -// }
  8277. -//
  8278. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_default_annotations(
  8279. - instanceKlassHandle scratch_class, TRAPS) {
  8280. -
  8281. - objArrayHandle methods_default_annotations(THREAD,
  8282. - scratch_class->methods_default_annotations());
  8283. -
  8284. - if (methods_default_annotations.is_null()
  8285. - || methods_default_annotations->length() == 0) {
  8286. - // no methods_default_annotations so nothing to do
  8287. - return true;
  8288. - }
  8289. -
  8290. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8291. - ("methods_default_annotations length=%d",
  8292. - methods_default_annotations->length()));
  8293. -
  8294. - for (int i = 0; i < methods_default_annotations->length(); i++) {
  8295. - typeArrayHandle method_default_annotations(THREAD,
  8296. - (typeArrayOop)methods_default_annotations->obj_at(i));
  8297. - if (method_default_annotations.is_null()
  8298. - || method_default_annotations->length() == 0) {
  8299. - // this method does not have any default annotations so skip it
  8300. - continue;
  8301. - }
  8302. -
  8303. - int byte_i = 0; // byte index into method_default_annotations
  8304. -
  8305. - if (!rewrite_cp_refs_in_element_value(
  8306. - method_default_annotations, byte_i, THREAD)) {
  8307. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  8308. - ("bad default element_value at %d", i));
  8309. - // propagate failure back to caller
  8310. - return false;
  8311. - }
  8312. - }
  8313. -
  8314. - return true;
  8315. -} // end rewrite_cp_refs_in_methods_default_annotations()
  8316. -
  8317. -
  8318. -// Rewrite constant pool references in the method's stackmap table.
  8319. -// These "structures" are adapted from the StackMapTable_attribute that
  8320. -// is described in section 4.8.4 of the 6.0 version of the VM spec
  8321. -// (dated 2005.10.26):
  8322. -// file:///net/quincunx.sfbay/export/gbracha/ClassFile-Java6.pdf
  8323. -//
  8324. -// stack_map {
  8325. -// u2 number_of_entries;
  8326. -// stack_map_frame entries[number_of_entries];
  8327. -// }
  8328. -//
  8329. -void VM_RedefineClasses::rewrite_cp_refs_in_stack_map_table(
  8330. - methodHandle method, TRAPS) {
  8331. -
  8332. - if (!method->has_stackmap_table()) {
  8333. - return;
  8334. - }
  8335. -
  8336. - typeArrayOop stackmap_data = method->stackmap_data();
  8337. - address stackmap_p = (address)stackmap_data->byte_at_addr(0);
  8338. - address stackmap_end = stackmap_p + stackmap_data->length();
  8339. -
  8340. - assert(stackmap_p + 2 <= stackmap_end, "no room for number_of_entries");
  8341. - u2 number_of_entries = Bytes::get_Java_u2(stackmap_p);
  8342. - stackmap_p += 2;
  8343. -
  8344. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  8345. - ("number_of_entries=%u", number_of_entries));
  8346. -
  8347. - // walk through each stack_map_frame
  8348. - u2 calc_number_of_entries = 0;
  8349. - for (; calc_number_of_entries < number_of_entries; calc_number_of_entries++) {
  8350. - // The stack_map_frame structure is a u1 frame_type followed by
  8351. - // 0 or more bytes of data:
  8352. - //
  8353. - // union stack_map_frame {
  8354. - // same_frame;
  8355. - // same_locals_1_stack_item_frame;
  8356. - // same_locals_1_stack_item_frame_extended;
  8357. - // chop_frame;
  8358. - // same_frame_extended;
  8359. - // append_frame;
  8360. - // full_frame;
  8361. - // }
  8362. -
  8363. - assert(stackmap_p + 1 <= stackmap_end, "no room for frame_type");
  8364. - // The Linux compiler does not like frame_type to be u1 or u2. It
  8365. - // issues the following warning for the first if-statement below:
  8366. - //
  8367. - // "warning: comparison is always true due to limited range of data type"
  8368. - //
  8369. - u4 frame_type = *stackmap_p;
  8370. - stackmap_p++;
  8371. -
  8372. - // same_frame {
  8373. - // u1 frame_type = SAME; /* 0-63 */
  8374. - // }
  8375. - if (frame_type >= 0 && frame_type <= 63) {
  8376. - // nothing more to do for same_frame
  8377. - }
  8378. -
  8379. - // same_locals_1_stack_item_frame {
  8380. - // u1 frame_type = SAME_LOCALS_1_STACK_ITEM; /* 64-127 */
  8381. - // verification_type_info stack[1];
  8382. - // }
  8383. - else if (frame_type >= 64 && frame_type <= 127) {
  8384. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8385. - calc_number_of_entries, frame_type, THREAD);
  8386. - }
  8387. -
  8388. - // reserved for future use
  8389. - else if (frame_type >= 128 && frame_type <= 246) {
  8390. - // nothing more to do for reserved frame_types
  8391. - }
  8392. -
  8393. - // same_locals_1_stack_item_frame_extended {
  8394. - // u1 frame_type = SAME_LOCALS_1_STACK_ITEM_EXTENDED; /* 247 */
  8395. - // u2 offset_delta;
  8396. - // verification_type_info stack[1];
  8397. - // }
  8398. - else if (frame_type == 247) {
  8399. - stackmap_p += 2;
  8400. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8401. - calc_number_of_entries, frame_type, THREAD);
  8402. - }
  8403. -
  8404. - // chop_frame {
  8405. - // u1 frame_type = CHOP; /* 248-250 */
  8406. - // u2 offset_delta;
  8407. - // }
  8408. - else if (frame_type >= 248 && frame_type <= 250) {
  8409. - stackmap_p += 2;
  8410. - }
  8411. -
  8412. - // same_frame_extended {
  8413. - // u1 frame_type = SAME_FRAME_EXTENDED; /* 251*/
  8414. - // u2 offset_delta;
  8415. - // }
  8416. - else if (frame_type == 251) {
  8417. - stackmap_p += 2;
  8418. - }
  8419. -
  8420. - // append_frame {
  8421. - // u1 frame_type = APPEND; /* 252-254 */
  8422. - // u2 offset_delta;
  8423. - // verification_type_info locals[frame_type - 251];
  8424. - // }
  8425. - else if (frame_type >= 252 && frame_type <= 254) {
  8426. - assert(stackmap_p + 2 <= stackmap_end,
  8427. - "no room for offset_delta");
  8428. - stackmap_p += 2;
  8429. - u1 len = frame_type - 251;
  8430. - for (u1 i = 0; i < len; i++) {
  8431. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8432. - calc_number_of_entries, frame_type, THREAD);
  8433. - }
  8434. - }
  8435. -
  8436. - // full_frame {
  8437. - // u1 frame_type = FULL_FRAME; /* 255 */
  8438. - // u2 offset_delta;
  8439. - // u2 number_of_locals;
  8440. - // verification_type_info locals[number_of_locals];
  8441. - // u2 number_of_stack_items;
  8442. - // verification_type_info stack[number_of_stack_items];
  8443. - // }
  8444. - else if (frame_type == 255) {
  8445. - assert(stackmap_p + 2 + 2 <= stackmap_end,
  8446. - "no room for smallest full_frame");
  8447. - stackmap_p += 2;
  8448. -
  8449. - u2 number_of_locals = Bytes::get_Java_u2(stackmap_p);
  8450. - stackmap_p += 2;
  8451. -
  8452. - for (u2 locals_i = 0; locals_i < number_of_locals; locals_i++) {
  8453. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8454. - calc_number_of_entries, frame_type, THREAD);
  8455. - }
  8456. -
  8457. - // Use the largest size for the number_of_stack_items, but only get
  8458. - // the right number of bytes.
  8459. - u2 number_of_stack_items = Bytes::get_Java_u2(stackmap_p);
  8460. - stackmap_p += 2;
  8461. -
  8462. - for (u2 stack_i = 0; stack_i < number_of_stack_items; stack_i++) {
  8463. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  8464. - calc_number_of_entries, frame_type, THREAD);
  8465. - }
  8466. - }
  8467. - } // end while there is a stack_map_frame
  8468. - assert(number_of_entries == calc_number_of_entries, "sanity check");
  8469. -} // end rewrite_cp_refs_in_stack_map_table()
  8470. -
  8471. -
  8472. -// Rewrite constant pool references in the verification type info
  8473. -// portion of the method's stackmap table. These "structures" are
  8474. -// adapted from the StackMapTable_attribute that is described in
  8475. -// section 4.8.4 of the 6.0 version of the VM spec (dated 2005.10.26):
  8476. -// file:///net/quincunx.sfbay/export/gbracha/ClassFile-Java6.pdf
  8477. -//
  8478. -// The verification_type_info structure is a u1 tag followed by 0 or
  8479. -// more bytes of data:
  8480. -//
  8481. -// union verification_type_info {
  8482. -// Top_variable_info;
  8483. -// Integer_variable_info;
  8484. -// Float_variable_info;
  8485. -// Long_variable_info;
  8486. -// Double_variable_info;
  8487. -// Null_variable_info;
  8488. -// UninitializedThis_variable_info;
  8489. -// Object_variable_info;
  8490. -// Uninitialized_variable_info;
  8491. -// }
  8492. -//
  8493. -void VM_RedefineClasses::rewrite_cp_refs_in_verification_type_info(
  8494. - address& stackmap_p_ref, address stackmap_end, u2 frame_i,
  8495. - u1 frame_type, TRAPS) {
  8496. -
  8497. - assert(stackmap_p_ref + 1 <= stackmap_end, "no room for tag");
  8498. - u1 tag = *stackmap_p_ref;
  8499. - stackmap_p_ref++;
  8500. -
  8501. - switch (tag) {
  8502. - // Top_variable_info {
  8503. - // u1 tag = ITEM_Top; /* 0 */
  8504. - // }
  8505. - // verificationType.hpp has zero as ITEM_Bogus instead of ITEM_Top
  8506. - case 0: // fall through
  8507. -
  8508. - // Integer_variable_info {
  8509. - // u1 tag = ITEM_Integer; /* 1 */
  8510. - // }
  8511. - case ITEM_Integer: // fall through
  8512. -
  8513. - // Float_variable_info {
  8514. - // u1 tag = ITEM_Float; /* 2 */
  8515. - // }
  8516. - case ITEM_Float: // fall through
  8517. -
  8518. - // Double_variable_info {
  8519. - // u1 tag = ITEM_Double; /* 3 */
  8520. - // }
  8521. - case ITEM_Double: // fall through
  8522. -
  8523. - // Long_variable_info {
  8524. - // u1 tag = ITEM_Long; /* 4 */
  8525. - // }
  8526. - case ITEM_Long: // fall through
  8527. -
  8528. - // Null_variable_info {
  8529. - // u1 tag = ITEM_Null; /* 5 */
  8530. - // }
  8531. - case ITEM_Null: // fall through
  8532. -
  8533. - // UninitializedThis_variable_info {
  8534. - // u1 tag = ITEM_UninitializedThis; /* 6 */
  8535. - // }
  8536. - case ITEM_UninitializedThis:
  8537. - // nothing more to do for the above tag types
  8538. - break;
  8539. -
  8540. - // Object_variable_info {
  8541. - // u1 tag = ITEM_Object; /* 7 */
  8542. - // u2 cpool_index;
  8543. - // }
  8544. - case ITEM_Object:
  8545. - {
  8546. - assert(stackmap_p_ref + 2 <= stackmap_end, "no room for cpool_index");
  8547. - u2 cpool_index = Bytes::get_Java_u2(stackmap_p_ref);
  8548. - u2 new_cp_index = find_new_index(cpool_index);
  8549. - if (new_cp_index != 0) {
  8550. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  8551. - ("mapped old cpool_index=%d", cpool_index));
  8552. - Bytes::put_Java_u2(stackmap_p_ref, new_cp_index);
  8553. - cpool_index = new_cp_index;
  8554. - }
  8555. - stackmap_p_ref += 2;
  8556. -
  8557. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  8558. - ("frame_i=%u, frame_type=%u, cpool_index=%d", frame_i,
  8559. - frame_type, cpool_index));
  8560. - } break;
  8561. -
  8562. - // Uninitialized_variable_info {
  8563. - // u1 tag = ITEM_Uninitialized; /* 8 */
  8564. - // u2 offset;
  8565. - // }
  8566. - case ITEM_Uninitialized:
  8567. - assert(stackmap_p_ref + 2 <= stackmap_end, "no room for offset");
  8568. - stackmap_p_ref += 2;
  8569. - break;
  8570. -
  8571. - default:
  8572. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  8573. - ("frame_i=%u, frame_type=%u, bad tag=0x%x", frame_i, frame_type, tag));
  8574. - ShouldNotReachHere();
  8575. - break;
  8576. - } // end switch (tag)
  8577. -} // end rewrite_cp_refs_in_verification_type_info()
  8578. -
  8579. -
  8580. -// Change the constant pool associated with klass scratch_class to
  8581. -// scratch_cp. If shrink is true, then scratch_cp_length elements
  8582. -// are copied from scratch_cp to a smaller constant pool and the
  8583. -// smaller constant pool is associated with scratch_class.
  8584. -void VM_RedefineClasses::set_new_constant_pool(
  8585. - instanceKlassHandle scratch_class, constantPoolHandle scratch_cp,
  8586. - int scratch_cp_length, TRAPS) {
  8587. - assert(scratch_cp->length() >= scratch_cp_length, "sanity check");
  8588. -
  8589. - // scratch_cp is a merged constant pool and has enough space for a
  8590. - // worst case merge situation. We want to associate the minimum
  8591. - // sized constant pool with the klass to save space.
  8592. - constantPoolHandle smaller_cp(THREAD,
  8593. - oopFactory::new_constantPool(scratch_cp_length,
  8594. - oopDesc::IsUnsafeConc,
  8595. - THREAD));
  8596. - // preserve orig_length() value in the smaller copy
  8597. - int orig_length = scratch_cp->orig_length();
  8598. - assert(orig_length != 0, "sanity check");
  8599. - smaller_cp->set_orig_length(orig_length);
  8600. -
  8601. - // attach klass to new constant pool
  8602. - // reference to the cp holder is needed for copy_operands()
  8603. - smaller_cp->set_pool_holder(scratch_class());
  8604. -
  8605. - scratch_cp->copy_cp_to(1, scratch_cp_length - 1, smaller_cp, 1, THREAD);
  8606. - scratch_cp = smaller_cp;
  8607. - smaller_cp()->set_is_conc_safe(true);
  8608. -
  8609. - // attach new constant pool to klass
  8610. - scratch_class->set_constants(scratch_cp());
  8611. -
  8612. - int i; // for portability
  8613. -
  8614. - // update each field in klass to use new constant pool indices as needed
  8615. - for (JavaFieldStream fs(scratch_class); !fs.done(); fs.next()) {
  8616. - jshort cur_index = fs.name_index();
  8617. - jshort new_index = find_new_index(cur_index);
  8618. - if (new_index != 0) {
  8619. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8620. - ("field-name_index change: %d to %d", cur_index, new_index));
  8621. - fs.set_name_index(new_index);
  8622. - }
  8623. - cur_index = fs.signature_index();
  8624. - new_index = find_new_index(cur_index);
  8625. - if (new_index != 0) {
  8626. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8627. - ("field-signature_index change: %d to %d", cur_index, new_index));
  8628. - fs.set_signature_index(new_index);
  8629. - }
  8630. - cur_index = fs.initval_index();
  8631. - new_index = find_new_index(cur_index);
  8632. - if (new_index != 0) {
  8633. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8634. - ("field-initval_index change: %d to %d", cur_index, new_index));
  8635. - fs.set_initval_index(new_index);
  8636. - }
  8637. - cur_index = fs.generic_signature_index();
  8638. - new_index = find_new_index(cur_index);
  8639. - if (new_index != 0) {
  8640. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8641. - ("field-generic_signature change: %d to %d", cur_index, new_index));
  8642. - fs.set_generic_signature_index(new_index);
  8643. - }
  8644. - } // end for each field
  8645. -
  8646. - // Update constant pool indices in the inner classes info to use
  8647. - // new constant indices as needed. The inner classes info is a
  8648. - // quadruple:
  8649. - // (inner_class_info, outer_class_info, inner_name, inner_access_flags)
  8650. - InnerClassesIterator iter(scratch_class);
  8651. - for (; !iter.done(); iter.next()) {
  8652. - int cur_index = iter.inner_class_info_index();
  8653. - if (cur_index == 0) {
  8654. - continue; // JVM spec. allows null inner class refs so skip it
  8655. - }
  8656. - int new_index = find_new_index(cur_index);
  8657. - if (new_index != 0) {
  8658. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8659. - ("inner_class_info change: %d to %d", cur_index, new_index));
  8660. - iter.set_inner_class_info_index(new_index);
  8661. - }
  8662. - cur_index = iter.outer_class_info_index();
  8663. - new_index = find_new_index(cur_index);
  8664. - if (new_index != 0) {
  8665. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8666. - ("outer_class_info change: %d to %d", cur_index, new_index));
  8667. - iter.set_outer_class_info_index(new_index);
  8668. - }
  8669. - cur_index = iter.inner_name_index();
  8670. - new_index = find_new_index(cur_index);
  8671. - if (new_index != 0) {
  8672. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8673. - ("inner_name change: %d to %d", cur_index, new_index));
  8674. - iter.set_inner_name_index(new_index);
  8675. - }
  8676. - } // end for each inner class
  8677. -
  8678. - // Attach each method in klass to the new constant pool and update
  8679. - // to use new constant pool indices as needed:
  8680. - objArrayHandle methods(THREAD, scratch_class->methods());
  8681. - for (i = methods->length() - 1; i >= 0; i--) {
  8682. - methodHandle method(THREAD, (methodOop)methods->obj_at(i));
  8683. - method->set_constants(scratch_cp());
  8684. -
  8685. - int new_index = find_new_index(method->name_index());
  8686. - if (new_index != 0) {
  8687. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8688. - ("method-name_index change: %d to %d", method->name_index(),
  8689. - new_index));
  8690. - method->set_name_index(new_index);
  8691. - }
  8692. - new_index = find_new_index(method->signature_index());
  8693. - if (new_index != 0) {
  8694. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8695. - ("method-signature_index change: %d to %d",
  8696. - method->signature_index(), new_index));
  8697. - method->set_signature_index(new_index);
  8698. - }
  8699. - new_index = find_new_index(method->generic_signature_index());
  8700. - if (new_index != 0) {
  8701. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8702. - ("method-generic_signature_index change: %d to %d",
  8703. - method->generic_signature_index(), new_index));
  8704. - method->set_generic_signature_index(new_index);
  8705. - }
  8706. -
  8707. - // Update constant pool indices in the method's checked exception
  8708. - // table to use new constant indices as needed.
  8709. - int cext_length = method->checked_exceptions_length();
  8710. - if (cext_length > 0) {
  8711. - CheckedExceptionElement * cext_table =
  8712. - method->checked_exceptions_start();
  8713. - for (int j = 0; j < cext_length; j++) {
  8714. - int cur_index = cext_table[j].class_cp_index;
  8715. - int new_index = find_new_index(cur_index);
  8716. - if (new_index != 0) {
  8717. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8718. - ("cext-class_cp_index change: %d to %d", cur_index, new_index));
  8719. - cext_table[j].class_cp_index = (u2)new_index;
  8720. - }
  8721. - } // end for each checked exception table entry
  8722. - } // end if there are checked exception table entries
  8723. -
  8724. - // Update each catch type index in the method's exception table
  8725. - // to use new constant pool indices as needed. The exception table
  8726. - // holds quadruple entries of the form:
  8727. - // (beg_bci, end_bci, handler_bci, klass_index)
  8728. -
  8729. - ExceptionTable ex_table(method());
  8730. - int ext_length = ex_table.length();
  8731. -
  8732. - for (int j = 0; j < ext_length; j ++) {
  8733. - int cur_index = ex_table.catch_type_index(j);
  8734. - int new_index = find_new_index(cur_index);
  8735. - if (new_index != 0) {
  8736. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8737. - ("ext-klass_index change: %d to %d", cur_index, new_index));
  8738. - ex_table.set_catch_type_index(j, new_index);
  8739. - }
  8740. - } // end for each exception table entry
  8741. -
  8742. - // Update constant pool indices in the method's local variable
  8743. - // table to use new constant indices as needed. The local variable
  8744. - // table hold sextuple entries of the form:
  8745. - // (start_pc, length, name_index, descriptor_index, signature_index, slot)
  8746. - int lvt_length = method->localvariable_table_length();
  8747. - if (lvt_length > 0) {
  8748. - LocalVariableTableElement * lv_table =
  8749. - method->localvariable_table_start();
  8750. - for (int j = 0; j < lvt_length; j++) {
  8751. - int cur_index = lv_table[j].name_cp_index;
  8752. - int new_index = find_new_index(cur_index);
  8753. - if (new_index != 0) {
  8754. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8755. - ("lvt-name_cp_index change: %d to %d", cur_index, new_index));
  8756. - lv_table[j].name_cp_index = (u2)new_index;
  8757. - }
  8758. - cur_index = lv_table[j].descriptor_cp_index;
  8759. - new_index = find_new_index(cur_index);
  8760. - if (new_index != 0) {
  8761. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8762. - ("lvt-descriptor_cp_index change: %d to %d", cur_index,
  8763. - new_index));
  8764. - lv_table[j].descriptor_cp_index = (u2)new_index;
  8765. - }
  8766. - cur_index = lv_table[j].signature_cp_index;
  8767. - new_index = find_new_index(cur_index);
  8768. - if (new_index != 0) {
  8769. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8770. - ("lvt-signature_cp_index change: %d to %d", cur_index, new_index));
  8771. - lv_table[j].signature_cp_index = (u2)new_index;
  8772. - }
  8773. - } // end for each local variable table entry
  8774. - } // end if there are local variable table entries
  8775. -
  8776. - rewrite_cp_refs_in_stack_map_table(method, THREAD);
  8777. - } // end for each method
  8778. - assert(scratch_cp()->is_conc_safe(), "Just checking");
  8779. -} // end set_new_constant_pool()
  8780. -
  8781. -
  8782. -// Unevolving classes may point to methods of the_class directly
  8783. -// from their constant pool caches, itables, and/or vtables. We
  8784. -// use the SystemDictionary::classes_do() facility and this helper
  8785. -// to fix up these pointers.
  8786. -//
  8787. -// Note: We currently don't support updating the vtable in
  8788. -// arrayKlassOops. See Open Issues in jvmtiRedefineClasses.hpp.
  8789. -void VM_RedefineClasses::adjust_cpool_cache_and_vtable(klassOop k_oop,
  8790. - oop initiating_loader, TRAPS) {
  8791. - Klass *k = k_oop->klass_part();
  8792. - if (k->oop_is_instance()) {
  8793. - HandleMark hm(THREAD);
  8794. - instanceKlass *ik = (instanceKlass *) k;
  8795. -
  8796. - // HotSpot specific optimization! HotSpot does not currently
  8797. - // support delegation from the bootstrap class loader to a
  8798. - // user-defined class loader. This means that if the bootstrap
  8799. - // class loader is the initiating class loader, then it will also
  8800. - // be the defining class loader. This also means that classes
  8801. - // loaded by the bootstrap class loader cannot refer to classes
  8802. - // loaded by a user-defined class loader. Note: a user-defined
  8803. - // class loader can delegate to the bootstrap class loader.
  8804. - //
  8805. - // If the current class being redefined has a user-defined class
  8806. - // loader as its defining class loader, then we can skip all
  8807. - // classes loaded by the bootstrap class loader.
  8808. - bool is_user_defined =
  8809. - instanceKlass::cast(_the_class_oop)->class_loader() != NULL;
  8810. - if (is_user_defined && ik->class_loader() == NULL) {
  8811. + if (!check_type_consistency()) {
  8812. + // (tw) TODO: Rollback the class redefinition
  8813. + rollback();
  8814. + RC_TRACE(0x00000001, ("Detected type inconsistency!"));
  8815. + _result = JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  8816. + RC_TIMER_STOP(_timer_check_type);
  8817. return;
  8818. }
  8819. - // This is a very busy routine. We don't want too much tracing
  8820. - // printed out.
  8821. - bool trace_name_printed = false;
  8822. + RC_TIMER_STOP(_timer_check_type);
  8823. - // Very noisy: only enable this call if you are trying to determine
  8824. - // that a specific class gets found by this routine.
  8825. - // RC_TRACE macro has an embedded ResourceMark
  8826. - // RC_TRACE_WITH_THREAD(0x00100000, THREAD,
  8827. - // ("adjust check: name=%s", ik->external_name()));
  8828. - // trace_name_printed = true;
  8829. + } else {
  8830. + RC_TRACE(0x00000001, ("No type narrowing => skipping check for type inconsistency"));
  8831. + }
  8832. - // Fix the vtable embedded in the_class and subclasses of the_class,
  8833. - // if one exists. We discard scratch_class and we don't keep an
  8834. - // instanceKlass around to hold obsolete methods so we don't have
  8835. - // any other instanceKlass embedded vtables to update. The vtable
  8836. - // holds the methodOops for virtual (but not final) methods.
  8837. - if (ik->vtable_length() > 0 && ik->is_subtype_of(_the_class_oop)) {
  8838. - // ik->vtable() creates a wrapper object; rm cleans it up
  8839. - ResourceMark rm(THREAD);
  8840. - ik->vtable()->adjust_method_entries(_matching_old_methods,
  8841. - _matching_new_methods,
  8842. - _matching_methods_length,
  8843. - &trace_name_printed);
  8844. + if (UseMethodForwardPoints) {
  8845. + RC_TRACE(0x00000001, ("Check stack for forwarding methods to new version"));
  8846. + method_forwarding();
  8847. + }
  8848. +
  8849. + if (UseSharedSpaces) {
  8850. + // Sharing is enabled so we remap the shared readonly space to
  8851. + // shared readwrite, private just in case we need to redefine
  8852. + // a shared class. We do the remap during the doit() phase of
  8853. + // the safepoint to be safer.
  8854. + if (!CompactingPermGenGen::remap_shared_readonly_as_readwrite()) {
  8855. + RC_TRACE(0x00000001, ("failed to remap shared readonly space to readwrite, private"));
  8856. + _result = JVMTI_ERROR_INTERNAL;
  8857. + return;
  8858. + }
  8859. + }
  8860. +
  8861. + RC_TIMER_START(_timer_prepare_redefinition);
  8862. + for (int i = 0; i < _new_classes->length(); i++) {
  8863. + redefine_single_class(_new_classes->at(i), thread);
  8864. + }
  8865. +
  8866. + // Deoptimize all compiled code that depends on this class
  8867. + flush_dependent_code(instanceKlassHandle(Thread::current(), (klassOop)NULL), Thread::current());
  8868. +
  8869. + // Adjust constantpool caches and vtables for all classes
  8870. + // that reference methods of the evolved class.
  8871. + SystemDictionary::classes_do(adjust_cpool_cache, Thread::current());
  8872. +
  8873. + RC_TIMER_STOP(_timer_prepare_redefinition);
  8874. + RC_TIMER_START(_timer_redefinition);
  8875. +
  8876. + class ChangePointersOopClosure : public OopClosure {
  8877. + virtual void do_oop(oop* o) {
  8878. + do_oop_work(o);
  8879. + }
  8880. +
  8881. + virtual void do_oop(narrowOop* o) {
  8882. + do_oop_work(o);
  8883. + }
  8884. + };
  8885. +
  8886. + class ChangePointersObjectClosure : public ObjectClosure {
  8887. +
  8888. + private:
  8889. +
  8890. + OopClosure *_closure;
  8891. + bool _needs_instance_update;
  8892. + GrowableArray<oop> *_updated_oops;
  8893. +
  8894. + public:
  8895. + ChangePointersObjectClosure(OopClosure *closure) : _closure(closure), _needs_instance_update(false), _updated_oops(NULL) {}
  8896. +
  8897. + bool needs_instance_update() {
  8898. + return _needs_instance_update;
  8899. + }
  8900. +
  8901. + GrowableArray<oop> *updated_oops() { return _updated_oops; }
  8902. +
  8903. + virtual void do_object(oop obj) {
  8904. + if (!obj->is_instanceKlass()) {
  8905. + obj->oop_iterate(_closure);
  8906. +
  8907. + if (obj->blueprint()->is_redefining()) {
  8908. +
  8909. + if (obj->blueprint()->check_redefinition_flag(Klass::HasInstanceTransformer)) {
  8910. + if (_updated_oops == NULL) {
  8911. + _updated_oops = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<oop>(100, true);
  8912. + }
  8913. + _updated_oops->append(obj);
  8914. + }
  8915. +
  8916. + if(obj->blueprint()->update_information() != NULL || obj->is_perm()) {
  8917. +
  8918. + assert(obj->blueprint()->old_version() != NULL, "must have old version");
  8919. + obj->set_klass_no_check(obj->blueprint()->old_version());
  8920. +
  8921. + if (obj->size() != obj->size_given_klass(obj->blueprint()->new_version()->klass_part()) || obj->is_perm()) {
  8922. + // We need an instance update => set back to old klass
  8923. + _needs_instance_update = true;
  8924. +
  8925. + } else {
  8926. + MarkSweep::update_fields(obj, obj);
  8927. + assert(obj->blueprint()->is_redefining(), "update fields resets the klass");
  8928. + }
  8929. + }
  8930. + }
  8931. +
  8932. + } else {
  8933. + instanceKlass *klass = instanceKlass::cast((klassOop)obj);
  8934. + if (klass->is_redefining()) {
  8935. + // DCEVM: We need to restorte constants pool owner which was updated by do_oop_work
  8936. + instanceKlass* old_klass = instanceKlass::cast(klass->old_version());
  8937. + old_klass->constants()->set_pool_holder(klass->old_version());
  8938. +
  8939. + // Initialize the new class! Special static initialization that does not execute the
  8940. + // static constructor but copies static field values from the old class if name
  8941. + // and signature of a static field match.
  8942. + klass->initialize_redefined_class();
  8943. + }
  8944. + // idubrov: FIXME: we probably don't need that since oop's will be visited in a regular way...
  8945. + // idubrov: need to check if there is a test to verify that fields referencing class being updated
  8946. + // idubrov: will get new version of that class
  8947. + //klass->iterate_static_fields(_closure);
  8948. + }
  8949. + }
  8950. + };
  8951. +
  8952. + ChangePointersOopClosure oopClosure;
  8953. + ChangePointersObjectClosure objectClosure(&oopClosure);
  8954. +
  8955. + {
  8956. + SharedHeap::heap()->gc_prologue(true);
  8957. + Universe::root_oops_do(&oopClosure);
  8958. + Universe::heap()->object_iterate(&objectClosure);
  8959. + SharedHeap::heap()->gc_epilogue(false);
  8960. }
  8961. - // If the current class has an itable and we are either redefining an
  8962. - // interface or if the current class is a subclass of the_class, then
  8963. - // we potentially have to fix the itable. If we are redefining an
  8964. - // interface, then we have to call adjust_method_entries() for
  8965. - // every instanceKlass that has an itable since there isn't a
  8966. - // subclass relationship between an interface and an instanceKlass.
  8967. - if (ik->itable_length() > 0 && (Klass::cast(_the_class_oop)->is_interface()
  8968. - || ik->is_subclass_of(_the_class_oop))) {
  8969. - // ik->itable() creates a wrapper object; rm cleans it up
  8970. - ResourceMark rm(THREAD);
  8971. - ik->itable()->adjust_method_entries(_matching_old_methods,
  8972. - _matching_new_methods,
  8973. - _matching_methods_length,
  8974. - &trace_name_printed);
  8975. + // Swap marks to have same hashcodes
  8976. + for (int i=0; i<_new_classes->length(); i++) {
  8977. + swap_marks(_new_classes->at(i)(), _new_classes->at(i)->old_version());
  8978. + swap_marks(_new_classes->at(i)->java_mirror(), _new_classes->at(i)->old_version()->java_mirror());
  8979. }
  8980. - // The constant pools in other classes (other_cp) can refer to
  8981. - // methods in the_class. We have to update method information in
  8982. - // other_cp's cache. If other_cp has a previous version, then we
  8983. - // have to repeat the process for each previous version. The
  8984. - // constant pool cache holds the methodOops for non-virtual
  8985. - // methods and for virtual, final methods.
  8986. - //
  8987. - // Special case: if the current class is the_class, then new_cp
  8988. - // has already been attached to the_class and old_cp has already
  8989. - // been added as a previous version. The new_cp doesn't have any
  8990. - // cached references to old methods so it doesn't need to be
  8991. - // updated. We can simply start with the previous version(s) in
  8992. - // that case.
  8993. - constantPoolHandle other_cp;
  8994. - constantPoolCacheOop cp_cache;
  8995. + _updated_oops = objectClosure.updated_oops();
  8996. - if (k_oop != _the_class_oop) {
  8997. - // this klass' constant pool cache may need adjustment
  8998. - other_cp = constantPoolHandle(ik->constants());
  8999. - cp_cache = other_cp->cache();
  9000. - if (cp_cache != NULL) {
  9001. - cp_cache->adjust_method_entries(_matching_old_methods,
  9002. - _matching_new_methods,
  9003. - _matching_methods_length,
  9004. - &trace_name_printed);
  9005. + if (objectClosure.needs_instance_update()){
  9006. +
  9007. + // Do a full garbage collection to update the instance sizes accordingly
  9008. + RC_TRACE(0x00000001, ("Before performing full GC!"));
  9009. + Universe::set_redefining_gc_run(true);
  9010. + JvmtiGCMarker jgcm;
  9011. + notify_gc_begin(true);
  9012. + Universe::heap()->collect_as_vm_thread(GCCause::_heap_inspection);
  9013. + notify_gc_end();
  9014. + Universe::set_redefining_gc_run(false);
  9015. + RC_TRACE(0x00000001, ("GC done!"));
  9016. + }
  9017. +
  9018. +
  9019. + if (RC_TRACE_ENABLED(0x00000001)) {
  9020. + if (_updated_oops != NULL) {
  9021. + RC_TRACE(0x00000001, ("%d object(s) updated!", _updated_oops->length()));
  9022. + } else {
  9023. + RC_TRACE(0x00000001, ("No objects updated!"));
  9024. + }
  9025. + }
  9026. +
  9027. + // Unmark klassOops as "redefining"
  9028. + for (int i=0; i<_new_classes->length(); i++) {
  9029. + klassOop cur = _new_classes->at(i)();
  9030. + _new_classes->at(i)->set_redefining(false);
  9031. + _new_classes->at(i)->clear_update_information();
  9032. + _new_classes->at(i)->update_supers_to_newest_version();
  9033. +
  9034. + if (((instanceKlass *)cur->klass_part()->old_version()->klass_part())->array_klasses() != NULL) {
  9035. + update_array_classes_to_newest_version(((instanceKlass *)cur->klass_part()->old_version()->klass_part())->array_klasses());
  9036. +
  9037. + // Transfer the array classes, otherwise we might get cast exceptions when casting array types.
  9038. + ((instanceKlass*)cur->klass_part())->set_array_klasses(((instanceKlass*)cur->klass_part()->old_version()->klass_part())->array_klasses());
  9039. +
  9040. + oop new_mirror = _new_classes->at(i)->java_mirror();
  9041. + oop old_mirror = _new_classes->at(i)->old_version()->java_mirror();
  9042. + java_lang_Class::set_array_klass(new_mirror, java_lang_Class::array_klass(old_mirror));
  9043. + }
  9044. + }
  9045. +
  9046. + for (int i=T_BOOLEAN; i<=T_LONG; i++) {
  9047. + update_array_classes_to_newest_version(Universe::typeArrayKlassObj((BasicType)i));
  9048. + }
  9049. +
  9050. + // Disable any dependent concurrent compilations
  9051. + SystemDictionary::notice_modification();
  9052. +
  9053. + // Set flag indicating that some invariants are no longer true.
  9054. + // See jvmtiExport.hpp for detailed explanation.
  9055. + JvmtiExport::set_has_redefined_a_class();
  9056. +
  9057. + // Clean up caches in the compiler interface and compiler threads
  9058. + CompileBroker::cleanup_after_redefinition();
  9059. +
  9060. +#ifdef ASSERT
  9061. +
  9062. + // Universe::verify();
  9063. + // JNIHandles::verify();
  9064. +
  9065. + SystemDictionary::classes_do(check_class, thread);
  9066. +#endif
  9067. +
  9068. + update_active_methods();
  9069. + RC_TIMER_STOP(_timer_redefinition);
  9070. +
  9071. +}
  9072. +
  9073. +void VM_RedefineClasses::update_array_classes_to_newest_version(klassOop smallest_dimension) {
  9074. +
  9075. + arrayKlass *curArrayKlass = arrayKlass::cast(smallest_dimension);
  9076. + assert(curArrayKlass->lower_dimension() == NULL, "argument must be smallest dimension");
  9077. +
  9078. +
  9079. + while (curArrayKlass != NULL) {
  9080. + klassOop higher_dimension = curArrayKlass->higher_dimension();
  9081. + klassOop lower_dimension = curArrayKlass->lower_dimension();
  9082. + curArrayKlass->update_supers_to_newest_version();
  9083. +
  9084. + curArrayKlass = NULL;
  9085. + if (higher_dimension != NULL) {
  9086. + curArrayKlass = arrayKlass::cast(higher_dimension);
  9087. + }
  9088. + }
  9089. +
  9090. +}
  9091. +
  9092. +void VM_RedefineClasses::doit_epilogue() {
  9093. +
  9094. + RC_TIMER_START(_timer_vm_op_epilogue);
  9095. +
  9096. + unlock_threads();
  9097. +
  9098. + ResourceMark mark;
  9099. +
  9100. + VM_GC_Operation::doit_epilogue();
  9101. + RC_TRACE(0x00000001, ("GC Operation epilogue finished! "));
  9102. +
  9103. + GrowableArray<methodHandle> instanceTransformerMethods;
  9104. +
  9105. + // Call static transformers
  9106. + for (int i=0; i<_new_classes->length(); i++) {
  9107. +
  9108. + instanceKlassHandle klass = _new_classes->at(i);
  9109. +
  9110. + // Transfer init state
  9111. + if (klass->old_version() != NULL) {
  9112. + instanceKlass::ClassState state = instanceKlass::cast(klass->old_version())->init_state();
  9113. + if (state > instanceKlass::linked) {
  9114. + klass->initialize(Thread::current());
  9115. }
  9116. }
  9117. - {
  9118. - ResourceMark rm(THREAD);
  9119. - // PreviousVersionInfo objects returned via PreviousVersionWalker
  9120. - // contain a GrowableArray of handles. We have to clean up the
  9121. - // GrowableArray _after_ the PreviousVersionWalker destructor
  9122. - // has destroyed the handles.
  9123. - {
  9124. - // the previous versions' constant pool caches may need adjustment
  9125. - PreviousVersionWalker pvw(ik);
  9126. - for (PreviousVersionInfo * pv_info = pvw.next_previous_version();
  9127. - pv_info != NULL; pv_info = pvw.next_previous_version()) {
  9128. - other_cp = pv_info->prev_constant_pool_handle();
  9129. - cp_cache = other_cp->cache();
  9130. - if (cp_cache != NULL) {
  9131. - cp_cache->adjust_method_entries(_matching_old_methods,
  9132. - _matching_new_methods,
  9133. - _matching_methods_length,
  9134. - &trace_name_printed);
  9135. - }
  9136. +
  9137. + // Find instance transformer method
  9138. +
  9139. + if (klass->check_redefinition_flag(Klass::HasInstanceTransformer)) {
  9140. +
  9141. + RC_TRACE(0x00008000, ("Call instance transformer of %s instance", klass->name()->as_C_string()));
  9142. + klassOop cur_klass = klass();
  9143. + while (cur_klass != NULL) {
  9144. + methodOop method = ((instanceKlass*)cur_klass->klass_part())->find_method(vmSymbols::transformer_name(), vmSymbols::void_method_signature());
  9145. + if (method != NULL) {
  9146. + methodHandle instanceTransformerMethod(method);
  9147. + instanceTransformerMethods.append(instanceTransformerMethod);
  9148. + break;
  9149. + } else {
  9150. + cur_klass = cur_klass->klass_part()->super();
  9151. }
  9152. - } // pvw is cleaned up
  9153. - } // rm is cleaned up
  9154. + }
  9155. + assert(cur_klass != NULL, "must have instance transformer method");
  9156. + } else {
  9157. + instanceTransformerMethods.append(methodHandle(Thread::current(), NULL));
  9158. + }
  9159. + }
  9160. +
  9161. +
  9162. + // Call instance transformers
  9163. + if (_updated_oops != NULL) {
  9164. +
  9165. + for (int i=0; i<_updated_oops->length(); i++) {
  9166. + assert(_updated_oops->at(i) != NULL, "must not be null!");
  9167. + Handle cur(_updated_oops->at(i));
  9168. + instanceKlassHandle klass(cur->klass());
  9169. +
  9170. + if (klass->check_redefinition_flag(Klass::HasInstanceTransformer)) {
  9171. +
  9172. + methodHandle method = instanceTransformerMethods.at(klass->redefinition_index());
  9173. +
  9174. + RC_TRACE(0x00008000, ("executing transformer method"));
  9175. +
  9176. + Thread *__the_thread__ = Thread::current();
  9177. + JavaValue result(T_VOID);
  9178. + JavaCallArguments args(cur);
  9179. + JavaCalls::call(&result,
  9180. + method,
  9181. + &args,
  9182. + THREAD);
  9183. +
  9184. + // TODO: What to do with an exception here?
  9185. + if (HAS_PENDING_EXCEPTION) {
  9186. + Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  9187. + RC_TRACE(0x00000002, ("exception when executing transformer: '%s'",
  9188. + ex_name->as_C_string()));
  9189. + CLEAR_PENDING_EXCEPTION;
  9190. + }
  9191. + }
  9192. + }
  9193. +
  9194. + delete _updated_oops;
  9195. + _updated_oops = NULL;
  9196. + }
  9197. +
  9198. + // Free the array of scratch classes
  9199. + delete _new_classes;
  9200. + _new_classes = NULL;
  9201. + RC_TRACE(0x00000001, ("Redefinition finished!"));
  9202. +
  9203. + RC_TIMER_STOP(_timer_vm_op_epilogue);
  9204. +}
  9205. +
  9206. +bool VM_RedefineClasses::is_modifiable_class(oop klass_mirror) {
  9207. + // classes for primitives cannot be redefined
  9208. + if (java_lang_Class::is_primitive(klass_mirror)) {
  9209. + return false;
  9210. + }
  9211. + klassOop the_class_oop = java_lang_Class::as_klassOop(klass_mirror);
  9212. + // classes for arrays cannot be redefined
  9213. + if (the_class_oop == NULL || !Klass::cast(the_class_oop)->oop_is_instance()) {
  9214. + return false;
  9215. + }
  9216. + return true;
  9217. +}
  9218. +
  9219. +#ifdef ASSERT
  9220. +
  9221. +void VM_RedefineClasses::verify_classes(klassOop k_oop_latest, oop initiating_loader, TRAPS) {
  9222. + klassOop k_oop = k_oop_latest;
  9223. + while (k_oop != NULL) {
  9224. +
  9225. + instanceKlassHandle k_handle(THREAD, k_oop);
  9226. + Verifier::verify(k_handle, Verifier::ThrowException, true, true, THREAD);
  9227. + k_oop = k_oop->klass_part()->old_version();
  9228. + }
  9229. +}
  9230. +
  9231. +#endif
  9232. +
  9233. +// Rewrite faster byte-codes back to their slower equivalent. Undoes rewriting happening in templateTable_xxx.cpp
  9234. +// The reason is that once we zero cpool caches, we need to re-resolve all entries again. Faster bytecodes do not
  9235. +// do that, they assume that cache entry is resolved already.
  9236. +static void unpatch_bytecode(methodOop method) {
  9237. + RawBytecodeStream bcs(method);
  9238. + Bytecodes::Code code;
  9239. + Bytecodes::Code java_code;
  9240. + while (!bcs.is_last_bytecode()) {
  9241. + code = bcs.raw_next();
  9242. + address bcp = bcs.bcp();
  9243. +
  9244. + if (code == Bytecodes::_breakpoint) {
  9245. + int bci = method->bci_from(bcp);
  9246. + code = method->orig_bytecode_at(bci);
  9247. + java_code = Bytecodes::java_code(code);
  9248. + if (code != java_code &&
  9249. + (java_code == Bytecodes::_getfield ||
  9250. + java_code == Bytecodes::_putfield ||
  9251. + java_code == Bytecodes::_aload_0)) {
  9252. + // Let breakpoint table handling unpatch bytecode
  9253. + method->set_orig_bytecode_at(bci, java_code);
  9254. + }
  9255. + } else {
  9256. + java_code = Bytecodes::java_code(code);
  9257. + if (code != java_code &&
  9258. + (java_code == Bytecodes::_getfield ||
  9259. + java_code == Bytecodes::_putfield ||
  9260. + java_code == Bytecodes::_aload_0)) {
  9261. + *bcp = java_code;
  9262. + }
  9263. + }
  9264. +
  9265. + // Additionally, we need to unpatch bytecode at bcp+1 for fast_xaccess (which would be fast field access)
  9266. + if (code == Bytecodes::_fast_iaccess_0 || code == Bytecodes::_fast_aaccess_0 || code == Bytecodes::_fast_faccess_0) {
  9267. + Bytecodes::Code code2 = Bytecodes::code_or_bp_at(bcp + 1);
  9268. + assert(code2 == Bytecodes::_fast_igetfield ||
  9269. + code2 == Bytecodes::_fast_agetfield ||
  9270. + code2 == Bytecodes::_fast_fgetfield, "");
  9271. + *(bcp + 1) = Bytecodes::java_code(code2);
  9272. + }
  9273. + }
  9274. +}
  9275. +
  9276. +// Unevolving classes may point to old methods directly
  9277. +// from their constant pool caches, itables, and/or vtables. We
  9278. +// use the SystemDictionary::classes_do() facility and this helper
  9279. +// to fix up these pointers. Additional field offsets and vtable indices
  9280. +// in the constant pool cache entries are fixed.
  9281. +//
  9282. +// Note: We currently don't support updating the vtable in
  9283. +// arrayKlassOops. See Open Issues in jvmtiRedefineClasses.hpp.
  9284. +void VM_RedefineClasses::adjust_cpool_cache(klassOop k_oop_latest, oop initiating_loader, TRAPS) {
  9285. + klassOop k_oop = k_oop_latest;
  9286. + while (k_oop != NULL) {
  9287. + //tty->print_cr("name=%s", k_oop->klass_part()->name()->as_C_string());
  9288. +/*
  9289. + methodOop *matching_old_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  9290. + methodOop *matching_new_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  9291. +
  9292. + for (int i=0; i<_matching_methods_length; i++) {
  9293. + matching_old_methods[i] = (methodOop)_old_methods->obj_at(_matching_old_methods[i]);
  9294. + matching_new_methods[i] = (methodOop)_new_methods->obj_at(_matching_new_methods[i]);
  9295. + }*/
  9296. +
  9297. + Klass *k = k_oop->klass_part();
  9298. + if (k->oop_is_instance()) {
  9299. + HandleMark hm(THREAD);
  9300. + instanceKlass *ik = (instanceKlass *) k;
  9301. +
  9302. + constantPoolHandle other_cp;
  9303. + constantPoolCacheOop cp_cache;
  9304. +
  9305. + other_cp = constantPoolHandle(ik->constants());
  9306. +
  9307. + for (int i=0; i<other_cp->length(); i++) {
  9308. + if (other_cp->tag_at(i).is_klass()) {
  9309. + klassOop klass = other_cp->klass_at(i, THREAD);
  9310. + if (klass->klass_part()->new_version() != NULL) {
  9311. +
  9312. + // (tw) TODO: check why/if this is necessary
  9313. + other_cp->klass_at_put(i, klass->klass_part()->new_version());
  9314. + }
  9315. + klass = other_cp->klass_at(i, THREAD);
  9316. + assert(klass->klass_part()->new_version() == NULL, "Must be new klass!");
  9317. + }
  9318. + }
  9319. +
  9320. + cp_cache = other_cp->cache();
  9321. +
  9322. + if (cp_cache != NULL) {
  9323. + cp_cache->adjust_entries(NULL,
  9324. + NULL,
  9325. + 0);
  9326. + }
  9327. +
  9328. + // If bytecode rewriting is enabled, we also need to unpatch bytecode to force resolution of zeroied entries
  9329. + if (RewriteBytecodes) {
  9330. + ik->methods_do(unpatch_bytecode);
  9331. + }
  9332. + }
  9333. + k_oop = k_oop->klass_part()->old_version();
  9334. }
  9335. }
  9336. void VM_RedefineClasses::update_jmethod_ids() {
  9337. for (int j = 0; j < _matching_methods_length; ++j) {
  9338. - methodOop old_method = _matching_old_methods[j];
  9339. + methodOop old_method = (methodOop)_old_methods->obj_at(_matching_old_methods[j]);
  9340. + RC_TRACE(0x00008000, ("matching method %s", old_method->name_and_sig_as_C_string()));
  9341. +
  9342. jmethodID jmid = old_method->find_jmethod_id_or_null();
  9343. + if (old_method->new_version() != NULL && jmid == NULL) {
  9344. + // (tw) Have to create jmethodID in this case
  9345. + jmid = old_method->jmethod_id();
  9346. + }
  9347. +
  9348. if (jmid != NULL) {
  9349. // There is a jmethodID, change it to point to the new method
  9350. - methodHandle new_method_h(_matching_new_methods[j]);
  9351. + methodHandle new_method_h((methodOop)_new_methods->obj_at(_matching_new_methods[j]));
  9352. + if (old_method->new_version() == NULL) {
  9353. + methodHandle old_method_h((methodOop)_old_methods->obj_at(_matching_old_methods[j]));
  9354. + jmethodID new_jmethod_id = JNIHandles::make_jmethod_id(old_method_h);
  9355. + bool result = instanceKlass::cast(old_method_h->method_holder())->update_jmethod_id(old_method_h(), new_jmethod_id);
  9356. + //RC_TRACE(0x00008000, ("Changed jmethodID for old method assigned to %d / result=%d", new_jmethod_id, result);
  9357. + //RC_TRACE(0x00008000, ("jmethodID new method: %d jmethodID old method: %d", new_method_h->jmethod_id(), old_method->jmethod_id());
  9358. + } else {
  9359. + jmethodID mid = new_method_h->jmethod_id();
  9360. + bool result = instanceKlass::cast(new_method_h->method_holder())->update_jmethod_id(new_method_h(), jmid);
  9361. + //RC_TRACE(0x00008000, ("Changed jmethodID for new method assigned to %d / result=%d", jmid, result);
  9362. +
  9363. + }
  9364. JNIHandles::change_method_associated_with_jmethod_id(jmid, new_method_h);
  9365. - assert(JNIHandles::resolve_jmethod_id(jmid) == _matching_new_methods[j],
  9366. - "should be replaced");
  9367. + //RC_TRACE(0x00008000, ("changing method associated with jmethod id %d to %s", (int)jmid, new_method_h->name()->as_C_string());
  9368. + assert(JNIHandles::resolve_jmethod_id(jmid) == (methodOop)_new_methods->obj_at(_matching_new_methods[j]), "should be replaced");
  9369. + jmethodID mid = ((methodOop)_new_methods->obj_at(_matching_new_methods[j]))->jmethod_id();
  9370. + assert(JNIHandles::resolve_non_null((jobject)mid) == new_method_h(), "must match!");
  9371. +
  9372. + //RC_TRACE(0x00008000, ("jmethodID new method: %d jmethodID old method: %d", new_method_h->jmethod_id(), old_method->jmethod_id());
  9373. }
  9374. }
  9375. }
  9376. -void VM_RedefineClasses::check_methods_and_mark_as_obsolete(
  9377. - BitMap *emcp_methods, int * emcp_method_count_p) {
  9378. - *emcp_method_count_p = 0;
  9379. - int obsolete_count = 0;
  9380. - int old_index = 0;
  9381. - for (int j = 0; j < _matching_methods_length; ++j, ++old_index) {
  9382. - methodOop old_method = _matching_old_methods[j];
  9383. - methodOop new_method = _matching_new_methods[j];
  9384. - methodOop old_array_method;
  9385. - // Maintain an old_index into the _old_methods array by skipping
  9386. - // deleted methods
  9387. - while ((old_array_method = (methodOop) _old_methods->obj_at(old_index))
  9388. - != old_method) {
  9389. - ++old_index;
  9390. - }
  9391. +// Deoptimize all compiled code that depends on this class.
  9392. +//
  9393. +// If the can_redefine_classes capability is obtained in the onload
  9394. +// phase then the compiler has recorded all dependencies from startup.
  9395. +// In that case we need only deoptimize and throw away all compiled code
  9396. +// that depends on the class.
  9397. +//
  9398. +// If can_redefine_classes is obtained sometime after the onload
  9399. +// phase then the dependency information may be incomplete. In that case
  9400. +// the first call to RedefineClasses causes all compiled code to be
  9401. +// thrown away. As can_redefine_classes has been obtained then
  9402. +// all future compilations will record dependencies so second and
  9403. +// subsequent calls to RedefineClasses need only throw away code
  9404. +// that depends on the class.
  9405. +//
  9406. +void VM_RedefineClasses::flush_dependent_code(instanceKlassHandle k_h, TRAPS) {
  9407. + assert_locked_or_safepoint(Compile_lock);
  9408. - if (MethodComparator::methods_EMCP(old_method, new_method)) {
  9409. - // The EMCP definition from JSR-163 requires the bytecodes to be
  9410. - // the same with the exception of constant pool indices which may
  9411. - // differ. However, the constants referred to by those indices
  9412. - // must be the same.
  9413. - //
  9414. - // We use methods_EMCP() for comparison since constant pool
  9415. - // merging can remove duplicate constant pool entries that were
  9416. - // present in the old method and removed from the rewritten new
  9417. - // method. A faster binary comparison function would consider the
  9418. - // old and new methods to be different when they are actually
  9419. - // EMCP.
  9420. - //
  9421. - // The old and new methods are EMCP and you would think that we
  9422. - // could get rid of one of them here and now and save some space.
  9423. - // However, the concept of EMCP only considers the bytecodes and
  9424. - // the constant pool entries in the comparison. Other things,
  9425. - // e.g., the line number table (LNT) or the local variable table
  9426. - // (LVT) don't count in the comparison. So the new (and EMCP)
  9427. - // method can have a new LNT that we need so we can't just
  9428. - // overwrite the new method with the old method.
  9429. - //
  9430. - // When this routine is called, we have already attached the new
  9431. - // methods to the_class so the old methods are effectively
  9432. - // overwritten. However, if an old method is still executing,
  9433. - // then the old method cannot be collected until sometime after
  9434. - // the old method call has returned. So the overwriting of old
  9435. - // methods by new methods will save us space except for those
  9436. - // (hopefully few) old methods that are still executing.
  9437. - //
  9438. - // A method refers to a constMethodOop and this presents another
  9439. - // possible avenue to space savings. The constMethodOop in the
  9440. - // new method contains possibly new attributes (LNT, LVT, etc).
  9441. - // At first glance, it seems possible to save space by replacing
  9442. - // the constMethodOop in the old method with the constMethodOop
  9443. - // from the new method. The old and new methods would share the
  9444. - // same constMethodOop and we would save the space occupied by
  9445. - // the old constMethodOop. However, the constMethodOop contains
  9446. - // a back reference to the containing method. Sharing the
  9447. - // constMethodOop between two methods could lead to confusion in
  9448. - // the code that uses the back reference. This would lead to
  9449. - // brittle code that could be broken in non-obvious ways now or
  9450. - // in the future.
  9451. - //
  9452. - // Another possibility is to copy the constMethodOop from the new
  9453. - // method to the old method and then overwrite the new method with
  9454. - // the old method. Since the constMethodOop contains the bytecodes
  9455. - // for the method embedded in the oop, this option would change
  9456. - // the bytecodes out from under any threads executing the old
  9457. - // method and make the thread's bcp invalid. Since EMCP requires
  9458. - // that the bytecodes be the same modulo constant pool indices, it
  9459. - // is straight forward to compute the correct new bcp in the new
  9460. - // constMethodOop from the old bcp in the old constMethodOop. The
  9461. - // time consuming part would be searching all the frames in all
  9462. - // of the threads to find all of the calls to the old method.
  9463. - //
  9464. - // It looks like we will have to live with the limited savings
  9465. - // that we get from effectively overwriting the old methods
  9466. - // when the new methods are attached to the_class.
  9467. + // All dependencies have been recorded from startup or this is a second or
  9468. + // subsequent use of RedefineClasses
  9469. - // track which methods are EMCP for add_previous_version() call
  9470. - emcp_methods->set_bit(old_index);
  9471. - (*emcp_method_count_p)++;
  9472. + // For now deopt all
  9473. + // (tw) TODO: Improve the dependency system such that we can safely deopt only a subset of the methods
  9474. + if (0 && JvmtiExport::all_dependencies_are_recorded()) {
  9475. + Universe::flush_evol_dependents_on(k_h);
  9476. + } else {
  9477. + CodeCache::mark_all_nmethods_for_deoptimization();
  9478. - // An EMCP method is _not_ obsolete. An obsolete method has a
  9479. - // different jmethodID than the current method. An EMCP method
  9480. - // has the same jmethodID as the current method. Having the
  9481. - // same jmethodID for all EMCP versions of a method allows for
  9482. - // a consistent view of the EMCP methods regardless of which
  9483. - // EMCP method you happen to have in hand. For example, a
  9484. - // breakpoint set in one EMCP method will work for all EMCP
  9485. - // versions of the method including the current one.
  9486. - } else {
  9487. - // mark obsolete methods as such
  9488. - old_method->set_is_obsolete();
  9489. - obsolete_count++;
  9490. + ResourceMark rm(THREAD);
  9491. + DeoptimizationMarker dm;
  9492. - // obsolete methods need a unique idnum
  9493. - u2 num = instanceKlass::cast(_the_class_oop)->next_method_idnum();
  9494. - if (num != constMethodOopDesc::UNSET_IDNUM) {
  9495. -// u2 old_num = old_method->method_idnum();
  9496. - old_method->set_method_idnum(num);
  9497. -// TO DO: attach obsolete annotations to obsolete method's new idnum
  9498. + // Deoptimize all activations depending on marked nmethods
  9499. + Deoptimization::deoptimize_dependents();
  9500. +
  9501. + // Make the dependent methods not entrant (in VM_Deoptimize they are made zombies)
  9502. + CodeCache::make_marked_nmethods_not_entrant();
  9503. +
  9504. + // From now on we know that the dependency information is complete
  9505. + JvmtiExport::set_all_dependencies_are_recorded(true);
  9506. + }
  9507. +}
  9508. +
  9509. +void VM_RedefineClasses::compute_added_deleted_matching_methods() {
  9510. + methodOop old_method;
  9511. + methodOop new_method;
  9512. +
  9513. + _matching_old_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  9514. + _matching_new_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  9515. + _added_methods = NEW_RESOURCE_ARRAY(int, _new_methods->length());
  9516. + _deleted_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  9517. +
  9518. + _matching_methods_length = 0;
  9519. + _deleted_methods_length = 0;
  9520. + _added_methods_length = 0;
  9521. +
  9522. + int nj = 0;
  9523. + int oj = 0;
  9524. + while (true) {
  9525. + if (oj >= _old_methods->length()) {
  9526. + if (nj >= _new_methods->length()) {
  9527. + break; // we've looked at everything, done
  9528. }
  9529. + // New method at the end
  9530. + new_method = (methodOop) _new_methods->obj_at(nj);
  9531. + _added_methods[_added_methods_length++] = nj;
  9532. + ++nj;
  9533. + } else if (nj >= _new_methods->length()) {
  9534. + // Old method, at the end, is deleted
  9535. + old_method = (methodOop) _old_methods->obj_at(oj);
  9536. + _deleted_methods[_deleted_methods_length++] = oj;
  9537. + ++oj;
  9538. + } else {
  9539. + old_method = (methodOop) _old_methods->obj_at(oj);
  9540. + new_method = (methodOop) _new_methods->obj_at(nj);
  9541. + if (old_method->name() == new_method->name()) {
  9542. + if (old_method->signature() == new_method->signature()) {
  9543. + _matching_old_methods[_matching_methods_length ] = oj;//old_method;
  9544. + _matching_new_methods[_matching_methods_length++] = nj;//new_method;
  9545. + ++nj;
  9546. + ++oj;
  9547. + } else {
  9548. + // added overloaded have already been moved to the end,
  9549. + // so this is a deleted overloaded method
  9550. + _deleted_methods[_deleted_methods_length++] = oj;//old_method;
  9551. + ++oj;
  9552. + }
  9553. + } else { // names don't match
  9554. + if (old_method->name()->fast_compare(new_method->name()) > 0) {
  9555. + // new method
  9556. + _added_methods[_added_methods_length++] = nj;//new_method;
  9557. + ++nj;
  9558. + } else {
  9559. + // deleted method
  9560. + _deleted_methods[_deleted_methods_length++] = oj;//old_method;
  9561. + ++oj;
  9562. + }
  9563. + }
  9564. + }
  9565. + }
  9566. + assert(_matching_methods_length + _deleted_methods_length == _old_methods->length(), "sanity");
  9567. + assert(_matching_methods_length + _added_methods_length == _new_methods->length(), "sanity");
  9568. + RC_TRACE(0x00008000, ("Matching methods = %d / deleted methods = %d / added methods = %d",
  9569. + _matching_methods_length, _deleted_methods_length, _added_methods_length));
  9570. +}
  9571. +
  9572. +
  9573. +
  9574. +// Install the redefinition of a class:
  9575. +// - house keeping (flushing breakpoints and caches, deoptimizing
  9576. +// dependent compiled code)
  9577. +// - adjusting constant pool caches and vtables in other classes
  9578. +void VM_RedefineClasses::redefine_single_class(instanceKlassHandle the_new_class, TRAPS) {
  9579. +
  9580. + ResourceMark rm(THREAD);
  9581. +
  9582. + assert(the_new_class->old_version() != NULL, "Must not be null");
  9583. + assert(the_new_class->old_version()->klass_part()->new_version() == the_new_class(), "Must equal");
  9584. +
  9585. + instanceKlassHandle the_old_class = instanceKlassHandle(THREAD, the_new_class->old_version());
  9586. +
  9587. +#ifndef JVMTI_KERNEL
  9588. + // Remove all breakpoints in methods of this class
  9589. + JvmtiBreakpoints& jvmti_breakpoints = JvmtiCurrentBreakpoints::get_jvmti_breakpoints();
  9590. + jvmti_breakpoints.clearall_in_class_at_safepoint(the_old_class());
  9591. +#endif // !JVMTI_KERNEL
  9592. +
  9593. + if (the_old_class() == Universe::reflect_invoke_cache()->klass()) {
  9594. + // We are redefining java.lang.reflect.Method. Method.invoke() is
  9595. + // cached and users of the cache care about each active version of
  9596. + // the method so we have to track this previous version.
  9597. + // Do this before methods get switched
  9598. + Universe::reflect_invoke_cache()->add_previous_version(
  9599. + the_old_class->method_with_idnum(Universe::reflect_invoke_cache()->method_idnum()));
  9600. + }
  9601. +
  9602. + _old_methods = the_old_class->methods();
  9603. + _new_methods = the_new_class->methods();
  9604. + _the_class_oop = the_old_class();
  9605. + compute_added_deleted_matching_methods();
  9606. +
  9607. + // track which methods are EMCP for add_previous_version() call below
  9608. +
  9609. + // (tw) TODO: Check if we need the concept of EMCP?
  9610. + BitMap emcp_methods(_old_methods->length());
  9611. + int emcp_method_count = 0;
  9612. + emcp_methods.clear(); // clears 0..(length() - 1)
  9613. +
  9614. + // We need to mark methods as old!!
  9615. + check_methods_and_mark_as_obsolete(&emcp_methods, &emcp_method_count);
  9616. + update_jmethod_ids();
  9617. +
  9618. + // keep track of previous versions of this class
  9619. + the_new_class->add_previous_version(the_old_class, &emcp_methods,
  9620. + emcp_method_count);
  9621. +
  9622. + // TODO:
  9623. + transfer_old_native_function_registrations(the_old_class);
  9624. +
  9625. +
  9626. +#ifdef ASSERT
  9627. +
  9628. +// klassOop systemLookup1 = SystemDictionary::resolve_or_null(the_old_class->name(), the_old_class->class_loader(), the_old_class->protection_domain(), THREAD);
  9629. +// assert(systemLookup1 == the_new_class(), "New class must be in system dictionary!");
  9630. +
  9631. + //JNIHandles::verify();
  9632. +
  9633. +// klassOop systemLookup = SystemDictionary::resolve_or_null(the_old_class->name(), the_old_class->class_loader(), the_old_class->protection_domain(), THREAD);
  9634. +
  9635. +// assert(systemLookup == the_new_class(), "New class must be in system dictionary!");
  9636. + assert(the_new_class->old_version() != NULL, "Must not be null");
  9637. + assert(the_new_class->old_version()->klass_part()->new_version() == the_new_class(), "Must equal");
  9638. +
  9639. + for (int i=0; i<the_new_class->methods()->length(); i++) {
  9640. + assert(((methodOop)the_new_class->methods()->obj_at(i))->method_holder() == the_new_class(), "method holder must match!");
  9641. + }
  9642. +
  9643. + _old_methods->verify();
  9644. + _new_methods->verify();
  9645. +
  9646. + the_new_class->vtable()->verify(tty);
  9647. + the_old_class->vtable()->verify(tty);
  9648. +
  9649. +#endif
  9650. +
  9651. + // increment the classRedefinedCount field in the_class and in any
  9652. + // direct and indirect subclasses of the_class
  9653. + increment_class_counter((instanceKlass *)the_old_class()->klass_part(), THREAD);
  9654. +
  9655. +}
  9656. +
  9657. +
  9658. +void VM_RedefineClasses::check_methods_and_mark_as_obsolete(BitMap *emcp_methods, int * emcp_method_count_p) {
  9659. + RC_TRACE(0x00008000, ("Checking matching methods for EMCP"));
  9660. + *emcp_method_count_p = 0;
  9661. + int obsolete_count = 0;
  9662. + int old_index = 0;
  9663. + for (int j = 0; j < _matching_methods_length; ++j, ++old_index) {
  9664. + methodOop old_method = (methodOop)_old_methods->obj_at(_matching_old_methods[j]);
  9665. + methodOop new_method = (methodOop)_new_methods->obj_at(_matching_new_methods[j]);
  9666. + methodOop old_array_method;
  9667. +
  9668. + // Maintain an old_index into the _old_methods array by skipping
  9669. + // deleted methods
  9670. + while ((old_array_method = (methodOop) _old_methods->obj_at(old_index))
  9671. + != old_method) {
  9672. + ++old_index;
  9673. + }
  9674. +
  9675. + if (MethodComparator::methods_EMCP(old_method, new_method)) {
  9676. + // The EMCP definition from JSR-163 requires the bytecodes to be
  9677. + // the same with the exception of constant pool indices which may
  9678. + // differ. However, the constants referred to by those indices
  9679. + // must be the same.
  9680. + //
  9681. + // We use methods_EMCP() for comparison since constant pool
  9682. + // merging can remove duplicate constant pool entries that were
  9683. + // present in the old method and removed from the rewritten new
  9684. + // method. A faster binary comparison function would consider the
  9685. + // old and new methods to be different when they are actually
  9686. + // EMCP.
  9687. +
  9688. + // track which methods are EMCP for add_previous_version() call
  9689. + emcp_methods->set_bit(old_index);
  9690. + (*emcp_method_count_p)++;
  9691. +
  9692. + // An EMCP method is _not_ obsolete. An obsolete method has a
  9693. + // different jmethodID than the current method. An EMCP method
  9694. + // has the same jmethodID as the current method. Having the
  9695. + // same jmethodID for all EMCP versions of a method allows for
  9696. + // a consistent view of the EMCP methods regardless of which
  9697. + // EMCP method you happen to have in hand. For example, a
  9698. + // breakpoint set in one EMCP method will work for all EMCP
  9699. + // versions of the method including the current one.
  9700. +
  9701. + old_method->set_new_version(new_method);
  9702. + new_method->set_old_version(old_method);
  9703. +
  9704. + RC_TRACE(0x00008000, ("Found EMCP method %s", old_method->name_and_sig_as_C_string()));
  9705. +
  9706. + // Transfer breakpoints
  9707. + instanceKlass *ik = instanceKlass::cast(old_method->method_holder());
  9708. + for (BreakpointInfo* bp = ik->breakpoints(); bp != NULL; bp = bp->next()) {
  9709. + RC_TRACE(0x00000002, ("Checking breakpoint"));
  9710. + RC_TRACE(0x00000002, ("%d / %d",
  9711. + bp->match(old_method), bp->match(new_method)));
  9712. + if (bp->match(old_method)) {
  9713. + assert(bp->match(new_method), "if old method is method, then new method must match too");
  9714. + RC_TRACE(0x00000002, ("Found a breakpoint in an old EMCP method"));
  9715. + new_method->set_breakpoint(bp->bci());
  9716. + }
  9717. + }
  9718. +
  9719. +
  9720. +
  9721. + } else {
  9722. + // mark obsolete methods as such
  9723. + old_method->set_is_obsolete();
  9724. + obsolete_count++;
  9725. +
  9726. + // With tracing we try not to "yack" too much. The position of
  9727. + // this trace assumes there are fewer obsolete methods than
  9728. + // EMCP methods.
  9729. + RC_TRACE(0x00008000, ("mark %s(%s) as obsolete",
  9730. + old_method->name()->as_C_string(),
  9731. + old_method->signature()->as_C_string()));
  9732. + }
  9733. + old_method->set_is_old();
  9734. + }
  9735. + for (int i = 0; i < _deleted_methods_length; ++i) {
  9736. + methodOop old_method = (methodOop)_old_methods->obj_at(_deleted_methods[i]);
  9737. +
  9738. + //assert(old_method->vtable_index() < 0,
  9739. + // "cannot delete methods with vtable entries");;
  9740. +
  9741. + // Mark all deleted methods as old and obsolete
  9742. + old_method->set_is_old();
  9743. + old_method->set_is_obsolete();
  9744. + ++obsolete_count;
  9745. // With tracing we try not to "yack" too much. The position of
  9746. // this trace assumes there are fewer obsolete methods than
  9747. // EMCP methods.
  9748. - RC_TRACE(0x00000100, ("mark %s(%s) as obsolete",
  9749. + RC_TRACE(0x00008000, ("mark deleted %s(%s) as obsolete",
  9750. old_method->name()->as_C_string(),
  9751. old_method->signature()->as_C_string()));
  9752. }
  9753. - old_method->set_is_old();
  9754. - }
  9755. - for (int i = 0; i < _deleted_methods_length; ++i) {
  9756. - methodOop old_method = _deleted_methods[i];
  9757. -
  9758. - assert(old_method->vtable_index() < 0,
  9759. - "cannot delete methods with vtable entries");;
  9760. -
  9761. - // Mark all deleted methods as old and obsolete
  9762. - old_method->set_is_old();
  9763. - old_method->set_is_obsolete();
  9764. - ++obsolete_count;
  9765. - // With tracing we try not to "yack" too much. The position of
  9766. - // this trace assumes there are fewer obsolete methods than
  9767. - // EMCP methods.
  9768. - RC_TRACE(0x00000100, ("mark deleted %s(%s) as obsolete",
  9769. - old_method->name()->as_C_string(),
  9770. - old_method->signature()->as_C_string()));
  9771. - }
  9772. - assert((*emcp_method_count_p + obsolete_count) == _old_methods->length(),
  9773. - "sanity check");
  9774. - RC_TRACE(0x00000100, ("EMCP_cnt=%d, obsolete_cnt=%d", *emcp_method_count_p,
  9775. - obsolete_count));
  9776. + //assert((*emcp_method_count_p + obsolete_count) == _old_methods->length(), "sanity check");
  9777. + RC_TRACE(0x00008000, ("EMCP_cnt=%d, obsolete_cnt=%d !", *emcp_method_count_p, obsolete_count));
  9778. }
  9779. +
  9780. +// Increment the classRedefinedCount field in the specific instanceKlass
  9781. +// and in all direct and indirect subclasses.
  9782. +void VM_RedefineClasses::increment_class_counter(instanceKlass *ik, TRAPS) {
  9783. + oop class_mirror = ik->java_mirror();
  9784. + klassOop class_oop = java_lang_Class::as_klassOop(class_mirror);
  9785. + int new_count = java_lang_Class::classRedefinedCount(class_mirror) + 1;
  9786. + java_lang_Class::set_classRedefinedCount(class_mirror, new_count);
  9787. + RC_TRACE(0x00008000, ("updated count for class=%s to %d", ik->external_name(), new_count));
  9788. +}
  9789. +
  9790. +#ifndef PRODUCT
  9791. +void VM_RedefineClasses::check_class(klassOop k_oop, TRAPS) {
  9792. + Klass *k = k_oop->klass_part();
  9793. + if (k->oop_is_instance()) {
  9794. + HandleMark hm(THREAD);
  9795. + instanceKlass *ik = (instanceKlass *) k;
  9796. + assert(ik->is_newest_version(), "must be latest version in system dictionary");
  9797. +
  9798. + if (ik->vtable_length() > 0) {
  9799. + ResourceMark rm(THREAD);
  9800. + if (!ik->vtable()->check_no_old_entries()) {
  9801. + RC_TRACE(0x00000001, ("size of class: %d\n",
  9802. + k_oop->size()));
  9803. + RC_TRACE(0x00000001, ("klassVtable::check_no_old_entries failure -- OLD method found -- class: %s",
  9804. + ik->signature_name()));
  9805. + assert(false, "OLD method found");
  9806. + }
  9807. +
  9808. + ik->vtable()->verify(tty, true);
  9809. + }
  9810. + }
  9811. +}
  9812. +
  9813. +#endif
  9814. +
  9815. +VM_RedefineClasses::FindAffectedKlassesClosure::FindAffectedKlassesClosure( GrowableArray<instanceKlassHandle> *original_klasses, GrowableArray<instanceKlassHandle> *result )
  9816. +{
  9817. + assert(original_klasses != NULL && result != NULL, "");
  9818. + this->_original_klasses = original_klasses;
  9819. + this->_result = result;
  9820. + SystemDictionary::classes_do(this);
  9821. +}
  9822. +
  9823. +void VM_RedefineClasses::FindAffectedKlassesClosure::do_object( oop obj )
  9824. +{
  9825. + klassOop klass = (klassOop)obj;
  9826. + assert(!_result->contains(klass), "must not occur more than once!");
  9827. + assert(klass->klass_part()->new_version() == NULL, "Only last version is valid entry in system dictionary");
  9828. +
  9829. + for(int i=0; i<_original_klasses->length(); i++) {
  9830. + instanceKlassHandle cur = _original_klasses->at(i);
  9831. + if (cur() != klass && klass->klass_part()->is_subtype_of(cur()) && !_original_klasses->contains(klass)) {
  9832. + RC_TRACE(0x00008000, ("Found affected class: %s", klass->klass_part()->name()->as_C_string()));
  9833. + _result->append(klass);
  9834. + break;
  9835. + }
  9836. + }
  9837. +}
  9838. +
  9839. +jvmtiError VM_RedefineClasses::do_topological_class_sorting( const jvmtiClassDefinition *class_defs, int class_count, GrowableArray<instanceKlassHandle> *affected, GrowableArray<instanceKlassHandle> *arr, TRAPS)
  9840. +{
  9841. + GrowableArray< Pair<klassOop, klassOop> > *links = new GrowableArray< Pair<klassOop, klassOop> >();
  9842. +
  9843. + for (int i=0; i<class_count; i++) {
  9844. +
  9845. + oop mirror = JNIHandles::resolve_non_null(class_defs[i].klass);
  9846. + klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
  9847. + instanceKlassHandle the_class(THREAD, the_class_oop);
  9848. + Handle the_class_loader(THREAD, the_class->class_loader());
  9849. + Handle protection_domain(THREAD, the_class->protection_domain());
  9850. +
  9851. + ClassFileStream st((u1*) class_defs[i].class_bytes,
  9852. + class_defs[i].class_byte_count, (char *)"__VM_RedefineClasses__");
  9853. + ClassFileParser cfp(&st);
  9854. +
  9855. + GrowableArray<Symbol*> symbolArr;
  9856. + RC_TRACE(0x00000002, ("Before find super symbols of class %s",
  9857. + the_class->name()->as_C_string()));
  9858. + cfp.findSuperSymbols(the_class->name(), the_class_loader, protection_domain, the_class, symbolArr, THREAD);
  9859. +
  9860. + for (int j=0; j<symbolArr.length(); j++) {
  9861. + Symbol* sym = symbolArr.at(j);
  9862. +
  9863. + RC_TRACE(0x00008000, ("Before adding link to super class %s", sym->as_C_string()));
  9864. +
  9865. + for (int k=0; k<arr->length(); k++) {
  9866. + klassOop curOop = arr->at(k)();
  9867. + // (tw) TODO: Check if we get aliasing problems with different class loaders?
  9868. + if (curOop->klass_part()->name() == sym /*&& curOop->klass_part()->class_loader() == the_class_loader()*/) {
  9869. + RC_TRACE(0x00000002, ("Found class to link"));
  9870. + links->append(Pair<klassOop, klassOop>(curOop, the_class()));
  9871. + break;
  9872. + }
  9873. + }
  9874. + }
  9875. + }
  9876. +
  9877. +
  9878. + RC_TRACE(0x00000001, ("Identified links between classes! "));
  9879. +
  9880. + for (int i=0; i<affected->length(); i++) {
  9881. +
  9882. + instanceKlassHandle klass = affected->at(i);
  9883. +
  9884. + klassOop superKlass = klass->super();
  9885. + if (affected->contains(superKlass)) {
  9886. + links->append(Pair<klassOop, klassOop>(superKlass, klass()));
  9887. + }
  9888. +
  9889. + objArrayOop superInterfaces = klass->local_interfaces();
  9890. + for (int j=0; j<superInterfaces->length(); j++) {
  9891. + klassOop interfaceKlass = (klassOop)superInterfaces->obj_at(j);
  9892. + if (arr->contains(interfaceKlass)) {
  9893. + links->append(Pair<klassOop, klassOop>(interfaceKlass, klass()));
  9894. + }
  9895. + }
  9896. + }
  9897. +
  9898. + if (RC_TRACE_ENABLED(0x00000002)) {
  9899. + RC_TRACE(0x00000002, ("Identified links: "));
  9900. + for (int i=0; i<links->length(); i++) {
  9901. + RC_TRACE(0x00000002, ("%s to %s",
  9902. + links->at(i).left()->klass_part()->name()->as_C_string(),
  9903. + links->at(i).right()->klass_part()->name()->as_C_string()));
  9904. + }
  9905. + }
  9906. +
  9907. + for (int i=0; i<arr->length(); i++) {
  9908. +
  9909. + int j;
  9910. + for (j=i; j<arr->length(); j++) {
  9911. +
  9912. + int k;
  9913. + for (k=0; k<links->length(); k++) {
  9914. +
  9915. + klassOop k1 = links->adr_at(k)->right();
  9916. + klassOop k2 = arr->at(j)();
  9917. + if (k1 == k2) {
  9918. + break;
  9919. + }
  9920. + }
  9921. +
  9922. + if (k == links->length()) {
  9923. + break;
  9924. + }
  9925. + }
  9926. +
  9927. + if (j == arr->length()) {
  9928. + // circle detected
  9929. + return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  9930. + }
  9931. +
  9932. + for (int k=0; k<links->length(); k++) {
  9933. + if (links->adr_at(k)->left() == arr->at(j)()) {
  9934. + links->at_put(k, links->at(links->length() - 1));
  9935. + links->remove_at(links->length() - 1);
  9936. + k--;
  9937. + }
  9938. + }
  9939. +
  9940. + instanceKlassHandle tmp = arr->at(j);
  9941. + arr->at_put(j, arr->at(i));
  9942. + arr->at_put(i, tmp);
  9943. + }
  9944. +
  9945. + return JVMTI_ERROR_NONE;
  9946. +}
  9947. +
  9948. +void VM_RedefineClasses::oops_do(OopClosure *closure) {
  9949. +
  9950. + if (_updated_oops != NULL) {
  9951. + for (int i=0; i<_updated_oops->length(); i++) {
  9952. + closure->do_oop(_updated_oops->adr_at(i));
  9953. + }
  9954. + }
  9955. +}
  9956. +
  9957. +void VM_RedefineClasses::transfer_special_access_flags(fieldDescriptor *from, fieldDescriptor *to) {
  9958. + to->set_is_field_modification_watched(from->is_field_modification_watched());
  9959. + to->set_is_field_access_watched(from->is_field_access_watched());
  9960. + if (from->is_field_modification_watched() || from->is_field_access_watched()) {
  9961. + RC_TRACE(0x00000002, ("Transferred watch for field %s",
  9962. + from->name()->as_C_string()));
  9963. + }
  9964. + update_klass_field_access_flag(to);
  9965. +}
  9966. +
  9967. +void VM_RedefineClasses::update_klass_field_access_flag(fieldDescriptor *fd) {
  9968. + instanceKlass* ik = instanceKlass::cast(fd->field_holder());
  9969. + FieldInfo* fi = FieldInfo::from_field_array(ik->fields(), fd->index());
  9970. + fi->set_access_flags(fd->access_flags().as_short());
  9971. +}
  9972. +
  9973. // This internal class transfers the native function registration from old methods
  9974. // to new methods. It is designed to handle both the simple case of unchanged
  9975. @@ -2969,7 +3161,7 @@
  9976. // Same, caused by prefix removal only 3_2_1_m -> 3_2_m
  9977. //
  9978. class TransferNativeFunctionRegistration {
  9979. - private:
  9980. +private:
  9981. instanceKlassHandle the_class;
  9982. int prefix_count;
  9983. char** prefixes;
  9984. @@ -2982,42 +3174,42 @@
  9985. // (2) with the prefix.
  9986. // where 'prefix' is the prefix at that 'depth' (first prefix, second prefix,...)
  9987. methodOop search_prefix_name_space(int depth, char* name_str, size_t name_len,
  9988. - Symbol* signature) {
  9989. - TempNewSymbol name_symbol = SymbolTable::probe(name_str, (int)name_len);
  9990. - if (name_symbol != NULL) {
  9991. - methodOop method = Klass::cast(the_class())->lookup_method(name_symbol, signature);
  9992. - if (method != NULL) {
  9993. - // Even if prefixed, intermediate methods must exist.
  9994. - if (method->is_native()) {
  9995. - // Wahoo, we found a (possibly prefixed) version of the method, return it.
  9996. - return method;
  9997. - }
  9998. - if (depth < prefix_count) {
  9999. - // Try applying further prefixes (other than this one).
  10000. - method = search_prefix_name_space(depth+1, name_str, name_len, signature);
  10001. - if (method != NULL) {
  10002. - return method; // found
  10003. + Symbol* signature) {
  10004. + Symbol* name_symbol = SymbolTable::probe(name_str, (int)name_len);
  10005. + if (name_symbol != NULL) {
  10006. + methodOop method = Klass::cast(the_class()->klass_part()->new_version())->lookup_method(name_symbol, signature);
  10007. + if (method != NULL) {
  10008. + // Even if prefixed, intermediate methods must exist.
  10009. + if (method->is_native()) {
  10010. + // Wahoo, we found a (possibly prefixed) version of the method, return it.
  10011. + return method;
  10012. }
  10013. + if (depth < prefix_count) {
  10014. + // Try applying further prefixes (other than this one).
  10015. + method = search_prefix_name_space(depth+1, name_str, name_len, signature);
  10016. + if (method != NULL) {
  10017. + return method; // found
  10018. + }
  10019. - // Try adding this prefix to the method name and see if it matches
  10020. - // another method name.
  10021. - char* prefix = prefixes[depth];
  10022. - size_t prefix_len = strlen(prefix);
  10023. - size_t trial_len = name_len + prefix_len;
  10024. - char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1);
  10025. - strcpy(trial_name_str, prefix);
  10026. - strcat(trial_name_str, name_str);
  10027. - method = search_prefix_name_space(depth+1, trial_name_str, trial_len,
  10028. - signature);
  10029. - if (method != NULL) {
  10030. - // If found along this branch, it was prefixed, mark as such
  10031. - method->set_is_prefixed_native();
  10032. - return method; // found
  10033. + // Try adding this prefix to the method name and see if it matches
  10034. + // another method name.
  10035. + char* prefix = prefixes[depth];
  10036. + size_t prefix_len = strlen(prefix);
  10037. + size_t trial_len = name_len + prefix_len;
  10038. + char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1);
  10039. + strcpy(trial_name_str, prefix);
  10040. + strcat(trial_name_str, name_str);
  10041. + method = search_prefix_name_space(depth+1, trial_name_str, trial_len,
  10042. + signature);
  10043. + if (method != NULL) {
  10044. + // If found along this branch, it was prefixed, mark as such
  10045. + method->set_is_prefixed_native();
  10046. + return method; // found
  10047. + }
  10048. }
  10049. }
  10050. }
  10051. - }
  10052. - return NULL; // This whole branch bore nothing
  10053. + return NULL; // This whole branch bore nothing
  10054. }
  10055. // Return the method name with old prefixes stripped away.
  10056. @@ -3042,10 +3234,10 @@
  10057. ResourceMark rm;
  10058. char* name_str = method_name_without_prefixes(method);
  10059. return search_prefix_name_space(0, name_str, strlen(name_str),
  10060. - method->signature());
  10061. + method->signature());
  10062. }
  10063. - public:
  10064. +public:
  10065. // Construct a native method transfer processor for this class.
  10066. TransferNativeFunctionRegistration(instanceKlassHandle _the_class) {
  10067. @@ -3056,9 +3248,9 @@
  10068. }
  10069. // Attempt to transfer any of the old or deleted methods that are native
  10070. - void transfer_registrations(methodOop* old_methods, int methods_length) {
  10071. + void transfer_registrations(instanceKlassHandle old_klass, int* old_methods, int methods_length) {
  10072. for (int j = 0; j < methods_length; j++) {
  10073. - methodOop old_method = old_methods[j];
  10074. + methodOop old_method = (methodOop)old_klass->methods()->obj_at(old_methods[j]);
  10075. if (old_method->is_native() && old_method->has_native_function()) {
  10076. methodOop new_method = strip_and_search_for_new_native(old_method);
  10077. @@ -3067,7 +3259,9 @@
  10078. // Redefine does not send events (except CFLH), certainly not this
  10079. // behind the scenes re-registration.
  10080. new_method->set_native_function(old_method->native_function(),
  10081. - !methodOopDesc::native_bind_event_is_interesting);
  10082. + !methodOopDesc::native_bind_event_is_interesting);
  10083. +
  10084. + RC_TRACE(0x00008000, ("Transferring native function for method %s", old_method->name()->as_C_string()));
  10085. }
  10086. }
  10087. }
  10088. @@ -3075,544 +3269,8 @@
  10089. };
  10090. // Don't lose the association between a native method and its JNI function.
  10091. -void VM_RedefineClasses::transfer_old_native_function_registrations(instanceKlassHandle the_class) {
  10092. - TransferNativeFunctionRegistration transfer(the_class);
  10093. - transfer.transfer_registrations(_deleted_methods, _deleted_methods_length);
  10094. - transfer.transfer_registrations(_matching_old_methods, _matching_methods_length);
  10095. -}
  10096. -
  10097. -// Deoptimize all compiled code that depends on this class.
  10098. -//
  10099. -// If the can_redefine_classes capability is obtained in the onload
  10100. -// phase then the compiler has recorded all dependencies from startup.
  10101. -// In that case we need only deoptimize and throw away all compiled code
  10102. -// that depends on the class.
  10103. -//
  10104. -// If can_redefine_classes is obtained sometime after the onload
  10105. -// phase then the dependency information may be incomplete. In that case
  10106. -// the first call to RedefineClasses causes all compiled code to be
  10107. -// thrown away. As can_redefine_classes has been obtained then
  10108. -// all future compilations will record dependencies so second and
  10109. -// subsequent calls to RedefineClasses need only throw away code
  10110. -// that depends on the class.
  10111. -//
  10112. -void VM_RedefineClasses::flush_dependent_code(instanceKlassHandle k_h, TRAPS) {
  10113. - assert_locked_or_safepoint(Compile_lock);
  10114. -
  10115. - // All dependencies have been recorded from startup or this is a second or
  10116. - // subsequent use of RedefineClasses
  10117. - if (JvmtiExport::all_dependencies_are_recorded()) {
  10118. - Universe::flush_evol_dependents_on(k_h);
  10119. - } else {
  10120. - CodeCache::mark_all_nmethods_for_deoptimization();
  10121. -
  10122. - ResourceMark rm(THREAD);
  10123. - DeoptimizationMarker dm;
  10124. -
  10125. - // Deoptimize all activations depending on marked nmethods
  10126. - Deoptimization::deoptimize_dependents();
  10127. -
  10128. - // Make the dependent methods not entrant (in VM_Deoptimize they are made zombies)
  10129. - CodeCache::make_marked_nmethods_not_entrant();
  10130. -
  10131. - // From now on we know that the dependency information is complete
  10132. - JvmtiExport::set_all_dependencies_are_recorded(true);
  10133. - }
  10134. -}
  10135. -
  10136. -void VM_RedefineClasses::compute_added_deleted_matching_methods() {
  10137. - methodOop old_method;
  10138. - methodOop new_method;
  10139. -
  10140. - _matching_old_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  10141. - _matching_new_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  10142. - _added_methods = NEW_RESOURCE_ARRAY(methodOop, _new_methods->length());
  10143. - _deleted_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  10144. -
  10145. - _matching_methods_length = 0;
  10146. - _deleted_methods_length = 0;
  10147. - _added_methods_length = 0;
  10148. -
  10149. - int nj = 0;
  10150. - int oj = 0;
  10151. - while (true) {
  10152. - if (oj >= _old_methods->length()) {
  10153. - if (nj >= _new_methods->length()) {
  10154. - break; // we've looked at everything, done
  10155. - }
  10156. - // New method at the end
  10157. - new_method = (methodOop) _new_methods->obj_at(nj);
  10158. - _added_methods[_added_methods_length++] = new_method;
  10159. - ++nj;
  10160. - } else if (nj >= _new_methods->length()) {
  10161. - // Old method, at the end, is deleted
  10162. - old_method = (methodOop) _old_methods->obj_at(oj);
  10163. - _deleted_methods[_deleted_methods_length++] = old_method;
  10164. - ++oj;
  10165. - } else {
  10166. - old_method = (methodOop) _old_methods->obj_at(oj);
  10167. - new_method = (methodOop) _new_methods->obj_at(nj);
  10168. - if (old_method->name() == new_method->name()) {
  10169. - if (old_method->signature() == new_method->signature()) {
  10170. - _matching_old_methods[_matching_methods_length ] = old_method;
  10171. - _matching_new_methods[_matching_methods_length++] = new_method;
  10172. - ++nj;
  10173. - ++oj;
  10174. - } else {
  10175. - // added overloaded have already been moved to the end,
  10176. - // so this is a deleted overloaded method
  10177. - _deleted_methods[_deleted_methods_length++] = old_method;
  10178. - ++oj;
  10179. - }
  10180. - } else { // names don't match
  10181. - if (old_method->name()->fast_compare(new_method->name()) > 0) {
  10182. - // new method
  10183. - _added_methods[_added_methods_length++] = new_method;
  10184. - ++nj;
  10185. - } else {
  10186. - // deleted method
  10187. - _deleted_methods[_deleted_methods_length++] = old_method;
  10188. - ++oj;
  10189. - }
  10190. - }
  10191. - }
  10192. - }
  10193. - assert(_matching_methods_length + _deleted_methods_length == _old_methods->length(), "sanity");
  10194. - assert(_matching_methods_length + _added_methods_length == _new_methods->length(), "sanity");
  10195. -}
  10196. -
  10197. -
  10198. -
  10199. -// Install the redefinition of a class:
  10200. -// - house keeping (flushing breakpoints and caches, deoptimizing
  10201. -// dependent compiled code)
  10202. -// - replacing parts in the_class with parts from scratch_class
  10203. -// - adding a weak reference to track the obsolete but interesting
  10204. -// parts of the_class
  10205. -// - adjusting constant pool caches and vtables in other classes
  10206. -// that refer to methods in the_class. These adjustments use the
  10207. -// SystemDictionary::classes_do() facility which only allows
  10208. -// a helper method to be specified. The interesting parameters
  10209. -// that we would like to pass to the helper method are saved in
  10210. -// static global fields in the VM operation.
  10211. -void VM_RedefineClasses::redefine_single_class(jclass the_jclass,
  10212. - instanceKlassHandle scratch_class, TRAPS) {
  10213. -
  10214. - RC_TIMER_START(_timer_rsc_phase1);
  10215. -
  10216. - oop the_class_mirror = JNIHandles::resolve_non_null(the_jclass);
  10217. - klassOop the_class_oop = java_lang_Class::as_klassOop(the_class_mirror);
  10218. - instanceKlassHandle the_class = instanceKlassHandle(THREAD, the_class_oop);
  10219. -
  10220. - // Remove all breakpoints in methods of this class
  10221. - JvmtiBreakpoints& jvmti_breakpoints = JvmtiCurrentBreakpoints::get_jvmti_breakpoints();
  10222. - jvmti_breakpoints.clearall_in_class_at_safepoint(the_class_oop);
  10223. -
  10224. - if (the_class_oop == Universe::reflect_invoke_cache()->klass()) {
  10225. - // We are redefining java.lang.reflect.Method. Method.invoke() is
  10226. - // cached and users of the cache care about each active version of
  10227. - // the method so we have to track this previous version.
  10228. - // Do this before methods get switched
  10229. - Universe::reflect_invoke_cache()->add_previous_version(
  10230. - the_class->method_with_idnum(Universe::reflect_invoke_cache()->method_idnum()));
  10231. - }
  10232. -
  10233. - // Deoptimize all compiled code that depends on this class
  10234. - flush_dependent_code(the_class, THREAD);
  10235. -
  10236. - _old_methods = the_class->methods();
  10237. - _new_methods = scratch_class->methods();
  10238. - _the_class_oop = the_class_oop;
  10239. - compute_added_deleted_matching_methods();
  10240. - update_jmethod_ids();
  10241. -
  10242. - // Attach new constant pool to the original klass. The original
  10243. - // klass still refers to the old constant pool (for now).
  10244. - scratch_class->constants()->set_pool_holder(the_class());
  10245. -
  10246. -#if 0
  10247. - // In theory, with constant pool merging in place we should be able
  10248. - // to save space by using the new, merged constant pool in place of
  10249. - // the old constant pool(s). By "pool(s)" I mean the constant pool in
  10250. - // the klass version we are replacing now and any constant pool(s) in
  10251. - // previous versions of klass. Nice theory, doesn't work in practice.
  10252. - // When this code is enabled, even simple programs throw NullPointer
  10253. - // exceptions. I'm guessing that this is caused by some constant pool
  10254. - // cache difference between the new, merged constant pool and the
  10255. - // constant pool that was just being used by the klass. I'm keeping
  10256. - // this code around to archive the idea, but the code has to remain
  10257. - // disabled for now.
  10258. -
  10259. - // Attach each old method to the new constant pool. This can be
  10260. - // done here since we are past the bytecode verification and
  10261. - // constant pool optimization phases.
  10262. - for (int i = _old_methods->length() - 1; i >= 0; i--) {
  10263. - methodOop method = (methodOop)_old_methods->obj_at(i);
  10264. - method->set_constants(scratch_class->constants());
  10265. - }
  10266. -
  10267. - {
  10268. - // walk all previous versions of the klass
  10269. - instanceKlass *ik = (instanceKlass *)the_class()->klass_part();
  10270. - PreviousVersionWalker pvw(ik);
  10271. - instanceKlassHandle ikh;
  10272. - do {
  10273. - ikh = pvw.next_previous_version();
  10274. - if (!ikh.is_null()) {
  10275. - ik = ikh();
  10276. -
  10277. - // attach previous version of klass to the new constant pool
  10278. - ik->set_constants(scratch_class->constants());
  10279. -
  10280. - // Attach each method in the previous version of klass to the
  10281. - // new constant pool
  10282. - objArrayOop prev_methods = ik->methods();
  10283. - for (int i = prev_methods->length() - 1; i >= 0; i--) {
  10284. - methodOop method = (methodOop)prev_methods->obj_at(i);
  10285. - method->set_constants(scratch_class->constants());
  10286. - }
  10287. - }
  10288. - } while (!ikh.is_null());
  10289. - }
  10290. -#endif
  10291. -
  10292. - // Replace methods and constantpool
  10293. - the_class->set_methods(_new_methods);
  10294. - scratch_class->set_methods(_old_methods); // To prevent potential GCing of the old methods,
  10295. - // and to be able to undo operation easily.
  10296. -
  10297. - constantPoolOop old_constants = the_class->constants();
  10298. - the_class->set_constants(scratch_class->constants());
  10299. - scratch_class->set_constants(old_constants); // See the previous comment.
  10300. -#if 0
  10301. - // We are swapping the guts of "the new class" with the guts of "the
  10302. - // class". Since the old constant pool has just been attached to "the
  10303. - // new class", it seems logical to set the pool holder in the old
  10304. - // constant pool also. However, doing this will change the observable
  10305. - // class hierarchy for any old methods that are still executing. A
  10306. - // method can query the identity of its "holder" and this query uses
  10307. - // the method's constant pool link to find the holder. The change in
  10308. - // holding class from "the class" to "the new class" can confuse
  10309. - // things.
  10310. - //
  10311. - // Setting the old constant pool's holder will also cause
  10312. - // verification done during vtable initialization below to fail.
  10313. - // During vtable initialization, the vtable's class is verified to be
  10314. - // a subtype of the method's holder. The vtable's class is "the
  10315. - // class" and the method's holder is gotten from the constant pool
  10316. - // link in the method itself. For "the class"'s directly implemented
  10317. - // methods, the method holder is "the class" itself (as gotten from
  10318. - // the new constant pool). The check works fine in this case. The
  10319. - // check also works fine for methods inherited from super classes.
  10320. - //
  10321. - // Miranda methods are a little more complicated. A miranda method is
  10322. - // provided by an interface when the class implementing the interface
  10323. - // does not provide its own method. These interfaces are implemented
  10324. - // internally as an instanceKlass. These special instanceKlasses
  10325. - // share the constant pool of the class that "implements" the
  10326. - // interface. By sharing the constant pool, the method holder of a
  10327. - // miranda method is the class that "implements" the interface. In a
  10328. - // non-redefine situation, the subtype check works fine. However, if
  10329. - // the old constant pool's pool holder is modified, then the check
  10330. - // fails because there is no class hierarchy relationship between the
  10331. - // vtable's class and "the new class".
  10332. -
  10333. - old_constants->set_pool_holder(scratch_class());
  10334. -#endif
  10335. -
  10336. - // track which methods are EMCP for add_previous_version() call below
  10337. - BitMap emcp_methods(_old_methods->length());
  10338. - int emcp_method_count = 0;
  10339. - emcp_methods.clear(); // clears 0..(length() - 1)
  10340. - check_methods_and_mark_as_obsolete(&emcp_methods, &emcp_method_count);
  10341. - transfer_old_native_function_registrations(the_class);
  10342. -
  10343. - // The class file bytes from before any retransformable agents mucked
  10344. - // with them was cached on the scratch class, move to the_class.
  10345. - // Note: we still want to do this if nothing needed caching since it
  10346. - // should get cleared in the_class too.
  10347. - if (the_class->get_cached_class_file_bytes() == 0) {
  10348. - // the_class doesn't have a cache yet so copy it
  10349. - the_class->set_cached_class_file(
  10350. - scratch_class->get_cached_class_file_bytes(),
  10351. - scratch_class->get_cached_class_file_len());
  10352. - }
  10353. -#ifndef PRODUCT
  10354. - else {
  10355. - assert(the_class->get_cached_class_file_bytes() ==
  10356. - scratch_class->get_cached_class_file_bytes(), "cache ptrs must match");
  10357. - assert(the_class->get_cached_class_file_len() ==
  10358. - scratch_class->get_cached_class_file_len(), "cache lens must match");
  10359. - }
  10360. -#endif
  10361. -
  10362. - // Replace inner_classes
  10363. - typeArrayOop old_inner_classes = the_class->inner_classes();
  10364. - the_class->set_inner_classes(scratch_class->inner_classes());
  10365. - scratch_class->set_inner_classes(old_inner_classes);
  10366. -
  10367. - // Initialize the vtable and interface table after
  10368. - // methods have been rewritten
  10369. - {
  10370. - ResourceMark rm(THREAD);
  10371. - // no exception should happen here since we explicitly
  10372. - // do not check loader constraints.
  10373. - // compare_and_normalize_class_versions has already checked:
  10374. - // - classloaders unchanged, signatures unchanged
  10375. - // - all instanceKlasses for redefined classes reused & contents updated
  10376. - the_class->vtable()->initialize_vtable(false, THREAD);
  10377. - the_class->itable()->initialize_itable(false, THREAD);
  10378. - assert(!HAS_PENDING_EXCEPTION || (THREAD->pending_exception()->is_a(SystemDictionary::ThreadDeath_klass())), "redefine exception");
  10379. - }
  10380. -
  10381. - // Leave arrays of jmethodIDs and itable index cache unchanged
  10382. -
  10383. - // Copy the "source file name" attribute from new class version
  10384. - the_class->set_source_file_name(scratch_class->source_file_name());
  10385. -
  10386. - // Copy the "source debug extension" attribute from new class version
  10387. - the_class->set_source_debug_extension(
  10388. - scratch_class->source_debug_extension(),
  10389. - scratch_class->source_debug_extension() == NULL ? 0 :
  10390. - (int)strlen(scratch_class->source_debug_extension()));
  10391. -
  10392. - // Use of javac -g could be different in the old and the new
  10393. - if (scratch_class->access_flags().has_localvariable_table() !=
  10394. - the_class->access_flags().has_localvariable_table()) {
  10395. -
  10396. - AccessFlags flags = the_class->access_flags();
  10397. - if (scratch_class->access_flags().has_localvariable_table()) {
  10398. - flags.set_has_localvariable_table();
  10399. - } else {
  10400. - flags.clear_has_localvariable_table();
  10401. - }
  10402. - the_class->set_access_flags(flags);
  10403. - }
  10404. -
  10405. - // Replace class annotation fields values
  10406. - typeArrayOop old_class_annotations = the_class->class_annotations();
  10407. - the_class->set_class_annotations(scratch_class->class_annotations());
  10408. - scratch_class->set_class_annotations(old_class_annotations);
  10409. -
  10410. - // Replace fields annotation fields values
  10411. - objArrayOop old_fields_annotations = the_class->fields_annotations();
  10412. - the_class->set_fields_annotations(scratch_class->fields_annotations());
  10413. - scratch_class->set_fields_annotations(old_fields_annotations);
  10414. -
  10415. - // Replace methods annotation fields values
  10416. - objArrayOop old_methods_annotations = the_class->methods_annotations();
  10417. - the_class->set_methods_annotations(scratch_class->methods_annotations());
  10418. - scratch_class->set_methods_annotations(old_methods_annotations);
  10419. -
  10420. - // Replace methods parameter annotation fields values
  10421. - objArrayOop old_methods_parameter_annotations =
  10422. - the_class->methods_parameter_annotations();
  10423. - the_class->set_methods_parameter_annotations(
  10424. - scratch_class->methods_parameter_annotations());
  10425. - scratch_class->set_methods_parameter_annotations(old_methods_parameter_annotations);
  10426. -
  10427. - // Replace methods default annotation fields values
  10428. - objArrayOop old_methods_default_annotations =
  10429. - the_class->methods_default_annotations();
  10430. - the_class->set_methods_default_annotations(
  10431. - scratch_class->methods_default_annotations());
  10432. - scratch_class->set_methods_default_annotations(old_methods_default_annotations);
  10433. -
  10434. - // Replace minor version number of class file
  10435. - u2 old_minor_version = the_class->minor_version();
  10436. - the_class->set_minor_version(scratch_class->minor_version());
  10437. - scratch_class->set_minor_version(old_minor_version);
  10438. -
  10439. - // Replace major version number of class file
  10440. - u2 old_major_version = the_class->major_version();
  10441. - the_class->set_major_version(scratch_class->major_version());
  10442. - scratch_class->set_major_version(old_major_version);
  10443. -
  10444. - // Replace CP indexes for class and name+type of enclosing method
  10445. - u2 old_class_idx = the_class->enclosing_method_class_index();
  10446. - u2 old_method_idx = the_class->enclosing_method_method_index();
  10447. - the_class->set_enclosing_method_indices(
  10448. - scratch_class->enclosing_method_class_index(),
  10449. - scratch_class->enclosing_method_method_index());
  10450. - scratch_class->set_enclosing_method_indices(old_class_idx, old_method_idx);
  10451. -
  10452. - // keep track of previous versions of this class
  10453. - the_class->add_previous_version(scratch_class, &emcp_methods,
  10454. - emcp_method_count);
  10455. -
  10456. - RC_TIMER_STOP(_timer_rsc_phase1);
  10457. - RC_TIMER_START(_timer_rsc_phase2);
  10458. -
  10459. - // Adjust constantpool caches and vtables for all classes
  10460. - // that reference methods of the evolved class.
  10461. - SystemDictionary::classes_do(adjust_cpool_cache_and_vtable, THREAD);
  10462. -
  10463. - // JSR-292 support
  10464. - MemberNameTable* mnt = the_class->member_names();
  10465. - if (mnt != NULL) {
  10466. - bool trace_name_printed = false;
  10467. - mnt->adjust_method_entries(_matching_old_methods,
  10468. - _matching_new_methods,
  10469. - _matching_methods_length,
  10470. - &trace_name_printed);
  10471. - }
  10472. -
  10473. - if (the_class->oop_map_cache() != NULL) {
  10474. - // Flush references to any obsolete methods from the oop map cache
  10475. - // so that obsolete methods are not pinned.
  10476. - the_class->oop_map_cache()->flush_obsolete_entries();
  10477. - }
  10478. -
  10479. - // increment the classRedefinedCount field in the_class and in any
  10480. - // direct and indirect subclasses of the_class
  10481. - increment_class_counter((instanceKlass *)the_class()->klass_part(), THREAD);
  10482. -
  10483. - // RC_TRACE macro has an embedded ResourceMark
  10484. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  10485. - ("redefined name=%s, count=%d (avail_mem=" UINT64_FORMAT "K)",
  10486. - the_class->external_name(),
  10487. - java_lang_Class::classRedefinedCount(the_class_mirror),
  10488. - os::available_memory() >> 10));
  10489. -
  10490. - RC_TIMER_STOP(_timer_rsc_phase2);
  10491. -} // end redefine_single_class()
  10492. -
  10493. -
  10494. -// Increment the classRedefinedCount field in the specific instanceKlass
  10495. -// and in all direct and indirect subclasses.
  10496. -void VM_RedefineClasses::increment_class_counter(instanceKlass *ik, TRAPS) {
  10497. - oop class_mirror = ik->java_mirror();
  10498. - klassOop class_oop = java_lang_Class::as_klassOop(class_mirror);
  10499. - int new_count = java_lang_Class::classRedefinedCount(class_mirror) + 1;
  10500. - java_lang_Class::set_classRedefinedCount(class_mirror, new_count);
  10501. -
  10502. - if (class_oop != _the_class_oop) {
  10503. - // _the_class_oop count is printed at end of redefine_single_class()
  10504. - RC_TRACE_WITH_THREAD(0x00000008, THREAD,
  10505. - ("updated count in subclass=%s to %d", ik->external_name(), new_count));
  10506. - }
  10507. -
  10508. - for (Klass *subk = ik->subklass(); subk != NULL;
  10509. - subk = subk->next_sibling()) {
  10510. - if (subk->oop_is_instance()) {
  10511. - // Only update instanceKlasses
  10512. - instanceKlass *subik = (instanceKlass*)subk;
  10513. - // recursively do subclasses of the current subclass
  10514. - increment_class_counter(subik, THREAD);
  10515. - }
  10516. - }
  10517. -}
  10518. -
  10519. -void VM_RedefineClasses::check_class(klassOop k_oop,
  10520. - oop initiating_loader, TRAPS) {
  10521. - Klass *k = k_oop->klass_part();
  10522. - if (k->oop_is_instance()) {
  10523. - HandleMark hm(THREAD);
  10524. - instanceKlass *ik = (instanceKlass *) k;
  10525. - bool no_old_methods = true; // be optimistic
  10526. - ResourceMark rm(THREAD);
  10527. -
  10528. - // a vtable should never contain old or obsolete methods
  10529. - if (ik->vtable_length() > 0 &&
  10530. - !ik->vtable()->check_no_old_or_obsolete_entries()) {
  10531. - if (RC_TRACE_ENABLED(0x00004000)) {
  10532. - RC_TRACE_WITH_THREAD(0x00004000, THREAD,
  10533. - ("klassVtable::check_no_old_or_obsolete_entries failure"
  10534. - " -- OLD or OBSOLETE method found -- class: %s",
  10535. - ik->signature_name()));
  10536. - ik->vtable()->dump_vtable();
  10537. - }
  10538. - no_old_methods = false;
  10539. - }
  10540. -
  10541. - // an itable should never contain old or obsolete methods
  10542. - if (ik->itable_length() > 0 &&
  10543. - !ik->itable()->check_no_old_or_obsolete_entries()) {
  10544. - if (RC_TRACE_ENABLED(0x00004000)) {
  10545. - RC_TRACE_WITH_THREAD(0x00004000, THREAD,
  10546. - ("klassItable::check_no_old_or_obsolete_entries failure"
  10547. - " -- OLD or OBSOLETE method found -- class: %s",
  10548. - ik->signature_name()));
  10549. - ik->itable()->dump_itable();
  10550. - }
  10551. - no_old_methods = false;
  10552. - }
  10553. -
  10554. - // the constant pool cache should never contain old or obsolete methods
  10555. - if (ik->constants() != NULL &&
  10556. - ik->constants()->cache() != NULL &&
  10557. - !ik->constants()->cache()->check_no_old_or_obsolete_entries()) {
  10558. - if (RC_TRACE_ENABLED(0x00004000)) {
  10559. - RC_TRACE_WITH_THREAD(0x00004000, THREAD,
  10560. - ("cp-cache::check_no_old_or_obsolete_entries failure"
  10561. - " -- OLD or OBSOLETE method found -- class: %s",
  10562. - ik->signature_name()));
  10563. - ik->constants()->cache()->dump_cache();
  10564. - }
  10565. - no_old_methods = false;
  10566. - }
  10567. -
  10568. - if (!no_old_methods) {
  10569. - if (RC_TRACE_ENABLED(0x00004000)) {
  10570. - dump_methods();
  10571. - } else {
  10572. - tty->print_cr("INFO: use the '-XX:TraceRedefineClasses=16384' option "
  10573. - "to see more info about the following guarantee() failure.");
  10574. - }
  10575. - guarantee(false, "OLD and/or OBSOLETE method(s) found");
  10576. - }
  10577. - }
  10578. -}
  10579. -
  10580. -void VM_RedefineClasses::dump_methods() {
  10581. - int j;
  10582. - RC_TRACE(0x00004000, ("_old_methods --"));
  10583. - for (j = 0; j < _old_methods->length(); ++j) {
  10584. - methodOop m = (methodOop) _old_methods->obj_at(j);
  10585. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  10586. - m->access_flags().print_on(tty);
  10587. - tty->print(" -- ");
  10588. - m->print_name(tty);
  10589. - tty->cr();
  10590. - }
  10591. - RC_TRACE(0x00004000, ("_new_methods --"));
  10592. - for (j = 0; j < _new_methods->length(); ++j) {
  10593. - methodOop m = (methodOop) _new_methods->obj_at(j);
  10594. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  10595. - m->access_flags().print_on(tty);
  10596. - tty->print(" -- ");
  10597. - m->print_name(tty);
  10598. - tty->cr();
  10599. - }
  10600. - RC_TRACE(0x00004000, ("_matching_(old/new)_methods --"));
  10601. - for (j = 0; j < _matching_methods_length; ++j) {
  10602. - methodOop m = _matching_old_methods[j];
  10603. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  10604. - m->access_flags().print_on(tty);
  10605. - tty->print(" -- ");
  10606. - m->print_name(tty);
  10607. - tty->cr();
  10608. - m = _matching_new_methods[j];
  10609. - RC_TRACE_NO_CR(0x00004000, (" (%5d) ", m->vtable_index()));
  10610. - m->access_flags().print_on(tty);
  10611. - tty->cr();
  10612. - }
  10613. - RC_TRACE(0x00004000, ("_deleted_methods --"));
  10614. - for (j = 0; j < _deleted_methods_length; ++j) {
  10615. - methodOop m = _deleted_methods[j];
  10616. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  10617. - m->access_flags().print_on(tty);
  10618. - tty->print(" -- ");
  10619. - m->print_name(tty);
  10620. - tty->cr();
  10621. - }
  10622. - RC_TRACE(0x00004000, ("_added_methods --"));
  10623. - for (j = 0; j < _added_methods_length; ++j) {
  10624. - methodOop m = _added_methods[j];
  10625. - RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
  10626. - m->access_flags().print_on(tty);
  10627. - tty->print(" -- ");
  10628. - m->print_name(tty);
  10629. - tty->cr();
  10630. - }
  10631. +void VM_RedefineClasses::transfer_old_native_function_registrations(instanceKlassHandle old_klass) {
  10632. + TransferNativeFunctionRegistration transfer(old_klass);
  10633. + transfer.transfer_registrations(old_klass, _deleted_methods, _deleted_methods_length);
  10634. + transfer.transfer_registrations(old_klass, _matching_old_methods, _matching_methods_length);
  10635. }
  10636. diff --git a/src/share/vm/prims/jvmtiRedefineClasses.hpp b/src/share/vm/prims/jvmtiRedefineClasses.hpp
  10637. index bfac62c..d7ba79f 100644
  10638. --- a/src/share/vm/prims/jvmtiRedefineClasses.hpp
  10639. +++ b/src/share/vm/prims/jvmtiRedefineClasses.hpp
  10640. @@ -1,26 +1,29 @@
  10641. /*
  10642. - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
  10643. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  10644. - *
  10645. - * This code is free software; you can redistribute it and/or modify it
  10646. - * under the terms of the GNU General Public License version 2 only, as
  10647. - * published by the Free Software Foundation.
  10648. - *
  10649. - * This code is distributed in the hope that it will be useful, but WITHOUT
  10650. - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10651. - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  10652. - * version 2 for more details (a copy is included in the LICENSE file that
  10653. - * accompanied this code).
  10654. - *
  10655. - * You should have received a copy of the GNU General Public License version
  10656. - * 2 along with this work; if not, write to the Free Software Foundation,
  10657. - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  10658. - *
  10659. - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  10660. - * or visit www.oracle.com if you need additional information or have any
  10661. - * questions.
  10662. - *
  10663. - */
  10664. +* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  10665. +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  10666. +*
  10667. +* This code is free software; you can redistribute it and/or modify it
  10668. +* under the terms of the GNU General Public License version 2 only, as
  10669. +* published by the Free Software Foundation.
  10670. +*
  10671. +* This code is distributed in the hope that it will be useful, but WITHOUT
  10672. +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10673. +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  10674. +* version 2 for more details (a copy is included in the LICENSE file that
  10675. +* accompanied this code).
  10676. +*
  10677. +* You should have received a copy of the GNU General Public License version
  10678. +* 2 along with this work; if not, write to the Free Software Foundation,
  10679. +* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  10680. +*
  10681. +* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  10682. +* or visit www.oracle.com if you need additional information or have any
  10683. +* questions.
  10684. +*
  10685. +*/
  10686. +
  10687. +// New version that allows arbitrary changes to already loaded classes.
  10688. +// Modifications done by: Thomas Wuerthinger <thomas.wuerthinger@gmail.com>
  10689. #ifndef SHARE_VM_PRIMS_JVMTIREDEFINECLASSES_HPP
  10690. #define SHARE_VM_PRIMS_JVMTIREDEFINECLASSES_HPP
  10691. @@ -32,330 +35,27 @@
  10692. #include "oops/objArrayOop.hpp"
  10693. #include "prims/jvmtiRedefineClassesTrace.hpp"
  10694. #include "runtime/vm_operations.hpp"
  10695. +#include "gc_implementation/shared/vmGCOperations.hpp"
  10696. -// Introduction:
  10697. -//
  10698. -// The RedefineClasses() API is used to change the definition of one or
  10699. -// more classes. While the API supports redefining more than one class
  10700. -// in a single call, in general, the API is discussed in the context of
  10701. -// changing the definition of a single current class to a single new
  10702. -// class. For clarity, the current class is will always be called
  10703. -// "the_class" and the new class will always be called "scratch_class".
  10704. -//
  10705. -// The name "the_class" is used because there is only one structure
  10706. -// that represents a specific class; redefinition does not replace the
  10707. -// structure, but instead replaces parts of the structure. The name
  10708. -// "scratch_class" is used because the structure that represents the
  10709. -// new definition of a specific class is simply used to carry around
  10710. -// the parts of the new definition until they are used to replace the
  10711. -// appropriate parts in the_class. Once redefinition of a class is
  10712. -// complete, scratch_class is thrown away.
  10713. -//
  10714. -//
  10715. -// Implementation Overview:
  10716. -//
  10717. -// The RedefineClasses() API is mostly a wrapper around the VM op that
  10718. -// does the real work. The work is split in varying degrees between
  10719. -// doit_prologue(), doit() and doit_epilogue().
  10720. -//
  10721. -// 1) doit_prologue() is called by the JavaThread on the way to a
  10722. -// safepoint. It does parameter verification and loads scratch_class
  10723. -// which involves:
  10724. -// - parsing the incoming class definition using the_class' class
  10725. -// loader and security context
  10726. -// - linking scratch_class
  10727. -// - merging constant pools and rewriting bytecodes as needed
  10728. -// for the merged constant pool
  10729. -// - verifying the bytecodes in scratch_class
  10730. -// - setting up the constant pool cache and rewriting bytecodes
  10731. -// as needed to use the cache
  10732. -// - finally, scratch_class is compared to the_class to verify
  10733. -// that it is a valid replacement class
  10734. -// - if everything is good, then scratch_class is saved in an
  10735. -// instance field in the VM operation for the doit() call
  10736. -//
  10737. -// Note: A JavaThread must do the above work.
  10738. -//
  10739. -// 2) doit() is called by the VMThread during a safepoint. It installs
  10740. -// the new class definition(s) which involves:
  10741. -// - retrieving the scratch_class from the instance field in the
  10742. -// VM operation
  10743. -// - house keeping (flushing breakpoints and caches, deoptimizing
  10744. -// dependent compiled code)
  10745. -// - replacing parts in the_class with parts from scratch_class
  10746. -// - adding weak reference(s) to track the obsolete but interesting
  10747. -// parts of the_class
  10748. -// - adjusting constant pool caches and vtables in other classes
  10749. -// that refer to methods in the_class. These adjustments use the
  10750. -// SystemDictionary::classes_do() facility which only allows
  10751. -// a helper method to be specified. The interesting parameters
  10752. -// that we would like to pass to the helper method are saved in
  10753. -// static global fields in the VM operation.
  10754. -// - telling the SystemDictionary to notice our changes
  10755. -//
  10756. -// Note: the above work must be done by the VMThread to be safe.
  10757. -//
  10758. -// 3) doit_epilogue() is called by the JavaThread after the VM op
  10759. -// is finished and the safepoint is done. It simply cleans up
  10760. -// memory allocated in doit_prologue() and used in doit().
  10761. -//
  10762. -//
  10763. -// Constant Pool Details:
  10764. -//
  10765. -// When the_class is redefined, we cannot just replace the constant
  10766. -// pool in the_class with the constant pool from scratch_class because
  10767. -// that could confuse obsolete methods that may still be running.
  10768. -// Instead, the constant pool from the_class, old_cp, is merged with
  10769. -// the constant pool from scratch_class, scratch_cp. The resulting
  10770. -// constant pool, merge_cp, replaces old_cp in the_class.
  10771. -//
  10772. -// The key part of any merging algorithm is the entry comparison
  10773. -// function so we have to know the types of entries in a constant pool
  10774. -// in order to merge two of them together. Constant pools can contain
  10775. -// up to 12 different kinds of entries; the JVM_CONSTANT_Unicode entry
  10776. -// is not presently used so we only have to worry about the other 11
  10777. -// entry types. For the purposes of constant pool merging, it is
  10778. -// helpful to know that the 11 entry types fall into 3 different
  10779. -// subtypes: "direct", "indirect" and "double-indirect".
  10780. -//
  10781. -// Direct CP entries contain data and do not contain references to
  10782. -// other CP entries. The following are direct CP entries:
  10783. -// JVM_CONSTANT_{Double,Float,Integer,Long,Utf8}
  10784. -//
  10785. -// Indirect CP entries contain 1 or 2 references to a direct CP entry
  10786. -// and no other data. The following are indirect CP entries:
  10787. -// JVM_CONSTANT_{Class,NameAndType,String}
  10788. -//
  10789. -// Double-indirect CP entries contain two references to indirect CP
  10790. -// entries and no other data. The following are double-indirect CP
  10791. -// entries:
  10792. -// JVM_CONSTANT_{Fieldref,InterfaceMethodref,Methodref}
  10793. -//
  10794. -// When comparing entries between two constant pools, the entry types
  10795. -// are compared first and if they match, then further comparisons are
  10796. -// made depending on the entry subtype. Comparing direct CP entries is
  10797. -// simply a matter of comparing the data associated with each entry.
  10798. -// Comparing both indirect and double-indirect CP entries requires
  10799. -// recursion.
  10800. -//
  10801. -// Fortunately, the recursive combinations are limited because indirect
  10802. -// CP entries can only refer to direct CP entries and double-indirect
  10803. -// CP entries can only refer to indirect CP entries. The following is
  10804. -// an example illustration of the deepest set of indirections needed to
  10805. -// access the data associated with a JVM_CONSTANT_Fieldref entry:
  10806. -//
  10807. -// JVM_CONSTANT_Fieldref {
  10808. -// class_index => JVM_CONSTANT_Class {
  10809. -// name_index => JVM_CONSTANT_Utf8 {
  10810. -// <data-1>
  10811. -// }
  10812. -// }
  10813. -// name_and_type_index => JVM_CONSTANT_NameAndType {
  10814. -// name_index => JVM_CONSTANT_Utf8 {
  10815. -// <data-2>
  10816. -// }
  10817. -// descriptor_index => JVM_CONSTANT_Utf8 {
  10818. -// <data-3>
  10819. -// }
  10820. -// }
  10821. -// }
  10822. -//
  10823. -// The above illustration is not a data structure definition for any
  10824. -// computer language. The curly braces ('{' and '}') are meant to
  10825. -// delimit the context of the "fields" in the CP entry types shown.
  10826. -// Each indirection from the JVM_CONSTANT_Fieldref entry is shown via
  10827. -// "=>", e.g., the class_index is used to indirectly reference a
  10828. -// JVM_CONSTANT_Class entry where the name_index is used to indirectly
  10829. -// reference a JVM_CONSTANT_Utf8 entry which contains the interesting
  10830. -// <data-1>. In order to understand a JVM_CONSTANT_Fieldref entry, we
  10831. -// have to do a total of 5 indirections just to get to the CP entries
  10832. -// that contain the interesting pieces of data and then we have to
  10833. -// fetch the three pieces of data. This means we have to do a total of
  10834. -// (5 + 3) * 2 == 16 dereferences to compare two JVM_CONSTANT_Fieldref
  10835. -// entries.
  10836. -//
  10837. -// Here is the indirection, data and dereference count for each entry
  10838. -// type:
  10839. -//
  10840. -// JVM_CONSTANT_Class 1 indir, 1 data, 2 derefs
  10841. -// JVM_CONSTANT_Double 0 indir, 1 data, 1 deref
  10842. -// JVM_CONSTANT_Fieldref 2 indir, 3 data, 8 derefs
  10843. -// JVM_CONSTANT_Float 0 indir, 1 data, 1 deref
  10844. -// JVM_CONSTANT_Integer 0 indir, 1 data, 1 deref
  10845. -// JVM_CONSTANT_InterfaceMethodref 2 indir, 3 data, 8 derefs
  10846. -// JVM_CONSTANT_Long 0 indir, 1 data, 1 deref
  10847. -// JVM_CONSTANT_Methodref 2 indir, 3 data, 8 derefs
  10848. -// JVM_CONSTANT_NameAndType 1 indir, 2 data, 4 derefs
  10849. -// JVM_CONSTANT_String 1 indir, 1 data, 2 derefs
  10850. -// JVM_CONSTANT_Utf8 0 indir, 1 data, 1 deref
  10851. -//
  10852. -// So different subtypes of CP entries require different amounts of
  10853. -// work for a proper comparison.
  10854. -//
  10855. -// Now that we've talked about the different entry types and how to
  10856. -// compare them we need to get back to merging. This is not a merge in
  10857. -// the "sort -u" sense or even in the "sort" sense. When we merge two
  10858. -// constant pools, we copy all the entries from old_cp to merge_cp,
  10859. -// preserving entry order. Next we append all the unique entries from
  10860. -// scratch_cp to merge_cp and we track the index changes from the
  10861. -// location in scratch_cp to the possibly new location in merge_cp.
  10862. -// When we are done, any obsolete code that is still running that
  10863. -// uses old_cp should not be able to observe any difference if it
  10864. -// were to use merge_cp. As for the new code in scratch_class, it is
  10865. -// modified to use the appropriate index values in merge_cp before it
  10866. -// is used to replace the code in the_class.
  10867. -//
  10868. -// There is one small complication in copying the entries from old_cp
  10869. -// to merge_cp. Two of the CP entry types are special in that they are
  10870. -// lazily resolved. Before explaining the copying complication, we need
  10871. -// to digress into CP entry resolution.
  10872. -//
  10873. -// JVM_CONSTANT_Class and JVM_CONSTANT_String entries are present in
  10874. -// the class file, but are not stored in memory as such until they are
  10875. -// resolved. The entries are not resolved unless they are used because
  10876. -// resolution is expensive. During class file parsing the entries are
  10877. -// initially stored in memory as JVM_CONSTANT_ClassIndex and
  10878. -// JVM_CONSTANT_StringIndex entries. These special CP entry types
  10879. -// indicate that the JVM_CONSTANT_Class and JVM_CONSTANT_String entries
  10880. -// have been parsed, but the index values in the entries have not been
  10881. -// validated. After the entire constant pool has been parsed, the index
  10882. -// values can be validated and then the entries are converted into
  10883. -// JVM_CONSTANT_UnresolvedClass and JVM_CONSTANT_UnresolvedString
  10884. -// entries. During this conversion process, the UTF8 values that are
  10885. -// indirectly referenced by the JVM_CONSTANT_ClassIndex and
  10886. -// JVM_CONSTANT_StringIndex entries are changed into Symbol*s and the
  10887. -// entries are modified to refer to the Symbol*s. This optimization
  10888. -// eliminates one level of indirection for those two CP entry types and
  10889. -// gets the entries ready for verification. During class file parsing
  10890. -// it is also possible for JVM_CONSTANT_UnresolvedString entries to be
  10891. -// resolved into JVM_CONSTANT_String entries. Verification expects to
  10892. -// find JVM_CONSTANT_UnresolvedClass and either JVM_CONSTANT_String or
  10893. -// JVM_CONSTANT_UnresolvedString entries and not JVM_CONSTANT_Class
  10894. -// entries.
  10895. -//
  10896. -// Now we can get back to the copying complication. When we copy
  10897. -// entries from old_cp to merge_cp, we have to revert any
  10898. -// JVM_CONSTANT_Class entries to JVM_CONSTANT_UnresolvedClass entries
  10899. -// or verification will fail.
  10900. -//
  10901. -// It is important to explicitly state that the merging algorithm
  10902. -// effectively unresolves JVM_CONSTANT_Class entries that were in the
  10903. -// old_cp when they are changed into JVM_CONSTANT_UnresolvedClass
  10904. -// entries in the merge_cp. This is done both to make verification
  10905. -// happy and to avoid adding more brittleness between RedefineClasses
  10906. -// and the constant pool cache. By allowing the constant pool cache
  10907. -// implementation to (re)resolve JVM_CONSTANT_UnresolvedClass entries
  10908. -// into JVM_CONSTANT_Class entries, we avoid having to embed knowledge
  10909. -// about those algorithms in RedefineClasses.
  10910. -//
  10911. -// Appending unique entries from scratch_cp to merge_cp is straight
  10912. -// forward for direct CP entries and most indirect CP entries. For the
  10913. -// indirect CP entry type JVM_CONSTANT_NameAndType and for the double-
  10914. -// indirect CP entry types, the presence of more than one piece of
  10915. -// interesting data makes appending the entries more complicated.
  10916. -//
  10917. -// For the JVM_CONSTANT_{Double,Float,Integer,Long,Utf8} entry types,
  10918. -// the entry is simply copied from scratch_cp to the end of merge_cp.
  10919. -// If the index in scratch_cp is different than the destination index
  10920. -// in merge_cp, then the change in index value is tracked.
  10921. -//
  10922. -// Note: the above discussion for the direct CP entries also applies
  10923. -// to the JVM_CONSTANT_Unresolved{Class,String} entry types.
  10924. -//
  10925. -// For the JVM_CONSTANT_{Class,String} entry types, since there is only
  10926. -// one data element at the end of the recursion, we know that we have
  10927. -// either one or two unique entries. If the JVM_CONSTANT_Utf8 entry is
  10928. -// unique then it is appended to merge_cp before the current entry.
  10929. -// If the JVM_CONSTANT_Utf8 entry is not unique, then the current entry
  10930. -// is updated to refer to the duplicate entry in merge_cp before it is
  10931. -// appended to merge_cp. Again, any changes in index values are tracked
  10932. -// as needed.
  10933. -//
  10934. -// Note: the above discussion for JVM_CONSTANT_{Class,String} entry
  10935. -// types is theoretical. Since those entry types have already been
  10936. -// optimized into JVM_CONSTANT_Unresolved{Class,String} entry types,
  10937. -// they are handled as direct CP entries.
  10938. -//
  10939. -// For the JVM_CONSTANT_NameAndType entry type, since there are two
  10940. -// data elements at the end of the recursions, we know that we have
  10941. -// between one and three unique entries. Any unique JVM_CONSTANT_Utf8
  10942. -// entries are appended to merge_cp before the current entry. For any
  10943. -// JVM_CONSTANT_Utf8 entries that are not unique, the current entry is
  10944. -// updated to refer to the duplicate entry in merge_cp before it is
  10945. -// appended to merge_cp. Again, any changes in index values are tracked
  10946. -// as needed.
  10947. -//
  10948. -// For the JVM_CONSTANT_{Fieldref,InterfaceMethodref,Methodref} entry
  10949. -// types, since there are two indirect CP entries and three data
  10950. -// elements at the end of the recursions, we know that we have between
  10951. -// one and six unique entries. See the JVM_CONSTANT_Fieldref diagram
  10952. -// above for an example of all six entries. The uniqueness algorithm
  10953. -// for the JVM_CONSTANT_Class and JVM_CONSTANT_NameAndType entries is
  10954. -// covered above. Any unique entries are appended to merge_cp before
  10955. -// the current entry. For any entries that are not unique, the current
  10956. -// entry is updated to refer to the duplicate entry in merge_cp before
  10957. -// it is appended to merge_cp. Again, any changes in index values are
  10958. -// tracked as needed.
  10959. -//
  10960. -//
  10961. -// Other Details:
  10962. -//
  10963. -// Details for other parts of RedefineClasses need to be written.
  10964. -// This is a placeholder section.
  10965. -//
  10966. -//
  10967. -// Open Issues (in no particular order):
  10968. -//
  10969. -// - How do we serialize the RedefineClasses() API without deadlocking?
  10970. -//
  10971. -// - SystemDictionary::parse_stream() was called with a NULL protection
  10972. -// domain since the initial version. This has been changed to pass
  10973. -// the_class->protection_domain(). This change has been tested with
  10974. -// all NSK tests and nothing broke, but what will adding it now break
  10975. -// in ways that we don't test?
  10976. -//
  10977. -// - GenerateOopMap::rewrite_load_or_store() has a comment in its
  10978. -// (indirect) use of the Relocator class that the max instruction
  10979. -// size is 4 bytes. goto_w and jsr_w are 5 bytes and wide/iinc is
  10980. -// 6 bytes. Perhaps Relocator only needs a 4 byte buffer to do
  10981. -// what it does to the bytecodes. More investigation is needed.
  10982. -//
  10983. -// - java.lang.Object methods can be called on arrays. This is
  10984. -// implemented via the arrayKlassOop vtable which we don't
  10985. -// update. For example, if we redefine java.lang.Object.toString(),
  10986. -// then the new version of the method will not be called for array
  10987. -// objects.
  10988. -//
  10989. -// - How do we know if redefine_single_class() and the guts of
  10990. -// instanceKlass are out of sync? I don't think this can be
  10991. -// automated, but we should probably order the work in
  10992. -// redefine_single_class() to match the order of field
  10993. -// definitions in instanceKlass. We also need to add some
  10994. -// comments about keeping things in sync.
  10995. -//
  10996. -// - set_new_constant_pool() is huge and we should consider refactoring
  10997. -// it into smaller chunks of work.
  10998. -//
  10999. -// - The exception table update code in set_new_constant_pool() defines
  11000. -// const values that are also defined in a local context elsewhere.
  11001. -// The same literal values are also used in elsewhere. We need to
  11002. -// coordinate a cleanup of these constants with Runtime.
  11003. -//
  11004. +#define RC_ABORT(error) { _result = error; return false; }
  11005. -class VM_RedefineClasses: public VM_Operation {
  11006. +class VM_RedefineClasses: public VM_GC_Operation {
  11007. private:
  11008. +
  11009. // These static fields are needed by SystemDictionary::classes_do()
  11010. // facility and the adjust_cpool_cache_and_vtable() helper:
  11011. static objArrayOop _old_methods;
  11012. static objArrayOop _new_methods;
  11013. - static methodOop* _matching_old_methods;
  11014. - static methodOop* _matching_new_methods;
  11015. - static methodOop* _deleted_methods;
  11016. - static methodOop* _added_methods;
  11017. + static int* _matching_old_methods;
  11018. + static int* _matching_new_methods;
  11019. + static int* _deleted_methods;
  11020. + static int* _added_methods;
  11021. static int _matching_methods_length;
  11022. static int _deleted_methods_length;
  11023. static int _added_methods_length;
  11024. static klassOop _the_class_oop;
  11025. +
  11026. + static int _revision_number;
  11027. // The instance fields are used to pass information from
  11028. // doit_prologue() to doit() and doit_epilogue().
  11029. @@ -370,42 +70,28 @@
  11030. // _index_map_p contains any entries.
  11031. int _index_map_count;
  11032. intArray * _index_map_p;
  11033. -
  11034. - // _operands_index_map_count is just an optimization for knowing if
  11035. - // _operands_index_map_p contains any entries.
  11036. - int _operands_cur_length;
  11037. - int _operands_index_map_count;
  11038. - intArray * _operands_index_map_p;
  11039. -
  11040. - // ptr to _class_count scratch_classes
  11041. - instanceKlassHandle * _scratch_classes;
  11042. - jvmtiError _res;
  11043. + GrowableArray<instanceKlassHandle>* _new_classes;
  11044. + GrowableArray<oop>* _updated_oops;
  11045. + jvmtiError _result;
  11046. + int _max_redefinition_flags;
  11047. // Performance measurement support. These timers do not cover all
  11048. // the work done for JVM/TI RedefineClasses() but they do cover
  11049. // the heavy lifting.
  11050. - elapsedTimer _timer_rsc_phase1;
  11051. - elapsedTimer _timer_rsc_phase2;
  11052. - elapsedTimer _timer_vm_op_prologue;
  11053. + elapsedTimer _timer_total;
  11054. + elapsedTimer _timer_prologue;
  11055. + elapsedTimer _timer_class_linking;
  11056. + elapsedTimer _timer_class_loading;
  11057. + elapsedTimer _timer_check_type;
  11058. + elapsedTimer _timer_prepare_redefinition;
  11059. + elapsedTimer _timer_wait_for_locks;
  11060. + elapsedTimer _timer_redefinition;
  11061. + elapsedTimer _timer_vm_op_epilogue;
  11062. - // These routines are roughly in call order unless otherwise noted.
  11063. -
  11064. - // Load the caller's new class definition(s) into _scratch_classes.
  11065. - // Constant pool merging work is done here as needed. Also calls
  11066. - // compare_and_normalize_class_versions() to verify the class
  11067. - // definition(s).
  11068. + jvmtiError check_redefinition_allowed(instanceKlassHandle new_class);
  11069. + jvmtiError find_sorted_affected_classes(GrowableArray<instanceKlassHandle> *all_affected_klasses);
  11070. + jvmtiError find_class_bytes(instanceKlassHandle the_class, const unsigned char **class_bytes, jint *class_byte_count, jboolean *not_changed);
  11071. jvmtiError load_new_class_versions(TRAPS);
  11072. -
  11073. - // Verify that the caller provided class definition(s) that meet
  11074. - // the restrictions of RedefineClasses. Normalize the order of
  11075. - // overloaded methods as needed.
  11076. - jvmtiError compare_and_normalize_class_versions(
  11077. - instanceKlassHandle the_class, instanceKlassHandle scratch_class);
  11078. -
  11079. - // Swap annotations[i] with annotations[j]
  11080. - // Used by compare_and_normalize_class_versions() when normalizing
  11081. - // overloaded methods or changing idnum as when adding or deleting methods.
  11082. - void swap_all_method_annotations(int i, int j, instanceKlassHandle scratch_class);
  11083. // Figure out which new methods match old methods in name and signature,
  11084. // which methods have been added, and which are no longer present
  11085. @@ -414,103 +100,99 @@
  11086. // Change jmethodIDs to point to the new methods
  11087. void update_jmethod_ids();
  11088. - // In addition to marking methods as obsolete, this routine
  11089. - // records which methods are EMCP (Equivalent Module Constant
  11090. - // Pool) in the emcp_methods BitMap and returns the number of
  11091. - // EMCP methods via emcp_method_count_p. This information is
  11092. - // used when information about the previous version of the_class
  11093. - // is squirreled away.
  11094. - void check_methods_and_mark_as_obsolete(BitMap *emcp_methods,
  11095. - int * emcp_method_count_p);
  11096. - void transfer_old_native_function_registrations(instanceKlassHandle the_class);
  11097. + class FindAffectedKlassesClosure : public ObjectClosure {
  11098. - // Unevolving classes may point to methods of the_class directly
  11099. - // from their constant pool caches, itables, and/or vtables. We
  11100. - // use the SystemDictionary::classes_do() facility and this helper
  11101. - // to fix up these pointers.
  11102. - static void adjust_cpool_cache_and_vtable(klassOop k_oop, oop loader, TRAPS);
  11103. + private:
  11104. + GrowableArray<instanceKlassHandle> *_original_klasses;
  11105. + GrowableArray<instanceKlassHandle> *_result;
  11106. +
  11107. + public:
  11108. + FindAffectedKlassesClosure(GrowableArray<instanceKlassHandle> *original_klasses, GrowableArray<instanceKlassHandle> *result);
  11109. +
  11110. + virtual void do_object(oop obj);
  11111. + };
  11112. +
  11113. +
  11114. + static jvmtiError do_topological_class_sorting(const jvmtiClassDefinition *class_definitions, int class_count, GrowableArray<instanceKlassHandle> *affected, GrowableArray<instanceKlassHandle> *arr, TRAPS);
  11115. // Install the redefinition of a class
  11116. - void redefine_single_class(jclass the_jclass,
  11117. - instanceKlassHandle scratch_class, TRAPS);
  11118. + void redefine_single_class(instanceKlassHandle the_new_class, TRAPS);
  11119. // Increment the classRedefinedCount field in the specific instanceKlass
  11120. // and in all direct and indirect subclasses.
  11121. void increment_class_counter(instanceKlass *ik, TRAPS);
  11122. - // Support for constant pool merging (these routines are in alpha order):
  11123. - void append_entry(constantPoolHandle scratch_cp, int scratch_i,
  11124. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS);
  11125. - void append_operand(constantPoolHandle scratch_cp, int scratch_bootstrap_spec_index,
  11126. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS);
  11127. - void finalize_operands_merge(constantPoolHandle merge_cp, TRAPS);
  11128. - int find_or_append_indirect_entry(constantPoolHandle scratch_cp, int scratch_i,
  11129. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS);
  11130. - int find_or_append_operand(constantPoolHandle scratch_cp, int scratch_bootstrap_spec_index,
  11131. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS);
  11132. - int find_new_index(int old_index);
  11133. - int find_new_operand_index(int old_bootstrap_spec_index);
  11134. - bool is_unresolved_class_mismatch(constantPoolHandle cp1, int index1,
  11135. - constantPoolHandle cp2, int index2);
  11136. - bool is_unresolved_string_mismatch(constantPoolHandle cp1, int index1,
  11137. - constantPoolHandle cp2, int index2);
  11138. - void map_index(constantPoolHandle scratch_cp, int old_index, int new_index);
  11139. - void map_operand_index(int old_bootstrap_spec_index, int new_bootstrap_spec_index);
  11140. - bool merge_constant_pools(constantPoolHandle old_cp,
  11141. - constantPoolHandle scratch_cp, constantPoolHandle *merge_cp_p,
  11142. - int *merge_cp_length_p, TRAPS);
  11143. - jvmtiError merge_cp_and_rewrite(instanceKlassHandle the_class,
  11144. - instanceKlassHandle scratch_class, TRAPS);
  11145. - u2 rewrite_cp_ref_in_annotation_data(
  11146. - typeArrayHandle annotations_typeArray, int &byte_i_ref,
  11147. - const char * trace_mesg, TRAPS);
  11148. - bool rewrite_cp_refs(instanceKlassHandle scratch_class, TRAPS);
  11149. - bool rewrite_cp_refs_in_annotation_struct(
  11150. - typeArrayHandle class_annotations, int &byte_i_ref, TRAPS);
  11151. - bool rewrite_cp_refs_in_annotations_typeArray(
  11152. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS);
  11153. - bool rewrite_cp_refs_in_class_annotations(
  11154. - instanceKlassHandle scratch_class, TRAPS);
  11155. - bool rewrite_cp_refs_in_element_value(
  11156. - typeArrayHandle class_annotations, int &byte_i_ref, TRAPS);
  11157. - bool rewrite_cp_refs_in_fields_annotations(
  11158. - instanceKlassHandle scratch_class, TRAPS);
  11159. - void rewrite_cp_refs_in_method(methodHandle method,
  11160. - methodHandle * new_method_p, TRAPS);
  11161. - bool rewrite_cp_refs_in_methods(instanceKlassHandle scratch_class, TRAPS);
  11162. - bool rewrite_cp_refs_in_methods_annotations(
  11163. - instanceKlassHandle scratch_class, TRAPS);
  11164. - bool rewrite_cp_refs_in_methods_default_annotations(
  11165. - instanceKlassHandle scratch_class, TRAPS);
  11166. - bool rewrite_cp_refs_in_methods_parameter_annotations(
  11167. - instanceKlassHandle scratch_class, TRAPS);
  11168. - void rewrite_cp_refs_in_stack_map_table(methodHandle method, TRAPS);
  11169. - void rewrite_cp_refs_in_verification_type_info(
  11170. - address& stackmap_addr_ref, address stackmap_end, u2 frame_i,
  11171. - u1 frame_size, TRAPS);
  11172. - void set_new_constant_pool(instanceKlassHandle scratch_class,
  11173. - constantPoolHandle scratch_cp, int scratch_cp_length, TRAPS);
  11174. void flush_dependent_code(instanceKlassHandle k_h, TRAPS);
  11175. - static void check_class(klassOop k_oop, oop initiating_loader, TRAPS);
  11176. - static void dump_methods();
  11177. + static void check_class(klassOop k_oop,/* oop initiating_loader,*/ TRAPS) PRODUCT_RETURN;
  11178. +
  11179. + static void adjust_cpool_cache(klassOop k_oop, oop initiating_loader, TRAPS);
  11180. +
  11181. +#ifdef ASSERT
  11182. + static void verify_classes(klassOop k_oop, oop initiating_loader, TRAPS);
  11183. +#endif
  11184. +
  11185. + int calculate_redefinition_flags(instanceKlassHandle new_version);
  11186. + void calculate_instance_update_information(klassOop new_version);
  11187. + void check_methods_and_mark_as_obsolete(BitMap *emcp_methods, int * emcp_method_count_p);
  11188. +
  11189. + static void calculate_type_check_information(klassOop k);
  11190. + static void clear_type_check_information(klassOop k);
  11191. public:
  11192. - VM_RedefineClasses(jint class_count,
  11193. - const jvmtiClassDefinition *class_defs,
  11194. - JvmtiClassLoadKind class_load_kind);
  11195. - VMOp_Type type() const { return VMOp_RedefineClasses; }
  11196. + VM_RedefineClasses(jint class_count, const jvmtiClassDefinition *class_defs, JvmtiClassLoadKind class_load_kind);
  11197. + virtual ~VM_RedefineClasses();
  11198. +
  11199. + bool check_arguments();
  11200. bool doit_prologue();
  11201. void doit();
  11202. void doit_epilogue();
  11203. + void rollback();
  11204. - bool allow_nested_vm_operations() const { return true; }
  11205. - jvmtiError check_error() { return _res; }
  11206. + jvmtiError check_exception() const;
  11207. + VMOp_Type type() const { return VMOp_RedefineClasses; }
  11208. + bool skip_operation() const { return false; }
  11209. + bool allow_nested_vm_operations() const { return true; }
  11210. + jvmtiError check_error() { return _result; }
  11211. +
  11212. + void update_active_methods();
  11213. +
  11214. + // Checks for type consistency after hierarchy change
  11215. + bool check_type_consistency();
  11216. + void calculate_type_check_information();
  11217. + bool check_field_value_types();
  11218. + void clear_type_check_information();
  11219. + bool check_method_stacks();
  11220. + bool check_loaded_methods();
  11221. + bool check_method(methodOop method);
  11222. + static Symbol* signature_to_class_name(Symbol* signature);
  11223. +
  11224. + void method_forwarding();
  11225. +
  11226. + void update_array_classes_to_newest_version(klassOop smallest_dimension);
  11227. // Modifiable test must be shared between IsModifiableClass query
  11228. // and redefine implementation
  11229. static bool is_modifiable_class(oop klass_mirror);
  11230. +
  11231. + // Method used during garbage collection, the VM operation must iterate over all oops.
  11232. + void oops_do(OopClosure* f);
  11233. +
  11234. + // Utility methods for transferring field access flags
  11235. +
  11236. + static void transfer_special_access_flags(fieldDescriptor *from, fieldDescriptor *to);
  11237. + static void update_klass_field_access_flag(fieldDescriptor *fd);
  11238. +
  11239. + void transfer_old_native_function_registrations(instanceKlassHandle the_class);
  11240. +
  11241. + void lock_threads();
  11242. + void unlock_threads();
  11243. +
  11244. + template <class T> static void do_oop_work(T* p);
  11245. +
  11246. + static void swap_marks(oop first, oop second);
  11247. +
  11248. };
  11249. #endif // SHARE_VM_PRIMS_JVMTIREDEFINECLASSES_HPP
  11250. diff --git a/src/share/vm/prims/methodComparator.cpp b/src/share/vm/prims/methodComparator.cpp
  11251. index 60eaf97..07bb6e3 100644
  11252. --- a/src/share/vm/prims/methodComparator.cpp
  11253. +++ b/src/share/vm/prims/methodComparator.cpp
  11254. @@ -65,6 +65,7 @@
  11255. if (! args_same(c_old, c_new))
  11256. return false;
  11257. }
  11258. +
  11259. return true;
  11260. }
  11261. diff --git a/src/share/vm/prims/nativeLookup.cpp b/src/share/vm/prims/nativeLookup.cpp
  11262. index 41fc42d..53b3e0c 100644
  11263. --- a/src/share/vm/prims/nativeLookup.cpp
  11264. +++ b/src/share/vm/prims/nativeLookup.cpp
  11265. @@ -35,6 +35,7 @@
  11266. #include "oops/symbol.hpp"
  11267. #include "prims/jvm_misc.hpp"
  11268. #include "prims/nativeLookup.hpp"
  11269. +#include "prims/jvmtiRedefineClasses.hpp"
  11270. #include "runtime/arguments.hpp"
  11271. #include "runtime/handles.inline.hpp"
  11272. #include "runtime/javaCalls.hpp"
  11273. @@ -52,7 +53,6 @@
  11274. #ifdef TARGET_OS_FAMILY_bsd
  11275. # include "os_bsd.inline.hpp"
  11276. #endif
  11277. -
  11278. static void mangle_name_on(outputStream* st, Symbol* name, int begin, int end) {
  11279. char* bytes = (char*)name->bytes() + begin;
  11280. @@ -138,6 +138,40 @@
  11281. { CC"Java_sun_hotspot_WhiteBox_registerNatives", NULL, FN_PTR(JVM_RegisterWhiteBoxMethods) },
  11282. };
  11283. +// Helper function to call redefineClasses from Java Code
  11284. +JVM_ENTRY(int, JVM_RedefineClassesHelper(JNIEnv *env, jclass cb, jclass target, jbyteArray bytes))
  11285. + ResourceMark rm(THREAD);
  11286. +
  11287. + JavaThread* current_thread = JavaThread::current();
  11288. + jbyte* bytecodes = NULL;
  11289. + const int class_count = 1;
  11290. + jvmtiClassDefinition* class_definitions = NEW_RESOURCE_ARRAY(jvmtiClassDefinition, class_count);
  11291. +
  11292. + {
  11293. + ThreadToNativeFromVM ttnfv(thread);
  11294. + jboolean is_copy = JNI_FALSE;
  11295. + bytecodes = env->GetByteArrayElements(bytes, &is_copy);
  11296. + class_definitions[0].klass = target;
  11297. + class_definitions[0].class_byte_count = env->GetArrayLength(bytes);
  11298. + class_definitions[0].class_bytes = (unsigned char*)bytecodes;
  11299. + }
  11300. +
  11301. + VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_retransform);
  11302. + VMThread::execute(&op);
  11303. + int result = op.check_error();
  11304. +
  11305. + {
  11306. + ThreadToNativeFromVM ttnfv(thread);
  11307. + if (env->ExceptionOccurred()) {
  11308. + return -1;
  11309. + }
  11310. + env->ReleaseByteArrayElements(bytes, bytecodes, 0);
  11311. + }
  11312. +
  11313. + return result;
  11314. +JVM_END
  11315. +
  11316. +
  11317. static address lookup_special_native(char* jni_name) {
  11318. int i = !JDK_Version::is_gte_jdk14x_version() ? 0 : 2; // see comment in lookup_special_native_methods
  11319. int count = sizeof(lookup_special_native_methods) / sizeof(JNINativeMethod);
  11320. @@ -177,6 +211,9 @@
  11321. return entry;
  11322. }
  11323. }
  11324. + if(strstr(jni_name, "Java_at_ssw_hotswap_ClassRedefinition_redefineClasses") != NULL) {
  11325. + return CAST_FROM_FN_PTR(address, JVM_RedefineClassesHelper);
  11326. + }
  11327. // Otherwise call static method findNative in ClassLoader
  11328. KlassHandle klass (THREAD, SystemDictionary::ClassLoader_klass());
  11329. diff --git a/src/share/vm/runtime/arguments.cpp b/src/share/vm/runtime/arguments.cpp
  11330. index 0496367..62e9d55 100644
  11331. --- a/src/share/vm/runtime/arguments.cpp
  11332. +++ b/src/share/vm/runtime/arguments.cpp
  11333. @@ -1874,6 +1874,15 @@
  11334. status = false;
  11335. }
  11336. + // (tw) Must use serial GC
  11337. + if (!UseSerialGC && i >= 1) {
  11338. + jio_fprintf(defaultStream::error_stream(),
  11339. + "Must use the serial GC in the Dynamic Code Evolution VM\n");
  11340. + status = false;
  11341. + } else {
  11342. + UseSerialGC = true;
  11343. + }
  11344. +
  11345. return status;
  11346. }
  11347. diff --git a/src/share/vm/runtime/deoptimization.cpp b/src/share/vm/runtime/deoptimization.cpp
  11348. index 2b767d4..e9b6f47 100644
  11349. --- a/src/share/vm/runtime/deoptimization.cpp
  11350. +++ b/src/share/vm/runtime/deoptimization.cpp
  11351. @@ -599,6 +599,38 @@
  11352. // Cleanup thread deopt data
  11353. cleanup_deopt_info(thread, array);
  11354. + // (tw) Redefinition support: Check if we need to transfer method execution points to new versions
  11355. + {
  11356. + ResourceMark res_mark;
  11357. +
  11358. + // Verify that the just-unpacked frames match the interpreter's
  11359. + // notions of expression stack and locals
  11360. + vframeArray* cur_array = thread->vframe_array_last();
  11361. + RegisterMap rm(thread, false);
  11362. + rm.set_include_argument_oops(false);
  11363. + for (int i = 0; i < cur_array->frames(); i++) {
  11364. + vframeArrayElement* el = cur_array->element(i);
  11365. + frame* frame = el->iframe();
  11366. + guarantee(frame->is_interpreted_frame(), "Wrong frame type");
  11367. + RegisterMap reg_map(thread);
  11368. + vframe* vf = vframe::new_vframe(frame, &reg_map, thread);
  11369. + interpretedVFrame *iframe = (interpretedVFrame *)vf;
  11370. + methodOop method = iframe->method();
  11371. + int bci = iframe->bci();
  11372. + method = method->newest_version();
  11373. + iframe->set_method(method, bci);
  11374. +
  11375. + methodOop forward_method = method->forward_method();
  11376. + if (forward_method != NULL && method->is_in_code_section(bci)) {
  11377. + int new_bci = method->calculate_forward_bci(bci, forward_method);
  11378. + if (TraceRedefineClasses >= 2) {
  11379. + 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);
  11380. + }
  11381. + iframe->set_method(forward_method, new_bci);
  11382. + }
  11383. + }
  11384. + }
  11385. +
  11386. #ifndef PRODUCT
  11387. if (VerifyStack) {
  11388. ResourceMark res_mark;
  11389. diff --git a/src/share/vm/runtime/frame.cpp b/src/share/vm/runtime/frame.cpp
  11390. index aacd835..3772b3f 100644
  11391. --- a/src/share/vm/runtime/frame.cpp
  11392. +++ b/src/share/vm/runtime/frame.cpp
  11393. @@ -408,6 +408,12 @@
  11394. *interpreter_frame_method_addr() = method;
  11395. }
  11396. +// (tw) Sets constant pool cache oop
  11397. +void frame::interpreter_frame_set_cache(constantPoolCacheOop cp) {
  11398. + assert(is_interpreted_frame(), "interpreted frame expected");
  11399. + *interpreter_frame_cache_addr() = cp;
  11400. +}
  11401. +
  11402. void frame::interpreter_frame_set_bcx(intptr_t bcx) {
  11403. assert(is_interpreted_frame(), "Not an interpreted frame");
  11404. if (ProfileInterpreter) {
  11405. @@ -423,19 +429,27 @@
  11406. // The bcx was just converted from bci to bcp.
  11407. // Convert the mdx in parallel.
  11408. methodDataOop mdo = interpreter_frame_method()->method_data();
  11409. - assert(mdo != NULL, "");
  11410. - int mdi = mdx - 1; // We distinguish valid mdi from zero by adding one.
  11411. - address mdp = mdo->di_to_dp(mdi);
  11412. - interpreter_frame_set_mdx((intptr_t)mdp);
  11413. + if (mdo == NULL) {
  11414. + interpreter_frame_set_mdx(0);
  11415. + } else {
  11416. + assert(mdo != NULL, "");
  11417. + int mdi = mdx - 1; // We distinguish valid mdi from zero by adding one.
  11418. + address mdp = mdo->di_to_dp(mdi);
  11419. + interpreter_frame_set_mdx((intptr_t)mdp);
  11420. + }
  11421. }
  11422. } else {
  11423. if (is_now_bci) {
  11424. // The bcx was just converted from bcp to bci.
  11425. // Convert the mdx in parallel.
  11426. methodDataOop mdo = interpreter_frame_method()->method_data();
  11427. - assert(mdo != NULL, "");
  11428. - int mdi = mdo->dp_to_di((address)mdx);
  11429. - interpreter_frame_set_mdx((intptr_t)mdi + 1); // distinguish valid from 0.
  11430. + if (mdo == NULL) {
  11431. + interpreter_frame_set_mdx(0);
  11432. + } else {
  11433. + assert(mdo != NULL, "");
  11434. + int mdi = mdo->dp_to_di((address)mdx);
  11435. + interpreter_frame_set_mdx((intptr_t)mdi + 1); // distinguish valid from 0.
  11436. + }
  11437. }
  11438. }
  11439. }
  11440. diff --git a/src/share/vm/runtime/frame.hpp b/src/share/vm/runtime/frame.hpp
  11441. index 9c7bb72..04a6595 100644
  11442. --- a/src/share/vm/runtime/frame.hpp
  11443. +++ b/src/share/vm/runtime/frame.hpp
  11444. @@ -346,6 +346,7 @@
  11445. // Method & constant pool cache
  11446. methodOop interpreter_frame_method() const;
  11447. void interpreter_frame_set_method(methodOop method);
  11448. + void interpreter_frame_set_cache(constantPoolCacheOop method);
  11449. methodOop* interpreter_frame_method_addr() const;
  11450. constantPoolCacheOop* interpreter_frame_cache_addr() const;
  11451. #ifdef PPC
  11452. diff --git a/src/share/vm/runtime/globals.hpp b/src/share/vm/runtime/globals.hpp
  11453. index 0731ca0..cbd6eca 100644
  11454. --- a/src/share/vm/runtime/globals.hpp
  11455. +++ b/src/share/vm/runtime/globals.hpp
  11456. @@ -1229,9 +1229,23 @@
  11457. product(bool, StressLdcRewrite, false, \
  11458. "Force ldc -> ldc_w rewrite during RedefineClasses") \
  11459. \
  11460. + product(bool, UseMethodForwardPoints, false, \
  11461. + "Use method forward points") \
  11462. + \
  11463. + product(intx, MethodForwardPointsMaxLocals, 300, \
  11464. + "Maximum number of locals in forwarding method") \
  11465. + \
  11466. + product(intx, MethodForwardPointsMaxStack, 300, \
  11467. + "Maximum number of stack slots in forwarding method") \
  11468. + \
  11469. product(intx, TraceRedefineClasses, 0, \
  11470. "Trace level for JVMTI RedefineClasses") \
  11471. \
  11472. + product(bool, TimeRedefineClasses, false, \
  11473. + "Measure timing for JVMTI RedefineClasses") \
  11474. + \
  11475. + product(bool, AllowAdvancedClassRedefinition, true, \
  11476. + "Allow advanced class redefinition beyond swapping method bodies")\
  11477. develop(bool, StressMethodComparator, false, \
  11478. "run the MethodComparator on all loaded methods") \
  11479. \
  11480. diff --git a/src/share/vm/runtime/interfaceSupport.hpp b/src/share/vm/runtime/interfaceSupport.hpp
  11481. index 2875ee0..61fd8fe 100644
  11482. --- a/src/share/vm/runtime/interfaceSupport.hpp
  11483. +++ b/src/share/vm/runtime/interfaceSupport.hpp
  11484. @@ -296,7 +296,7 @@
  11485. ThreadToNativeFromVM(JavaThread *thread) : ThreadStateTransition(thread) {
  11486. // We are leaving the VM at this point and going directly to native code.
  11487. // Block, if we are in the middle of a safepoint synchronization.
  11488. - assert(!thread->owns_locks(), "must release all locks when leaving VM");
  11489. + assert(!thread->owns_locks_but_redefine_classes_lock(), "must release all locks when leaving VM");
  11490. thread->frame_anchor()->make_walkable(thread);
  11491. trans_and_fence(_thread_in_vm, _thread_in_native);
  11492. // Check for pending. async. exceptions or suspends.
  11493. diff --git a/src/share/vm/runtime/javaCalls.cpp b/src/share/vm/runtime/javaCalls.cpp
  11494. index edbba98..4a27925 100644
  11495. --- a/src/share/vm/runtime/javaCalls.cpp
  11496. +++ b/src/share/vm/runtime/javaCalls.cpp
  11497. @@ -60,7 +60,7 @@
  11498. bool clear_pending_exception = true;
  11499. guarantee(thread->is_Java_thread(), "crucial check - the VM thread cannot and must not escape to Java code");
  11500. - assert(!thread->owns_locks(), "must release all locks when leaving VM");
  11501. + assert(!thread->owns_locks_but_redefine_classes_lock(), "must release all locks when leaving VM");
  11502. guarantee(!thread->is_Compiler_thread(), "cannot make java calls from the compiler");
  11503. _result = result;
  11504. diff --git a/src/share/vm/runtime/jniHandles.cpp b/src/share/vm/runtime/jniHandles.cpp
  11505. index 3cbcaca..30839d7 100644
  11506. --- a/src/share/vm/runtime/jniHandles.cpp
  11507. +++ b/src/share/vm/runtime/jniHandles.cpp
  11508. @@ -112,6 +112,10 @@
  11509. }
  11510. jmethodID JNIHandles::make_jmethod_id(methodHandle mh) {
  11511. + if (mh->newest_version() != mh()) {
  11512. + methodHandle mh_new(Thread::current(), mh()->newest_version());
  11513. + return (jmethodID) make_weak_global(mh_new);
  11514. + }
  11515. return (jmethodID) make_weak_global(mh);
  11516. }
  11517. diff --git a/src/share/vm/runtime/mutex.cpp b/src/share/vm/runtime/mutex.cpp
  11518. index 2095237..c541434 100644
  11519. --- a/src/share/vm/runtime/mutex.cpp
  11520. +++ b/src/share/vm/runtime/mutex.cpp
  11521. @@ -1227,7 +1227,7 @@
  11522. // in increasing rank order (modulo any native ranks)
  11523. for (tmp = locks; tmp != NULL; tmp = tmp->next()) {
  11524. if (tmp->next() != NULL) {
  11525. - assert(tmp->rank() == Mutex::native ||
  11526. + assert(tmp->rank() == Mutex::native || tmp->rank() == Mutex::redefine_classes ||
  11527. tmp->rank() <= tmp->next()->rank(), "mutex rank anomaly?");
  11528. }
  11529. }
  11530. @@ -1247,7 +1247,7 @@
  11531. // in increasing rank order (modulo any native ranks)
  11532. for (tmp = locks; tmp != NULL; tmp = tmp->next()) {
  11533. if (tmp->next() != NULL) {
  11534. - assert(tmp->rank() == Mutex::native ||
  11535. + assert(tmp->rank() == Mutex::native || tmp->rank() == Mutex::redefine_classes ||
  11536. tmp->rank() <= tmp->next()->rank(), "mutex rank anomaly?");
  11537. }
  11538. }
  11539. @@ -1310,6 +1310,7 @@
  11540. // already hold Terminator_lock - may happen because of periodic safepoints
  11541. if (this->rank() != Mutex::native &&
  11542. this->rank() != Mutex::suspend_resume &&
  11543. + this->rank() != Mutex::redefine_classes &&
  11544. locks != NULL && locks->rank() <= this->rank() &&
  11545. !SafepointSynchronize::is_at_safepoint() &&
  11546. this != Interrupt_lock &&
  11547. diff --git a/src/share/vm/runtime/mutex.hpp b/src/share/vm/runtime/mutex.hpp
  11548. index 7d2cd82..11eb32e 100644
  11549. --- a/src/share/vm/runtime/mutex.hpp
  11550. +++ b/src/share/vm/runtime/mutex.hpp
  11551. @@ -109,7 +109,8 @@
  11552. barrier = safepoint + 1,
  11553. nonleaf = barrier + 1,
  11554. max_nonleaf = nonleaf + 900,
  11555. - native = max_nonleaf + 1
  11556. + native = max_nonleaf + 1,
  11557. + redefine_classes = native + 1
  11558. };
  11559. // The WaitSet and EntryList linked lists are composed of ParkEvents.
  11560. diff --git a/src/share/vm/runtime/mutexLocker.cpp b/src/share/vm/runtime/mutexLocker.cpp
  11561. index 77fddef..9d453d4 100644
  11562. --- a/src/share/vm/runtime/mutexLocker.cpp
  11563. +++ b/src/share/vm/runtime/mutexLocker.cpp
  11564. @@ -49,6 +49,7 @@
  11565. // Consider using GCC's __read_mostly.
  11566. Mutex* Patching_lock = NULL;
  11567. +Mutex* RedefineClasses_lock = NULL;
  11568. Monitor* SystemDictionary_lock = NULL;
  11569. Mutex* PackageTable_lock = NULL;
  11570. Mutex* CompiledIC_lock = NULL;
  11571. @@ -91,6 +92,7 @@
  11572. Mutex* DirtyCardQ_FL_lock = NULL;
  11573. Monitor* DirtyCardQ_CBL_mon = NULL;
  11574. Mutex* Shared_DirtyCardQ_lock = NULL;
  11575. +Monitor* RedefinitionSync_lock = NULL;
  11576. Mutex* ParGCRareEvent_lock = NULL;
  11577. Mutex* EvacFailureStack_lock = NULL;
  11578. Mutex* DerivedPointerTableGC_lock = NULL;
  11579. @@ -208,6 +210,7 @@
  11580. def(HotCardCache_lock , Mutex , special , true );
  11581. def(EvacFailureStack_lock , Mutex , nonleaf , true );
  11582. }
  11583. + def(RedefinitionSync_lock , Monitor , leaf , false );
  11584. def(ParGCRareEvent_lock , Mutex , leaf , true );
  11585. def(DerivedPointerTableGC_lock , Mutex, leaf, true );
  11586. def(CodeCache_lock , Mutex , special, true );
  11587. @@ -283,6 +286,7 @@
  11588. def(Debug3_lock , Mutex , nonleaf+4, true );
  11589. def(CompileThread_lock , Monitor, nonleaf+5, false);
  11590. def(PeriodicTask_lock , Monitor, nonleaf+5, true);
  11591. + def(RedefineClasses_lock , Mutex , nonleaf+7, false ); // for ensuring that class redefinition is not done in parallel
  11592. #ifdef INCLUDE_TRACE
  11593. def(JfrMsg_lock , Monitor, leaf, true);
  11594. diff --git a/src/share/vm/runtime/mutexLocker.hpp b/src/share/vm/runtime/mutexLocker.hpp
  11595. index a6549b1..089ed11 100644
  11596. --- a/src/share/vm/runtime/mutexLocker.hpp
  11597. +++ b/src/share/vm/runtime/mutexLocker.hpp
  11598. @@ -43,6 +43,8 @@
  11599. // Mutexes used in the VM.
  11600. extern Mutex* Patching_lock; // a lock used to guard code patching of compiled code
  11601. +extern Monitor* RedefinitionSync_lock; // a lock on synchronized class redefinition
  11602. +extern Mutex* RedefineClasses_lock; // a lock on class redefinition
  11603. extern Monitor* SystemDictionary_lock; // a lock on the system dictonary
  11604. extern Mutex* PackageTable_lock; // a lock on the class loader package table
  11605. extern Mutex* CompiledIC_lock; // a lock used to guard compiled IC patching and access
  11606. diff --git a/src/share/vm/runtime/reflection.cpp b/src/share/vm/runtime/reflection.cpp
  11607. index 1665d93..6baabba 100644
  11608. --- a/src/share/vm/runtime/reflection.cpp
  11609. +++ b/src/share/vm/runtime/reflection.cpp
  11610. @@ -468,7 +468,8 @@
  11611. // sun/reflect/MagicAccessorImpl subclasses to succeed trivially.
  11612. if ( JDK_Version::is_gte_jdk14x_version()
  11613. && UseNewReflection
  11614. - && Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass())) {
  11615. + && (Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()) ||
  11616. + Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()->klass_part()->newest_version()))) {
  11617. return true;
  11618. }
  11619. @@ -519,6 +520,12 @@
  11620. AccessFlags access,
  11621. bool classloader_only,
  11622. bool protected_restriction) {
  11623. +
  11624. + // (tw) Decide accessibility based on active version
  11625. + if (current_class != NULL) {
  11626. + current_class = current_class->klass_part()->active_version();
  11627. + }
  11628. +
  11629. // Verify that current_class can access a field of field_class, where that
  11630. // field's access bits are "access". We assume that we've already verified
  11631. // that current_class can access field_class.
  11632. @@ -560,7 +567,8 @@
  11633. // sun/reflect/MagicAccessorImpl subclasses to succeed trivially.
  11634. if ( JDK_Version::is_gte_jdk14x_version()
  11635. && UseNewReflection
  11636. - && Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass())) {
  11637. + && (Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()) ||
  11638. + Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()->klass_part()->newest_version()))) {
  11639. return true;
  11640. }
  11641. diff --git a/src/share/vm/runtime/sharedRuntime.cpp b/src/share/vm/runtime/sharedRuntime.cpp
  11642. index 709d783..e0e19b1 100644
  11643. --- a/src/share/vm/runtime/sharedRuntime.cpp
  11644. +++ b/src/share/vm/runtime/sharedRuntime.cpp
  11645. @@ -1137,7 +1137,20 @@
  11646. if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
  11647. int retry_count = 0;
  11648. while (!HAS_PENDING_EXCEPTION && callee_method->is_old() &&
  11649. - callee_method->method_holder() != SystemDictionary::Object_klass()) {
  11650. + callee_method->method_holder()->klass_part()->newest_version() != SystemDictionary::Object_klass()->klass_part()->newest_version()) {
  11651. +
  11652. + // DCEVM: If we are executing an old method, this is OK!
  11653. + {
  11654. + ResourceMark rm(thread);
  11655. + RegisterMap cbl_map(thread, false);
  11656. + frame caller_frame = thread->last_frame().sender(&cbl_map);
  11657. +
  11658. + CodeBlob* caller_cb = caller_frame.cb();
  11659. + guarantee(caller_cb != NULL && caller_cb->is_nmethod(), "must be called from nmethod");
  11660. + nmethod* caller_nm = caller_cb->as_nmethod_or_null();
  11661. + if (caller_nm->method()->is_old()) break;
  11662. + }
  11663. +
  11664. // If has a pending exception then there is no need to re-try to
  11665. // resolve this method.
  11666. // If the method has been redefined, we need to try again.
  11667. diff --git a/src/share/vm/runtime/thread.cpp b/src/share/vm/runtime/thread.cpp
  11668. index f3acf4d..ea61cae 100644
  11669. --- a/src/share/vm/runtime/thread.cpp
  11670. +++ b/src/share/vm/runtime/thread.cpp
  11671. @@ -216,6 +216,8 @@
  11672. set_self_raw_id(0);
  11673. set_lgrp_id(-1);
  11674. + _redefine_classes_mutex = new Mutex(Mutex::redefine_classes, "redefine classes lock", false);
  11675. +
  11676. // allocated data structures
  11677. set_osthread(NULL);
  11678. set_resource_area(new (mtThread)ResourceArea());
  11679. @@ -249,6 +251,7 @@
  11680. omFreeProvision = 32 ;
  11681. omInUseList = NULL ;
  11682. omInUseCount = 0 ;
  11683. + _pretend_new_universe = false;
  11684. #ifdef ASSERT
  11685. _visited_for_critical_count = false;
  11686. @@ -880,6 +883,15 @@
  11687. bool Thread::owns_locks_but_compiled_lock() const {
  11688. for(Monitor *cur = _owned_locks; cur; cur = cur->next()) {
  11689. if (cur != Compile_lock) return true;
  11690. + }
  11691. + return false;
  11692. +}
  11693. +
  11694. +bool Thread::owns_locks_but_redefine_classes_lock() const {
  11695. + for(Monitor *cur = _owned_locks; cur; cur = cur->next()) {
  11696. + if (cur != RedefineClasses_lock && cur->rank() != Mutex::redefine_classes) {
  11697. + return true;
  11698. + }
  11699. }
  11700. return false;
  11701. }
  11702. @@ -1637,7 +1649,7 @@
  11703. ThreadStateTransition::transition_and_fence(this, _thread_new, _thread_in_vm);
  11704. assert(JavaThread::current() == this, "sanity check");
  11705. - assert(!Thread::current()->owns_locks(), "sanity check");
  11706. + assert(!Thread::current()->owns_locks_but_redefine_classes_lock(), "sanity check");
  11707. DTRACE_THREAD_PROBE(start, this);
  11708. @@ -3193,7 +3205,7 @@
  11709. // Create a CompilerThread
  11710. CompilerThread::CompilerThread(CompileQueue* queue, CompilerCounters* counters)
  11711. -: JavaThread(&compiler_thread_entry) {
  11712. +: JavaThread(&compiler_thread_entry), _should_bailout(false) {
  11713. _env = NULL;
  11714. _log = NULL;
  11715. _task = NULL;
  11716. @@ -3201,6 +3213,7 @@
  11717. _counters = counters;
  11718. _buffer_blob = NULL;
  11719. _scanned_nmethod = NULL;
  11720. + _compilation_mutex = new Mutex(Mutex::redefine_classes, "compilationMutex", false);
  11721. #ifndef PRODUCT
  11722. _ideal_graph_printer = NULL;
  11723. @@ -3230,6 +3243,7 @@
  11724. int Threads::_number_of_non_daemon_threads = 0;
  11725. int Threads::_return_code = 0;
  11726. size_t JavaThread::_stack_size_at_create = 0;
  11727. +bool Threads::_wait_at_instrumentation_entry = false;
  11728. // All JavaThreads
  11729. #define ALL_JAVA_THREADS(X) for (JavaThread* X = _thread_list; X; X = X->next())
  11730. diff --git a/src/share/vm/runtime/thread.hpp b/src/share/vm/runtime/thread.hpp
  11731. index 774bd27..4ca4502 100644
  11732. --- a/src/share/vm/runtime/thread.hpp
  11733. +++ b/src/share/vm/runtime/thread.hpp
  11734. @@ -203,10 +203,13 @@
  11735. void enter_signal_handler() { _num_nested_signal++; }
  11736. void leave_signal_handler() { _num_nested_signal--; }
  11737. bool is_inside_signal_handler() const { return _num_nested_signal > 0; }
  11738. + Mutex* redefine_classes_mutex() { return _redefine_classes_mutex; }
  11739. private:
  11740. // Debug tracing
  11741. static void trace(const char* msg, const Thread* const thread) PRODUCT_RETURN;
  11742. +
  11743. + Mutex* _redefine_classes_mutex;
  11744. // Active_handles points to a block of handles
  11745. JNIHandleBlock* _active_handles;
  11746. @@ -530,10 +533,15 @@
  11747. uintptr_t _self_raw_id; // used by get_thread (mutable)
  11748. int _lgrp_id;
  11749. +
  11750. + bool _pretend_new_universe;
  11751. +
  11752. public:
  11753. // Stack overflow support
  11754. address stack_base() const { assert(_stack_base != NULL,"Sanity check"); return _stack_base; }
  11755. + 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; } }
  11756. + bool pretend_new_universe() { return _pretend_new_universe; }
  11757. void set_stack_base(address base) { _stack_base = base; }
  11758. size_t stack_size() const { return _stack_size; }
  11759. void set_stack_size(size_t size) { _stack_size = size; }
  11760. @@ -570,6 +578,7 @@
  11761. void print_owned_locks() const { print_owned_locks_on(tty); }
  11762. Monitor* owned_locks() const { return _owned_locks; }
  11763. bool owns_locks() const { return owned_locks() != NULL; }
  11764. + bool owns_locks_but_redefine_classes_lock() const;
  11765. bool owns_locks_but_compiled_lock() const;
  11766. // Deadlock detection
  11767. @@ -1793,6 +1802,8 @@
  11768. CompileTask* _task;
  11769. CompileQueue* _queue;
  11770. BufferBlob* _buffer_blob;
  11771. + bool _should_bailout;
  11772. + Mutex* _compilation_mutex;
  11773. nmethod* _scanned_nmethod; // nmethod being scanned by the sweeper
  11774. @@ -1802,12 +1813,16 @@
  11775. CompilerThread(CompileQueue* queue, CompilerCounters* counters);
  11776. + bool should_bailout() const { return _should_bailout; }
  11777. + void set_should_bailout(bool b) { _should_bailout = false; }
  11778. +
  11779. bool is_Compiler_thread() const { return true; }
  11780. // Hide this compiler thread from external view.
  11781. bool is_hidden_from_external_view() const { return true; }
  11782. CompileQueue* queue() { return _queue; }
  11783. CompilerCounters* counters() { return _counters; }
  11784. + Mutex *compilation_mutex() { return _compilation_mutex; }
  11785. // Get/set the thread's compilation environment.
  11786. ciEnv* env() { return _env; }
  11787. @@ -1862,6 +1877,7 @@
  11788. static int _number_of_threads;
  11789. static int _number_of_non_daemon_threads;
  11790. static int _return_code;
  11791. + static bool _wait_at_instrumentation_entry;
  11792. public:
  11793. // Thread management
  11794. @@ -1873,6 +1889,9 @@
  11795. static JavaThread* first() { return _thread_list; }
  11796. static void threads_do(ThreadClosure* tc);
  11797. + static bool wait_at_instrumentation_entry() { return _wait_at_instrumentation_entry; }
  11798. + static void set_wait_at_instrumentation_entry(bool b) { _wait_at_instrumentation_entry = b; }
  11799. +
  11800. // Initializes the vm and creates the vm thread
  11801. static jint create_vm(JavaVMInitArgs* args, bool* canTryAgain);
  11802. static void convert_vm_init_libraries_to_agents();
  11803. diff --git a/src/share/vm/runtime/vframe.cpp b/src/share/vm/runtime/vframe.cpp
  11804. index 09e324f..d47ffef 100644
  11805. --- a/src/share/vm/runtime/vframe.cpp
  11806. +++ b/src/share/vm/runtime/vframe.cpp
  11807. @@ -253,6 +253,46 @@
  11808. return fr().interpreter_frame_method();
  11809. }
  11810. +// (tw) Sets interpreter frame method.
  11811. +void interpretedVFrame::set_method(methodOop new_method, int new_bci) {
  11812. + methodOop old_method = fr().interpreter_frame_method();
  11813. + int old_stack_size = fr().interpreter_frame_expression_stack_size();
  11814. + if (old_method == new_method) return;
  11815. + u_char *old_bcp = bcp();
  11816. + int old_bci = bci();
  11817. + fr().interpreter_frame_set_method(new_method);
  11818. + fr().interpreter_frame_set_cache(new_method->constants()->cache());
  11819. + u_char *new_bcp = new_method->code_base() + new_bci;
  11820. + assert(new_method->bcp_from(new_bci) == new_bcp, "");
  11821. +
  11822. + set_bcp(new_bcp);
  11823. +
  11824. + Bytecodes::Code code = Bytecodes::java_code_at(old_method, old_bcp);
  11825. + assert(Bytecodes::java_code_at(new_method, new_bcp) == code, "must have same bytecode at this position");
  11826. +
  11827. + switch (code) {
  11828. + case Bytecodes::_invokevirtual :
  11829. + case Bytecodes::_invokespecial :
  11830. + case Bytecodes::_invokestatic :
  11831. + case Bytecodes::_invokeinterface: {
  11832. + int old_index = Bytes::get_native_u2(old_bcp+1);
  11833. + int new_index = Bytes::get_native_u2(new_bcp+1);
  11834. + new_method->constants()->cache()->entry_at(new_index)->copy_from(old_method->constants()->cache()->entry_at(old_index));
  11835. + break;
  11836. + }
  11837. +
  11838. + case Bytecodes::_invokedynamic: {
  11839. + int old_index = Bytes::get_native_u4(old_bcp+1);
  11840. + int new_index = Bytes::get_native_u4(new_bcp+1);
  11841. + new_method->constants()->cache()->secondary_entry_at(new_index)->copy_from(old_method->constants()->cache()->secondary_entry_at(old_index));
  11842. + break;
  11843. + }
  11844. + }
  11845. +
  11846. + int new_stack_size = fr().interpreter_frame_expression_stack_size();
  11847. + assert(new_method->validate_bci_from_bcx((intptr_t)new_bcp) == new_bci, "");
  11848. +}
  11849. +
  11850. StackValueCollection* interpretedVFrame::locals() const {
  11851. int length = method()->max_locals();
  11852. diff --git a/src/share/vm/runtime/vframe.hpp b/src/share/vm/runtime/vframe.hpp
  11853. index badfea5..edbc5c7 100644
  11854. --- a/src/share/vm/runtime/vframe.hpp
  11855. +++ b/src/share/vm/runtime/vframe.hpp
  11856. @@ -163,6 +163,7 @@
  11857. StackValueCollection* locals() const;
  11858. StackValueCollection* expressions() const;
  11859. GrowableArray<MonitorInfo*>* monitors() const;
  11860. + void set_method(methodOop method, int new_bci);
  11861. void set_locals(StackValueCollection* values) const;
  11862. diff --git a/src/share/vm/runtime/vmThread.cpp b/src/share/vm/runtime/vmThread.cpp
  11863. index 0a3e0da..3d294e1 100644
  11864. --- a/src/share/vm/runtime/vmThread.cpp
  11865. +++ b/src/share/vm/runtime/vmThread.cpp
  11866. @@ -694,6 +694,10 @@
  11867. void VMThread::oops_do(OopClosure* f, CodeBlobClosure* cf) {
  11868. Thread::oops_do(f, cf);
  11869. _vm_queue->oops_do(f);
  11870. + // (DCEVM) need to update oops in VM_RedefineClasses!
  11871. + if (_cur_vm_operation != NULL) {
  11872. + _cur_vm_operation->oops_do(f);
  11873. + }
  11874. }
  11875. //------------------------------------------------------------------------------------------------------------------
  11876. diff --git a/src/share/vm/utilities/exceptions.cpp b/src/share/vm/utilities/exceptions.cpp
  11877. index 03f254d..c9e0efc 100644
  11878. --- a/src/share/vm/utilities/exceptions.cpp
  11879. +++ b/src/share/vm/utilities/exceptions.cpp
  11880. @@ -254,6 +254,8 @@
  11881. assert(thread->is_Java_thread(), "can only be called by a Java thread");
  11882. assert(!thread->has_pending_exception(), "already has exception");
  11883. + bool old_pretend_value = Thread::current()->pretend_new_universe();
  11884. + Thread::current()->set_pretend_new_universe(false);
  11885. Handle h_exception;
  11886. // Resolve exception klass
  11887. @@ -285,6 +287,7 @@
  11888. h_exception = Handle(thread, thread->pending_exception());
  11889. thread->clear_pending_exception();
  11890. }
  11891. + Thread::current()->set_pretend_new_universe(old_pretend_value);
  11892. return h_exception;
  11893. }
  11894. @@ -295,6 +298,8 @@
  11895. Symbol* signature, JavaCallArguments *args,
  11896. Handle h_cause,
  11897. Handle h_loader, Handle h_protection_domain) {
  11898. + bool old_pretend_value = Thread::current()->pretend_new_universe();
  11899. + Thread::current()->set_pretend_new_universe(false);
  11900. Handle h_exception = new_exception(thread, name, signature, args, h_loader, h_protection_domain);
  11901. // Future: object initializer should take a cause argument
  11902. @@ -317,6 +322,8 @@
  11903. h_exception = Handle(thread, thread->pending_exception());
  11904. thread->clear_pending_exception();
  11905. }
  11906. +
  11907. + Thread::current()->set_pretend_new_universe(old_pretend_value);
  11908. return h_exception;
  11909. }
  11910. diff --git a/src/share/vm/utilities/growableArray.hpp b/src/share/vm/utilities/growableArray.hpp
  11911. index ea92a80..05e940e 100644
  11912. --- a/src/share/vm/utilities/growableArray.hpp
  11913. +++ b/src/share/vm/utilities/growableArray.hpp
  11914. @@ -145,6 +145,33 @@
  11915. assert(on_stack(), "fast ResourceObj path only");
  11916. return (void*)resource_allocate_bytes(thread, elementSize * _max);
  11917. }
  11918. +
  11919. +};
  11920. +
  11921. +template<class E, class F> class Pair : public StackObj
  11922. +{
  11923. +private:
  11924. + E _left;
  11925. + F _right;
  11926. +
  11927. +public:
  11928. +
  11929. + Pair() {
  11930. +
  11931. + }
  11932. +
  11933. + Pair(E left, F right) {
  11934. + this->_left = left;
  11935. + this->_right = right;
  11936. + }
  11937. +
  11938. + E left() {
  11939. + return _left;
  11940. + }
  11941. +
  11942. + F right() {
  11943. + return _right;
  11944. + }
  11945. };
  11946. template<class E> class GrowableArray : public GenericGrowableArray {