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

light-jdk8u5-b13.patch 174KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258
  1. diff -r 8a6717910608 make/openjdk_distro
  2. --- a/make/openjdk_distro Tue Mar 11 13:02:13 2014 -0700
  3. +++ b/make/openjdk_distro Wed Apr 30 11:27:18 2014 -0700
  4. @@ -27,6 +27,6 @@
  5. #
  6. # Don't put quotes (fail windows build).
  7. -HOTSPOT_VM_DISTRO=OpenJDK
  8. +HOTSPOT_VM_DISTRO=Dynamic Code Evolution
  9. COMPANY_NAME=
  10. PRODUCT_NAME=OpenJDK
  11. diff -r 8a6717910608 src/share/vm/ci/ciObjectFactory.cpp
  12. --- a/src/share/vm/ci/ciObjectFactory.cpp Tue Mar 11 13:02:13 2014 -0700
  13. +++ b/src/share/vm/ci/ciObjectFactory.cpp Wed Apr 30 11:27:18 2014 -0700
  14. @@ -750,3 +750,27 @@
  15. _unloaded_instances->length(),
  16. _unloaded_klasses->length());
  17. }
  18. +
  19. +int ciObjectFactory::compare_cimetadata(ciMetadata** a, ciMetadata** b) {
  20. + Metadata* am = (*a)->constant_encoding();
  21. + Metadata* bm = (*b)->constant_encoding();
  22. + return ((am > bm) ? 1 : ((am == bm) ? 0 : -1));
  23. +}
  24. +
  25. +// (DCEVM) Resoring the ciObject arrays after class redefinition
  26. +void ciObjectFactory::resort_shared_ci_metadata() {
  27. + if (_shared_ci_metadata == NULL) return;
  28. + _shared_ci_metadata->sort(ciObjectFactory::compare_cimetadata);
  29. +
  30. +#ifdef ASSERT
  31. + if (CIObjectFactoryVerify) {
  32. + Metadata* last = NULL;
  33. + for (int j = 0; j< _shared_ci_metadata->length(); j++) {
  34. + Metadata* o = _shared_ci_metadata->at(j)->constant_encoding();
  35. + assert(last < o, "out of order");
  36. + last = o;
  37. + }
  38. + }
  39. +#endif // ASSERT
  40. +}
  41. +
  42. diff -r 8a6717910608 src/share/vm/ci/ciObjectFactory.hpp
  43. --- a/src/share/vm/ci/ciObjectFactory.hpp Tue Mar 11 13:02:13 2014 -0700
  44. +++ b/src/share/vm/ci/ciObjectFactory.hpp Wed Apr 30 11:27:18 2014 -0700
  45. @@ -90,6 +90,7 @@
  46. ciInstance* get_unloaded_instance(ciInstanceKlass* klass);
  47. + static int compare_cimetadata(ciMetadata** a, ciMetadata** b);
  48. public:
  49. static bool is_initialized() { return _initialized; }
  50. @@ -145,6 +146,8 @@
  51. void print_contents();
  52. void print();
  53. +
  54. + static void resort_shared_ci_metadata();
  55. };
  56. #endif // SHARE_VM_CI_CIOBJECTFACTORY_HPP
  57. diff -r 8a6717910608 src/share/vm/classfile/classFileParser.cpp
  58. --- a/src/share/vm/classfile/classFileParser.cpp Tue Mar 11 13:02:13 2014 -0700
  59. +++ b/src/share/vm/classfile/classFileParser.cpp Wed Apr 30 11:27:18 2014 -0700
  60. @@ -759,6 +759,7 @@
  61. Array<Klass*>* ClassFileParser::parse_interfaces(int length,
  62. Handle protection_domain,
  63. Symbol* class_name,
  64. + bool pick_newest,
  65. bool* has_default_methods,
  66. TRAPS) {
  67. if (length == 0) {
  68. @@ -777,7 +778,11 @@
  69. "Interface name has bad constant pool index %u in class file %s",
  70. interface_index, CHECK_NULL);
  71. if (_cp->tag_at(interface_index).is_klass()) {
  72. - interf = KlassHandle(THREAD, _cp->resolved_klass_at(interface_index));
  73. + Klass* resolved_klass = _cp->resolved_klass_at(interface_index);
  74. + if (pick_newest) {
  75. + resolved_klass = resolved_klass->newest_version();
  76. + }
  77. + interf = KlassHandle(THREAD, resolved_klass);
  78. } else {
  79. Symbol* unresolved_klass = _cp->klass_name_at(interface_index);
  80. @@ -791,6 +796,9 @@
  81. Klass* k = SystemDictionary::resolve_super_or_fail(class_name,
  82. unresolved_klass, class_loader, protection_domain,
  83. false, CHECK_NULL);
  84. + if (pick_newest) {
  85. + k = k->newest_version();
  86. + }
  87. interf = KlassHandle(THREAD, k);
  88. }
  89. @@ -3093,6 +3101,7 @@
  90. }
  91. instanceKlassHandle ClassFileParser::parse_super_class(int super_class_index,
  92. + bool pick_newest,
  93. TRAPS) {
  94. instanceKlassHandle super_klass;
  95. if (super_class_index == 0) {
  96. @@ -3109,7 +3118,11 @@
  97. // However, make sure it is not an array type.
  98. bool is_array = false;
  99. if (_cp->tag_at(super_class_index).is_klass()) {
  100. - super_klass = instanceKlassHandle(THREAD, _cp->resolved_klass_at(super_class_index));
  101. + Klass* resolved_klass = _cp->resolved_klass_at(super_class_index);
  102. + if (pick_newest) {
  103. + resolved_klass = resolved_klass->newest_version();
  104. + }
  105. + super_klass = instanceKlassHandle(THREAD, resolved_klass);
  106. if (_need_verify)
  107. is_array = super_klass->oop_is_array();
  108. } else if (_need_verify) {
  109. @@ -3658,8 +3671,10 @@
  110. instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
  111. ClassLoaderData* loader_data,
  112. Handle protection_domain,
  113. + KlassHandle old_klass,
  114. KlassHandle host_klass,
  115. GrowableArray<Handle>* cp_patches,
  116. + GrowableArray<Symbol*>* parsed_super_symbols,
  117. TempNewSymbol& parsed_name,
  118. bool verify,
  119. TRAPS) {
  120. @@ -3672,6 +3687,7 @@
  121. JvmtiCachedClassFileData *cached_class_file = NULL;
  122. Handle class_loader(THREAD, loader_data->class_loader());
  123. bool has_default_methods = false;
  124. + bool pick_newest = !old_klass.is_null();
  125. ResourceMark rm(THREAD);
  126. ClassFileStream* cfs = stream();
  127. @@ -3688,7 +3704,7 @@
  128. init_parsed_class_attributes(loader_data);
  129. - if (JvmtiExport::should_post_class_file_load_hook()) {
  130. + if (parsed_super_symbols == NULL && JvmtiExport::should_post_class_file_load_hook()) {
  131. // Get the cached class file bytes (if any) from the class that
  132. // is being redefined or retransformed. We use jvmti_thread_state()
  133. // instead of JvmtiThreadState::state_for(jt) so we don't allocate
  134. @@ -3823,6 +3839,26 @@
  135. CHECK_(nullHandle));
  136. }
  137. + // (DCEVM) Do not parse full class file, only get super symbols and return.
  138. + if (parsed_super_symbols != NULL) {
  139. + u2 super_class_index = cfs->get_u2_fast();
  140. +
  141. + if (super_class_index != 0) {
  142. + parsed_super_symbols->append(cp->klass_name_at(super_class_index));
  143. + }
  144. +
  145. + // Interfaces
  146. + u2 itfs_len = cfs->get_u2_fast();
  147. + Array<Klass*>* local_interfaces =
  148. + parse_interfaces(itfs_len, protection_domain, _class_name, pick_newest, &has_default_methods, CHECK_NULL);
  149. +
  150. + for (int i = 0; i < local_interfaces->length(); i++) {
  151. + Klass* o = local_interfaces->at(i);
  152. + parsed_super_symbols->append(o->name());
  153. + }
  154. + return NULL;
  155. + }
  156. +
  157. Klass* preserve_this_klass; // for storing result across HandleMark
  158. // release all handles when parsing is done
  159. @@ -3849,13 +3885,14 @@
  160. u2 super_class_index = cfs->get_u2_fast();
  161. instanceKlassHandle super_klass = parse_super_class(super_class_index,
  162. + pick_newest,
  163. CHECK_NULL);
  164. // Interfaces
  165. u2 itfs_len = cfs->get_u2_fast();
  166. Array<Klass*>* local_interfaces =
  167. parse_interfaces(itfs_len, protection_domain, _class_name,
  168. - &has_default_methods, CHECK_(nullHandle));
  169. + pick_newest, &has_default_methods, CHECK_(nullHandle));
  170. u2 java_fields_count = 0;
  171. // Fields (offsets are filled in later)
  172. @@ -3897,6 +3934,9 @@
  173. true,
  174. CHECK_(nullHandle));
  175. + if (pick_newest) {
  176. + k = k->newest_version();
  177. + }
  178. KlassHandle kh (THREAD, k);
  179. super_klass = instanceKlassHandle(THREAD, kh());
  180. }
  181. @@ -4056,7 +4096,7 @@
  182. fill_oop_maps(this_klass, info.nonstatic_oop_map_count, info.nonstatic_oop_offsets, info.nonstatic_oop_counts);
  183. // Fill in has_finalizer, has_vanilla_constructor, and layout_helper
  184. - set_precomputed_flags(this_klass);
  185. + set_precomputed_flags(this_klass, old_klass);
  186. // reinitialize modifiers, using the InnerClasses attribute
  187. int computed_modifiers = this_klass->compute_modifier_flags(CHECK_(nullHandle));
  188. @@ -4283,7 +4323,7 @@
  189. }
  190. -void ClassFileParser::set_precomputed_flags(instanceKlassHandle k) {
  191. +void ClassFileParser::set_precomputed_flags(instanceKlassHandle k, KlassHandle old_klass) {
  192. Klass* super = k->super();
  193. // Check if this klass has an empty finalize method (i.e. one with return bytecode only),
  194. @@ -4291,7 +4331,9 @@
  195. if (!_has_empty_finalizer) {
  196. if (_has_finalizer ||
  197. (super != NULL && super->has_finalizer())) {
  198. - k->set_has_finalizer();
  199. + if (old_klass.is_null() || old_klass->has_finalizer()) {
  200. + k->set_has_finalizer();
  201. + }
  202. }
  203. }
  204. @@ -4307,7 +4349,7 @@
  205. // Check if this klass supports the java.lang.Cloneable interface
  206. if (SystemDictionary::Cloneable_klass_loaded()) {
  207. - if (k->is_subtype_of(SystemDictionary::Cloneable_klass())) {
  208. + if (k->is_subtype_of(SystemDictionary::Cloneable_klass()) || k->is_subtype_of(SystemDictionary::Cloneable_klass()->newest_version())) {
  209. k->set_is_cloneable();
  210. }
  211. }
  212. diff -r 8a6717910608 src/share/vm/classfile/classFileParser.hpp
  213. --- a/src/share/vm/classfile/classFileParser.hpp Tue Mar 11 13:02:13 2014 -0700
  214. +++ b/src/share/vm/classfile/classFileParser.hpp Wed Apr 30 11:27:18 2014 -0700
  215. @@ -214,11 +214,12 @@
  216. Array<Klass*>* parse_interfaces(int length,
  217. Handle protection_domain,
  218. Symbol* class_name,
  219. + bool pick_newest,
  220. bool* has_default_methods,
  221. TRAPS);
  222. void record_defined_class_dependencies(instanceKlassHandle defined_klass, TRAPS);
  223. - instanceKlassHandle parse_super_class(int super_class_index, TRAPS);
  224. + instanceKlassHandle parse_super_class(int super_class_index, bool pick_newest, TRAPS);
  225. // Field parsing
  226. void parse_field_attributes(u2 attributes_count,
  227. bool is_static, u2 signature_index,
  228. @@ -299,7 +300,7 @@
  229. unsigned int nonstatic_oop_map_count,
  230. int* nonstatic_oop_offsets,
  231. unsigned int* nonstatic_oop_counts);
  232. - void set_precomputed_flags(instanceKlassHandle k);
  233. + void set_precomputed_flags(instanceKlassHandle k, KlassHandle old_klass);
  234. Array<Klass*>* compute_transitive_interfaces(instanceKlassHandle super,
  235. Array<Klass*>* local_ifs, TRAPS);
  236. @@ -461,17 +462,20 @@
  237. instanceKlassHandle parseClassFile(Symbol* name,
  238. ClassLoaderData* loader_data,
  239. Handle protection_domain,
  240. + KlassHandle old_klass,
  241. TempNewSymbol& parsed_name,
  242. bool verify,
  243. TRAPS) {
  244. KlassHandle no_host_klass;
  245. - return parseClassFile(name, loader_data, protection_domain, no_host_klass, NULL, parsed_name, verify, THREAD);
  246. + return parseClassFile(name, loader_data, protection_domain, old_klass, no_host_klass, NULL, NULL, parsed_name, verify, THREAD);
  247. }
  248. instanceKlassHandle parseClassFile(Symbol* name,
  249. ClassLoaderData* loader_data,
  250. Handle protection_domain,
  251. + KlassHandle old_klass,
  252. KlassHandle host_klass,
  253. GrowableArray<Handle>* cp_patches,
  254. + GrowableArray<Symbol*>* parsed_super_symbols,
  255. TempNewSymbol& parsed_name,
  256. bool verify,
  257. TRAPS);
  258. diff -r 8a6717910608 src/share/vm/classfile/classLoader.cpp
  259. --- a/src/share/vm/classfile/classLoader.cpp Tue Mar 11 13:02:13 2014 -0700
  260. +++ b/src/share/vm/classfile/classLoader.cpp Wed Apr 30 11:27:18 2014 -0700
  261. @@ -926,6 +926,7 @@
  262. instanceKlassHandle result = parser.parseClassFile(h_name,
  263. loader_data,
  264. protection_domain,
  265. + KlassHandle(),
  266. parsed_name,
  267. false,
  268. CHECK_(h));
  269. diff -r 8a6717910608 src/share/vm/classfile/dictionary.cpp
  270. --- a/src/share/vm/classfile/dictionary.cpp Tue Mar 11 13:02:13 2014 -0700
  271. +++ b/src/share/vm/classfile/dictionary.cpp Wed Apr 30 11:27:18 2014 -0700
  272. @@ -145,7 +145,7 @@
  273. InstanceKlass* ik = InstanceKlass::cast(e);
  274. // Non-unloadable classes were handled in always_strong_oops_do
  275. - if (!is_strongly_reachable(loader_data, e)) {
  276. + if (!ik->is_redefining() && !is_strongly_reachable(loader_data, e)) {
  277. // Entry was not visited in phase1 (negated test from phase1)
  278. assert(!loader_data->is_the_null_class_loader_data(), "unloading entry with null class loader");
  279. ClassLoaderData* k_def_class_loader_data = ik->class_loader_data();
  280. @@ -336,6 +336,32 @@
  281. add_entry(index, entry);
  282. }
  283. +// (DCEVM) Updates the klass entry to point to the new Klass*. Necessary only for class redefinition.
  284. +bool Dictionary::update_klass(int index, unsigned int hash, Symbol* name, ClassLoaderData* loader_data, KlassHandle k, KlassHandle old_class) {
  285. +
  286. + // There are several entries for the same class in the dictionary: One extra entry for each parent classloader of the classloader of the class.
  287. + bool found = false;
  288. + for (int index = 0; index < table_size(); index++) {
  289. + for (DictionaryEntry* entry = bucket(index); entry != NULL; entry = entry->next()) {
  290. + if (entry->klass() == old_class()) {
  291. + entry->set_literal(k());
  292. + found = true;
  293. + }
  294. + }
  295. + }
  296. + return found;
  297. +}
  298. +
  299. +// (DCEVM) Undo previous updates to the system dictionary
  300. +void Dictionary::rollback_redefinition() {
  301. + for (int index = 0; index < table_size(); index++) {
  302. + for (DictionaryEntry* entry = bucket(index); entry != NULL; entry = entry->next()) {
  303. + if (entry->klass()->is_redefining()) {
  304. + entry->set_literal(entry->klass()->old_version());
  305. + }
  306. + }
  307. + }
  308. +}
  309. // This routine does not lock the system dictionary.
  310. //
  311. @@ -366,7 +392,7 @@
  312. ClassLoaderData* loader_data, Handle protection_domain, TRAPS) {
  313. DictionaryEntry* entry = get_entry(index, hash, name, loader_data);
  314. if (entry != NULL && entry->is_valid_protection_domain(protection_domain)) {
  315. - return entry->klass();
  316. + return intercept_for_version(entry->klass());
  317. } else {
  318. return NULL;
  319. }
  320. @@ -379,7 +405,7 @@
  321. assert (index == index_for(name, loader_data), "incorrect index?");
  322. DictionaryEntry* entry = get_entry(index, hash, name, loader_data);
  323. - return (entry != NULL) ? entry->klass() : (Klass*)NULL;
  324. + return intercept_for_version((entry != NULL) ? entry->klass() : (Klass*)NULL);
  325. }
  326. @@ -391,7 +417,7 @@
  327. assert (index == index_for(name, NULL), "incorrect index?");
  328. DictionaryEntry* entry = get_entry(index, hash, name, NULL);
  329. - return (entry != NULL) ? entry->klass() : (Klass*)NULL;
  330. + return intercept_for_version((entry != NULL) ? entry->klass() : (Klass*)NULL);
  331. }
  332. diff -r 8a6717910608 src/share/vm/classfile/dictionary.hpp
  333. --- a/src/share/vm/classfile/dictionary.hpp Tue Mar 11 13:02:13 2014 -0700
  334. +++ b/src/share/vm/classfile/dictionary.hpp Wed Apr 30 11:27:18 2014 -0700
  335. @@ -78,6 +78,10 @@
  336. void add_klass(Symbol* class_name, ClassLoaderData* loader_data,KlassHandle obj);
  337. + bool update_klass(int index, unsigned int hash, Symbol* name, ClassLoaderData* loader_data, KlassHandle k, KlassHandle old_class);
  338. +
  339. + void rollback_redefinition();
  340. +
  341. Klass* find_class(int index, unsigned int hash,
  342. Symbol* name, ClassLoaderData* loader_data);
  343. @@ -107,6 +111,11 @@
  344. return (loader_data->is_the_null_class_loader_data() || !ClassUnloading);
  345. }
  346. + // (DCEVM) During enhanced class redefinition we want old version if new is being redefined
  347. + static Klass* intercept_for_version(Klass* k) {
  348. + return (k != NULL && k->is_redefining()) ? k->old_version() : k;
  349. + }
  350. +
  351. // Unload (that is, break root links to) all unmarked classes and
  352. // loaders. Returns "true" iff something was unloaded.
  353. bool do_unloading();
  354. diff -r 8a6717910608 src/share/vm/classfile/javaClasses.cpp
  355. --- a/src/share/vm/classfile/javaClasses.cpp Tue Mar 11 13:02:13 2014 -0700
  356. +++ b/src/share/vm/classfile/javaClasses.cpp Wed Apr 30 11:27:18 2014 -0700
  357. @@ -1629,6 +1629,8 @@
  358. skip_throwableInit_check = true;
  359. }
  360. }
  361. + // (DCEVM): Line numbers from newest version must be used for EMCP-swapped methods
  362. + method = method->newest_version();
  363. if (method->is_hidden()) {
  364. if (skip_hidden) continue;
  365. }
  366. diff -r 8a6717910608 src/share/vm/classfile/loaderConstraints.cpp
  367. --- a/src/share/vm/classfile/loaderConstraints.cpp Tue Mar 11 13:02:13 2014 -0700
  368. +++ b/src/share/vm/classfile/loaderConstraints.cpp Wed Apr 30 11:27:18 2014 -0700
  369. @@ -446,7 +446,7 @@
  370. if (k != NULL) {
  371. // We found the class in the system dictionary, so we should
  372. // make sure that the Klass* matches what we already have.
  373. - guarantee(k == probe->klass(), "klass should be in dictionary");
  374. + guarantee(k == probe->klass()->newest_version(), "klass should be in dictionary");
  375. } else {
  376. // If we don't find the class in the system dictionary, it
  377. // has to be in the placeholders table.
  378. diff -r 8a6717910608 src/share/vm/classfile/systemDictionary.cpp
  379. --- a/src/share/vm/classfile/systemDictionary.cpp Tue Mar 11 13:02:13 2014 -0700
  380. +++ b/src/share/vm/classfile/systemDictionary.cpp Wed Apr 30 11:27:18 2014 -0700
  381. @@ -174,6 +174,7 @@
  382. // can return a null klass
  383. klass = handle_resolution_exception(class_name, class_loader, protection_domain, throw_error, k_h, THREAD);
  384. }
  385. + assert(klass == NULL || klass->is_newest_version() || klass->newest_version()->is_redefining(), "must be");
  386. return klass;
  387. }
  388. @@ -216,7 +217,7 @@
  389. // Forwards to resolve_instance_class_or_null
  390. Klass* SystemDictionary::resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS) {
  391. - assert(!THREAD->is_Compiler_thread(),
  392. + assert(!THREAD->is_Compiler_thread() || JvmtiThreadState::state_for(JavaThread::current())->get_class_being_redefined() != NULL,
  393. err_msg("can not load classes with compiler thread: class=%s, classloader=%s",
  394. class_name->as_C_string(),
  395. class_loader.is_null() ? "null" : class_loader->klass()->name()->as_C_string()));
  396. @@ -1029,8 +1030,10 @@
  397. instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
  398. loader_data,
  399. protection_domain,
  400. + KlassHandle(),
  401. host_klass,
  402. cp_patches,
  403. + NULL,
  404. parsed_name,
  405. true,
  406. THREAD);
  407. @@ -1085,6 +1088,7 @@
  408. Handle protection_domain,
  409. ClassFileStream* st,
  410. bool verify,
  411. + KlassHandle old_class,
  412. TRAPS) {
  413. // Classloaders that support parallelism, e.g. bootstrap classloader,
  414. @@ -1112,9 +1116,15 @@
  415. instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
  416. loader_data,
  417. protection_domain,
  418. + old_class,
  419. parsed_name,
  420. verify,
  421. THREAD);
  422. + // (DCEVM) During enhanced class redefinition, mark loaded class as being redefined
  423. + if (!old_class.is_null() && !k.is_null()) {
  424. + k->set_redefining(true);
  425. + k->set_old_version(old_class());
  426. + }
  427. const char* pkg = "java/";
  428. if (!HAS_PENDING_EXCEPTION &&
  429. @@ -1149,10 +1159,11 @@
  430. // Add class just loaded
  431. // If a class loader supports parallel classloading handle parallel define requests
  432. // find_or_define_instance_class may return a different InstanceKlass
  433. - if (is_parallelCapable(class_loader)) {
  434. + // (DCEVM) TODO: for class redefinition the parallel version does not work, check if this is a problem?
  435. + if (is_parallelCapable(class_loader) && old_class.is_null()) {
  436. k = find_or_define_instance_class(class_name, class_loader, k, THREAD);
  437. } else {
  438. - define_instance_class(k, THREAD);
  439. + define_instance_class(k, old_class, THREAD);
  440. }
  441. }
  442. @@ -1166,7 +1177,7 @@
  443. MutexLocker mu(SystemDictionary_lock, THREAD);
  444. Klass* check = find_class(parsed_name, loader_data);
  445. - assert(check == k(), "should be present in the dictionary");
  446. + assert((check == k() && !k->is_redefining()) || (k->is_redefining() && check == k->old_version()), "should be present in the dictionary");
  447. Klass* check2 = find_class(h_name, defining_loader_data);
  448. assert(check == check2, "name inconsistancy in SystemDictionary");
  449. @@ -1386,7 +1397,11 @@
  450. }
  451. }
  452. -void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) {
  453. +void SystemDictionary::rollback_redefinition() {
  454. + dictionary()->rollback_redefinition();
  455. +}
  456. +
  457. +void SystemDictionary::define_instance_class(instanceKlassHandle k, KlassHandle old_class, TRAPS) {
  458. ClassLoaderData* loader_data = k->class_loader_data();
  459. Handle class_loader_h(THREAD, loader_data->class_loader());
  460. @@ -1416,7 +1431,17 @@
  461. Symbol* name_h = k->name();
  462. unsigned int d_hash = dictionary()->compute_hash(name_h, loader_data);
  463. int d_index = dictionary()->hash_to_index(d_hash);
  464. - check_constraints(d_index, d_hash, k, class_loader_h, true, CHECK);
  465. +
  466. + // (DCEVM) Update version of the Klass* in the system dictionary
  467. + // TODO: Check for thread safety!
  468. + if (!old_class.is_null()) {
  469. + bool ok = dictionary()->update_klass(d_index, d_hash, name_h, loader_data, k, old_class);
  470. + assert (ok, "must have found old class and updated!");
  471. + }
  472. + check_constraints(d_index, d_hash, k, class_loader_h, old_class.is_null(), CHECK);
  473. +
  474. + // FIXME: (DCEVM) clean this...
  475. + if(!old_class.is_null() && TraceRedefineClasses >= 3){ tty->print_cr("Class has been updated!"); }
  476. // Register class just loaded with class loader (placed in Vector)
  477. // Note we do this before updating the dictionary, as this can
  478. @@ -1449,8 +1474,9 @@
  479. }
  480. k->eager_initialize(THREAD);
  481. + // (DCEVM) Only notify jvmti if not redefining a class.
  482. // notify jvmti
  483. - if (JvmtiExport::should_post_class_load()) {
  484. + if (JvmtiExport::should_post_class_load() && old_class.is_null()) {
  485. assert(THREAD->is_Java_thread(), "thread->is_Java_thread()");
  486. JvmtiExport::post_class_load((JavaThread *) THREAD, k());
  487. @@ -1524,7 +1550,7 @@
  488. }
  489. }
  490. - define_instance_class(k, THREAD);
  491. + define_instance_class(k, KlassHandle(), THREAD);
  492. Handle linkage_exception = Handle(); // null handle
  493. @@ -1654,6 +1680,14 @@
  494. Universe::flush_dependents_on(k);
  495. }
  496. +// (DCEVM) Remove from hierarchy - Undo add_to_hierarchy.
  497. +void SystemDictionary::remove_from_hierarchy(instanceKlassHandle k) {
  498. + assert(k.not_null(), "just checking");
  499. +
  500. + // remove receiver from sibling list
  501. + k->remove_from_sibling_list();
  502. + // TODO (DCEVM): Remove from interfaces.
  503. +}
  504. // ----------------------------------------------------------------------------
  505. // GC support
  506. @@ -2000,7 +2034,7 @@
  507. // also holds array classes
  508. assert(check->oop_is_instance(), "noninstance in systemdictionary");
  509. - if ((defining == true) || (k() != check)) {
  510. + if ((defining == true) && ((k() != check) && k->old_version() != check)) {
  511. linkage_error = "loader (instance of %s): attempted duplicate class "
  512. "definition for name: \"%s\"";
  513. } else {
  514. diff -r 8a6717910608 src/share/vm/classfile/systemDictionary.hpp
  515. --- a/src/share/vm/classfile/systemDictionary.hpp Tue Mar 11 13:02:13 2014 -0700
  516. +++ b/src/share/vm/classfile/systemDictionary.hpp Wed Apr 30 11:27:18 2014 -0700
  517. @@ -269,7 +269,7 @@
  518. // Resolve from stream (called by jni_DefineClass and JVM_DefineClass)
  519. static Klass* resolve_from_stream(Symbol* class_name, Handle class_loader,
  520. Handle protection_domain,
  521. - ClassFileStream* st, bool verify, TRAPS);
  522. + ClassFileStream* st, bool verify, KlassHandle old_class, TRAPS);
  523. // Lookup an already loaded class. If not found NULL is returned.
  524. static Klass* find(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS);
  525. @@ -339,6 +339,8 @@
  526. // System loader lock
  527. static oop system_loader_lock() { return _system_loader_lock_obj; }
  528. + // (DCEVM) Remove link to hierarchy
  529. + static void remove_from_hierarchy(instanceKlassHandle k);
  530. private:
  531. // Extended Redefine classes support (tbi)
  532. static void preloaded_classes_do(KlassClosure* f);
  533. @@ -408,6 +410,9 @@
  534. initialize_wk_klasses_until((WKID) limit, start_id, THREAD);
  535. }
  536. + // (DCEVM) rollback class redefinition
  537. + static void rollback_redefinition();
  538. +
  539. public:
  540. #define WK_KLASS_DECLARE(name, symbol, option) \
  541. static Klass* name() { return check_klass_##option(_well_known_klasses[WK_KLASS_ENUM_NAME(name)]); } \
  542. @@ -613,7 +618,7 @@
  543. // after waiting, but before reentering SystemDictionary_lock
  544. // to preserve lock order semantics.
  545. static void double_lock_wait(Handle lockObject, TRAPS);
  546. - static void define_instance_class(instanceKlassHandle k, TRAPS);
  547. + static void define_instance_class(instanceKlassHandle k, KlassHandle old_class, TRAPS);
  548. static instanceKlassHandle find_or_define_instance_class(Symbol* class_name,
  549. Handle class_loader,
  550. instanceKlassHandle k, TRAPS);
  551. diff -r 8a6717910608 src/share/vm/classfile/verifier.cpp
  552. --- a/src/share/vm/classfile/verifier.cpp Tue Mar 11 13:02:13 2014 -0700
  553. +++ b/src/share/vm/classfile/verifier.cpp Wed Apr 30 11:27:18 2014 -0700
  554. @@ -189,7 +189,7 @@
  555. Symbol* name = klass->name();
  556. Klass* refl_magic_klass = SystemDictionary::reflect_MagicAccessorImpl_klass();
  557. - bool is_reflect = refl_magic_klass != NULL && klass->is_subtype_of(refl_magic_klass);
  558. + bool is_reflect = refl_magic_klass != NULL && (klass->is_subtype_of(refl_magic_klass) || klass->is_subtype_of(refl_magic_klass->newest_version()));
  559. return (should_verify_for(klass->class_loader(), should_verify_class) &&
  560. // return if the class is a bootstrapping class
  561. @@ -518,7 +518,7 @@
  562. ClassVerifier::ClassVerifier(
  563. instanceKlassHandle klass, TRAPS)
  564. - : _thread(THREAD), _exception_type(NULL), _message(NULL), _klass(klass) {
  565. + : _thread(THREAD), _exception_type(NULL), _message(NULL), _klass(klass->newest_version()), _klass_to_verify(klass) {
  566. _this_type = VerificationType::reference_type(klass->name());
  567. // Create list to hold symbols in reference area.
  568. _symbols = new GrowableArray<Symbol*>(100, 0, NULL);
  569. @@ -548,7 +548,7 @@
  570. _klass->external_name());
  571. }
  572. - Array<Method*>* methods = _klass->methods();
  573. + Array<Method*>* methods = _klass_to_verify->methods();
  574. int num_methods = methods->length();
  575. for (int index = 0; index < num_methods; index++) {
  576. diff -r 8a6717910608 src/share/vm/classfile/verifier.hpp
  577. --- a/src/share/vm/classfile/verifier.hpp Tue Mar 11 13:02:13 2014 -0700
  578. +++ b/src/share/vm/classfile/verifier.hpp Wed Apr 30 11:27:18 2014 -0700
  579. @@ -331,6 +331,7 @@
  580. VerificationType object_type() const;
  581. + instanceKlassHandle _klass_to_verify;
  582. instanceKlassHandle _klass; // the class being verified
  583. methodHandle _method; // current method being verified
  584. VerificationType _this_type; // the verification type of the current class
  585. diff -r 8a6717910608 src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
  586. --- a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp Tue Mar 11 13:02:13 2014 -0700
  587. +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp Wed Apr 30 11:27:18 2014 -0700
  588. @@ -161,6 +161,12 @@
  589. }
  590. }
  591. +HeapWord* CompactibleFreeListSpace::forward_compact_top(size_t size,
  592. + CompactPoint* cp, HeapWord* compact_top) {
  593. + ShouldNotReachHere();
  594. + return NULL;
  595. +}
  596. +
  597. // Like CompactibleSpace forward() but always calls cross_threshold() to
  598. // update the block offset table. Removed initialize_threshold call because
  599. // CFLS does not use a block offset array for contiguous spaces.
  600. @@ -2098,7 +2104,7 @@
  601. // Support for compaction
  602. void CompactibleFreeListSpace::prepare_for_compaction(CompactPoint* cp) {
  603. - SCAN_AND_FORWARD(cp,end,block_is_obj,block_size);
  604. + SCAN_AND_FORWARD(cp,end,block_is_obj,block_size,false);
  605. // prepare_for_compaction() uses the space between live objects
  606. // so that later phase can skip dead space quickly. So verification
  607. // of the free lists doesn't work after.
  608. @@ -2119,7 +2125,7 @@
  609. }
  610. void CompactibleFreeListSpace::compact() {
  611. - SCAN_AND_COMPACT(obj_size);
  612. + SCAN_AND_COMPACT(obj_size, false);
  613. }
  614. // fragmentation_metric = 1 - [sum of (fbs**2) / (sum of fbs)**2]
  615. diff -r 8a6717910608 src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
  616. --- a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp Tue Mar 11 13:02:13 2014 -0700
  617. +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp Wed Apr 30 11:27:18 2014 -0700
  618. @@ -150,6 +150,7 @@
  619. // Support for compacting cms
  620. HeapWord* cross_threshold(HeapWord* start, HeapWord* end);
  621. + HeapWord* forward_compact_top(size_t size, CompactPoint* cp, HeapWord* compact_top);
  622. HeapWord* forward(oop q, size_t size, CompactPoint* cp, HeapWord* compact_top);
  623. // Initialization helpers.
  624. diff -r 8a6717910608 src/share/vm/gc_implementation/shared/markSweep.cpp
  625. --- a/src/share/vm/gc_implementation/shared/markSweep.cpp Tue Mar 11 13:02:13 2014 -0700
  626. +++ b/src/share/vm/gc_implementation/shared/markSweep.cpp Wed Apr 30 11:27:18 2014 -0700
  627. @@ -32,6 +32,8 @@
  628. #include "oops/objArrayKlass.inline.hpp"
  629. #include "oops/oop.inline.hpp"
  630. +GrowableArray<HeapWord*>* MarkSweep::_rescued_oops = NULL;
  631. +
  632. uint MarkSweep::_total_invocations = 0;
  633. Stack<oop, mtGC> MarkSweep::_marking_stack;
  634. @@ -171,3 +173,100 @@
  635. }
  636. #endif
  637. +
  638. +// (DCEVM) Copy the rescued objects to their destination address after compaction.
  639. +void MarkSweep::copy_rescued_objects_back() {
  640. +
  641. + if (_rescued_oops != NULL) {
  642. +
  643. + for (int i=0; i<_rescued_oops->length(); i++) {
  644. + HeapWord* rescued_ptr = _rescued_oops->at(i);
  645. + oop rescued_obj = (oop) rescued_ptr;
  646. +
  647. + int size = rescued_obj->size();
  648. + oop new_obj = rescued_obj->forwardee();
  649. +
  650. + assert(rescued_obj->klass()->new_version() != NULL, "just checking");
  651. +
  652. + if (rescued_obj->klass()->new_version()->update_information() != NULL) {
  653. + MarkSweep::update_fields(rescued_obj, new_obj);
  654. + } else {
  655. + rescued_obj->set_klass(rescued_obj->klass()->new_version());
  656. + Copy::aligned_disjoint_words((HeapWord*)rescued_obj, (HeapWord*)new_obj, size);
  657. + }
  658. +
  659. + FREE_RESOURCE_ARRAY(HeapWord, rescued_ptr, size);
  660. +
  661. + new_obj->init_mark();
  662. + assert(new_obj->is_oop(), "must be a valid oop");
  663. + }
  664. + _rescued_oops->clear();
  665. + _rescued_oops = NULL;
  666. + }
  667. +}
  668. +
  669. +// (DCEVM) Update instances of a class whose fields changed.
  670. +void MarkSweep::update_fields(oop q, oop new_location) {
  671. +
  672. + assert(q->klass()->new_version() != NULL, "class of old object must have new version");
  673. +
  674. + Klass* old_klass_oop = q->klass();
  675. + Klass* new_klass_oop = q->klass()->new_version();
  676. +
  677. + InstanceKlass *old_klass = InstanceKlass::cast(old_klass_oop);
  678. + InstanceKlass *new_klass = InstanceKlass::cast(new_klass_oop);
  679. +
  680. + int size = q->size_given_klass(old_klass);
  681. + int new_size = q->size_given_klass(new_klass);
  682. +
  683. + HeapWord* tmp = NULL;
  684. + oop tmp_obj = q;
  685. +
  686. + // Save object somewhere, there is an overlap in fields
  687. + if (new_klass_oop->is_copying_backwards()) {
  688. + if (((HeapWord *)q >= (HeapWord *)new_location && (HeapWord *)q < (HeapWord *)new_location + new_size) ||
  689. + ((HeapWord *)new_location >= (HeapWord *)q && (HeapWord *)new_location < (HeapWord *)q + size)) {
  690. + tmp = NEW_RESOURCE_ARRAY(HeapWord, size);
  691. + q = (oop) tmp;
  692. + Copy::aligned_disjoint_words((HeapWord*)q, (HeapWord*)tmp_obj, size);
  693. + }
  694. + }
  695. +
  696. + q->set_klass(new_klass_oop);
  697. + int *cur = new_klass_oop->update_information();
  698. + assert(cur != NULL, "just checking");
  699. + MarkSweep::update_fields(new_location, q, cur);
  700. +
  701. + if (tmp != NULL) {
  702. + FREE_RESOURCE_ARRAY(HeapWord, tmp, size);
  703. + }
  704. +}
  705. +
  706. +void MarkSweep::update_fields(oop new_location, oop tmp_obj, int *cur) {
  707. + assert(cur != NULL, "just checking");
  708. + char* to = (char*)(HeapWord*)new_location;
  709. + while (*cur != 0) {
  710. + int size = *cur;
  711. + if (size > 0) {
  712. + cur++;
  713. + int offset = *cur;
  714. + HeapWord* from = (HeapWord*)(((char *)(HeapWord*)tmp_obj) + offset);
  715. + if (size == HeapWordSize) {
  716. + *((HeapWord*)to) = *from;
  717. + } else if (size == HeapWordSize * 2) {
  718. + *((HeapWord*)to) = *from;
  719. + *(((HeapWord*)to) + 1) = *(from + 1);
  720. + } else {
  721. + Copy::conjoint_jbytes(from, to, size);
  722. + }
  723. + to += size;
  724. + cur++;
  725. + } else {
  726. + assert(size < 0, "");
  727. + int skip = -*cur;
  728. + Copy::fill_to_bytes(to, skip, 0);
  729. + to += skip;
  730. + cur++;
  731. + }
  732. + }
  733. +}
  734. diff -r 8a6717910608 src/share/vm/gc_implementation/shared/markSweep.hpp
  735. --- a/src/share/vm/gc_implementation/shared/markSweep.hpp Tue Mar 11 13:02:13 2014 -0700
  736. +++ b/src/share/vm/gc_implementation/shared/markSweep.hpp Wed Apr 30 11:27:18 2014 -0700
  737. @@ -107,8 +107,12 @@
  738. friend class AdjustPointerClosure;
  739. friend class KeepAliveClosure;
  740. friend class VM_MarkSweep;
  741. + friend class GenMarkSweep;
  742. friend void marksweep_init();
  743. +public:
  744. + static GrowableArray<HeapWord*>* _rescued_oops;
  745. +
  746. //
  747. // Vars
  748. //
  749. @@ -169,6 +173,9 @@
  750. static inline void push_objarray(oop obj, size_t index);
  751. + static void copy_rescued_objects_back();
  752. + static void update_fields(oop q, oop new_location);
  753. + static void update_fields(oop new_location, oop tmp_obj, int *cur);
  754. static void follow_stack(); // Empty marking stack.
  755. static void follow_klass(Klass* klass);
  756. diff -r 8a6717910608 src/share/vm/interpreter/linkResolver.cpp
  757. --- a/src/share/vm/interpreter/linkResolver.cpp Tue Mar 11 13:02:13 2014 -0700
  758. +++ b/src/share/vm/interpreter/linkResolver.cpp Wed Apr 30 11:27:18 2014 -0700
  759. @@ -215,8 +215,8 @@
  760. // Klass resolution
  761. void LinkResolver::check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS) {
  762. - if (!Reflection::verify_class_access(ref_klass(),
  763. - sel_klass(),
  764. + if (!Reflection::verify_class_access(ref_klass()->newest_version(),
  765. + sel_klass()->newest_version(),
  766. true)) {
  767. ResourceMark rm(THREAD);
  768. Exceptions::fthrow(
  769. @@ -444,7 +444,7 @@
  770. // We'll check for the method name first, as that's most likely
  771. // to be false (so we'll short-circuit out of these tests).
  772. if (sel_method->name() == vmSymbols::clone_name() &&
  773. - sel_klass() == SystemDictionary::Object_klass() &&
  774. + sel_klass()->newest_version() == SystemDictionary::Object_klass()->newest_version() &&
  775. resolved_klass->oop_is_array()) {
  776. // We need to change "protected" to "public".
  777. assert(flags.is_protected(), "clone not protected?");
  778. @@ -802,7 +802,7 @@
  779. }
  780. // Final fields can only be accessed from its own class.
  781. - if (is_put && fd.access_flags().is_final() && sel_klass() != current_klass()) {
  782. + if (is_put && fd.access_flags().is_final() && sel_klass() != current_klass() && sel_klass() != current_klass()->active_version()) {
  783. THROW(vmSymbols::java_lang_IllegalAccessError());
  784. }
  785. @@ -1199,6 +1199,16 @@
  786. // recv_klass might be an arrayKlassOop but all vtables start at
  787. // the same place. The cast is to avoid virtual call and assertion.
  788. InstanceKlass* inst = (InstanceKlass*)recv_klass();
  789. +
  790. + // (DCEVM) Check that the receiver is a subtype of the holder of the resolved method.
  791. + if (!inst->is_subtype_of(resolved_method->method_holder())) {
  792. + inst->print();
  793. + tty->print_cr("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  794. + resolved_method->method_holder()->print();
  795. + tty->print_cr("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  796. + resolved_method->print();
  797. + }
  798. + assert(inst->is_subtype_of(resolved_method->method_holder()), "receiver and resolved method holder are inconsistent");
  799. selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index));
  800. }
  801. }
  802. diff -r 8a6717910608 src/share/vm/memory/genMarkSweep.cpp
  803. --- a/src/share/vm/memory/genMarkSweep.cpp Tue Mar 11 13:02:13 2014 -0700
  804. +++ b/src/share/vm/memory/genMarkSweep.cpp Wed Apr 30 11:27:18 2014 -0700
  805. @@ -334,11 +334,16 @@
  806. // in the same order in phase2, phase3 and phase4. We don't quite do that
  807. // here (perm_gen first rather than last), so we tell the validate code
  808. // to use a higher index (saved from phase2) when verifying perm_gen.
  809. + assert(_rescued_oops == NULL, "must be empty before processing");
  810. GenCollectedHeap* gch = GenCollectedHeap::heap();
  811. GCTraceTime tm("phase 4", PrintGC && Verbose, true, _gc_timer);
  812. trace("4");
  813. + MarkSweep::copy_rescued_objects_back();
  814. +
  815. GenCompactClosure blk;
  816. gch->generation_iterate(&blk, true);
  817. +
  818. + MarkSweep::copy_rescued_objects_back();
  819. }
  820. diff -r 8a6717910608 src/share/vm/memory/space.cpp
  821. --- a/src/share/vm/memory/space.cpp Tue Mar 11 13:02:13 2014 -0700
  822. +++ b/src/share/vm/memory/space.cpp Wed Apr 30 11:27:18 2014 -0700
  823. @@ -379,9 +379,8 @@
  824. _compaction_top = bottom();
  825. }
  826. -HeapWord* CompactibleSpace::forward(oop q, size_t size,
  827. - CompactPoint* cp, HeapWord* compact_top) {
  828. - // q is alive
  829. +// (DCEVM) Calculates the compact_top that will be used for placing the next object with the giving size on the heap.
  830. +HeapWord* CompactibleSpace::forward_compact_top(size_t size, CompactPoint* cp, HeapWord* compact_top) {
  831. // First check if we should switch compaction space
  832. assert(this == cp->space, "'this' should be current compaction space.");
  833. size_t compaction_max_size = pointer_delta(end(), compact_top);
  834. @@ -401,8 +400,15 @@
  835. compaction_max_size = pointer_delta(cp->space->end(), compact_top);
  836. }
  837. + return compact_top;
  838. +}
  839. +
  840. +HeapWord* CompactibleSpace::forward(oop q, size_t size,
  841. + CompactPoint* cp, HeapWord* compact_top) {
  842. + compact_top = forward_compact_top(size, cp, compact_top);
  843. +
  844. // store the forwarding pointer into the mark word
  845. - if ((HeapWord*)q != compact_top) {
  846. + if ((HeapWord*)q != compact_top || (size_t)q->size() != size) {
  847. q->forward_to(oop(compact_top));
  848. assert(q->is_gc_marked(), "encoding the pointer should preserve the mark");
  849. } else {
  850. @@ -423,6 +429,58 @@
  851. return compact_top;
  852. }
  853. +// Compute the forward sizes and leave out objects whose position could
  854. +// possibly overlap other objects.
  855. +HeapWord* CompactibleSpace::forward_with_rescue(HeapWord* q, size_t size,
  856. + CompactPoint* cp, HeapWord* compact_top) {
  857. + size_t forward_size = size;
  858. +
  859. + // (DCEVM) There is a new version of the class of q => different size
  860. + if (oop(q)->klass()->new_version() != NULL && oop(q)->klass()->new_version()->update_information() != NULL) {
  861. +
  862. + size_t new_size = oop(q)->size_given_klass(oop(q)->klass()->new_version());
  863. + assert(size != new_size, "instances without changed size have to be updated prior to GC run");
  864. + forward_size = new_size;
  865. + }
  866. +
  867. + compact_top = forward_compact_top(forward_size, cp, compact_top);
  868. +
  869. + if (must_rescue(oop(q), oop(compact_top))) {
  870. + if (MarkSweep::_rescued_oops == NULL) {
  871. + MarkSweep::_rescued_oops = new GrowableArray<HeapWord*>(128);
  872. + }
  873. + MarkSweep::_rescued_oops->append(q);
  874. + return compact_top;
  875. + }
  876. +
  877. + return forward(oop(q), forward_size, cp, compact_top);
  878. +}
  879. +
  880. +// Compute the forwarding addresses for the objects that need to be rescued.
  881. +HeapWord* CompactibleSpace::forward_rescued(CompactPoint* cp, HeapWord* compact_top) {
  882. + // TODO: empty the _rescued_oops after ALL spaces are compacted!
  883. + if (MarkSweep::_rescued_oops != NULL) {
  884. + for (int i=0; i<MarkSweep::_rescued_oops->length(); i++) {
  885. + HeapWord* q = MarkSweep::_rescued_oops->at(i);
  886. +
  887. + /* size_t size = oop(q)->size(); changing this for cms for perm gen */
  888. + size_t size = block_size(q);
  889. +
  890. + // (DCEVM) There is a new version of the class of q => different size
  891. + if (oop(q)->klass()->new_version() != NULL) {
  892. + size_t new_size = oop(q)->size_given_klass(oop(q)->klass()->new_version());
  893. + assert(size != new_size, "instances without changed size have to be updated prior to GC run");
  894. + size = new_size;
  895. + }
  896. +
  897. + compact_top = cp->space->forward(oop(q), size, cp, compact_top);
  898. + assert(compact_top <= end(), "must not write over end of space!");
  899. + }
  900. + MarkSweep::_rescued_oops->clear();
  901. + MarkSweep::_rescued_oops = NULL;
  902. + }
  903. + return compact_top;
  904. +}
  905. bool CompactibleSpace::insert_deadspace(size_t& allowed_deadspace_words,
  906. HeapWord* q, size_t deadlength) {
  907. @@ -444,12 +502,17 @@
  908. #define adjust_obj_size(s) s
  909. void CompactibleSpace::prepare_for_compaction(CompactPoint* cp) {
  910. - SCAN_AND_FORWARD(cp, end, block_is_obj, block_size);
  911. + SCAN_AND_FORWARD(cp, end, block_is_obj, block_size, false);
  912. }
  913. // Faster object search.
  914. void ContiguousSpace::prepare_for_compaction(CompactPoint* cp) {
  915. - SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size);
  916. + if (!Universe::is_redefining_gc_run()) {
  917. + SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size, false);
  918. + } else {
  919. + // Redefinition run
  920. + SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size, true);
  921. + }
  922. }
  923. void Space::adjust_pointers() {
  924. @@ -487,6 +550,111 @@
  925. assert(q == t, "just checking");
  926. }
  927. +
  928. +#ifdef ASSERT
  929. +
  930. +int CompactibleSpace::space_index(oop obj) {
  931. + GenCollectedHeap* heap = GenCollectedHeap::heap();
  932. +
  933. + //if (heap->is_in_permanent(obj)) {
  934. + // return -1;
  935. + //}
  936. +
  937. + int index = 0;
  938. + for (int i = heap->n_gens() - 1; i >= 0; i--) {
  939. + Generation* gen = heap->get_gen(i);
  940. + CompactibleSpace* space = gen->first_compaction_space();
  941. + while (space != NULL) {
  942. + if (space->is_in_reserved(obj)) {
  943. + return index;
  944. + }
  945. + space = space->next_compaction_space();
  946. + index++;
  947. + }
  948. + }
  949. +
  950. + tty->print_cr("could not compute space_index for %08xh", (HeapWord*)obj);
  951. + index = 0;
  952. + for (int i = heap->n_gens() - 1; i >= 0; i--) {
  953. + Generation* gen = heap->get_gen(i);
  954. + tty->print_cr(" generation %s: %08xh - %08xh", gen->name(), gen->reserved().start(), gen->reserved().end());
  955. +
  956. + CompactibleSpace* space = gen->first_compaction_space();
  957. + while (space != NULL) {
  958. + tty->print_cr(" %2d space %08xh - %08xh", index, space->bottom(), space->end());
  959. + space = space->next_compaction_space();
  960. + index++;
  961. + }
  962. + }
  963. +
  964. + ShouldNotReachHere();
  965. + return 0;
  966. +}
  967. +#endif
  968. +
  969. +bool CompactibleSpace::must_rescue(oop old_obj, oop new_obj) {
  970. + // Only redefined objects can have the need to be rescued.
  971. + if (oop(old_obj)->klass()->new_version() == NULL) return false;
  972. +
  973. + //if (old_obj->is_perm()) {
  974. + // // This object is in perm gen: Always rescue to satisfy invariant obj->klass() <= obj.
  975. + // return true;
  976. + //}
  977. +
  978. + int new_size = old_obj->size_given_klass(oop(old_obj)->klass()->new_version());
  979. + int original_size = old_obj->size();
  980. +
  981. + Generation* tenured_gen = GenCollectedHeap::heap()->get_gen(1);
  982. + bool old_in_tenured = tenured_gen->is_in_reserved(old_obj);
  983. + bool new_in_tenured = tenured_gen->is_in_reserved(new_obj);
  984. + if (old_in_tenured == new_in_tenured) {
  985. + // Rescue if object may overlap with a higher memory address.
  986. + bool overlap = ((HeapWord*)old_obj + original_size < (HeapWord*)new_obj + new_size);
  987. + if (old_in_tenured) {
  988. + // Old and new address are in same space, so just compare the address.
  989. + // Must rescue if object moves towards the top of the space.
  990. + assert(space_index(old_obj) == space_index(new_obj), "old_obj and new_obj must be in same space");
  991. + } else {
  992. + // In the new generation, eden is located before the from space, so a
  993. + // simple pointer comparison is sufficient.
  994. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(old_obj), "old_obj must be in DefNewGeneration");
  995. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(new_obj), "new_obj must be in DefNewGeneration");
  996. + assert(overlap == (space_index(old_obj) < space_index(new_obj)), "slow and fast computation must yield same result");
  997. + }
  998. + return overlap;
  999. +
  1000. + } else {
  1001. + assert(space_index(old_obj) != space_index(new_obj), "old_obj and new_obj must be in different spaces");
  1002. + if (tenured_gen->is_in_reserved(new_obj)) {
  1003. + // Must never rescue when moving from the new into the old generation.
  1004. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(old_obj), "old_obj must be in DefNewGeneration");
  1005. + assert(space_index(old_obj) > space_index(new_obj), "must be");
  1006. + return false;
  1007. +
  1008. + } else /* if (tenured_gen->is_in_reserved(old_obj)) */ {
  1009. + // Must always rescue when moving from the old into the new generation.
  1010. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(new_obj), "new_obj must be in DefNewGeneration");
  1011. + assert(space_index(old_obj) < space_index(new_obj), "must be");
  1012. + return true;
  1013. + }
  1014. + }
  1015. +}
  1016. +
  1017. +HeapWord* CompactibleSpace::rescue(HeapWord* old_obj) {
  1018. + assert(must_rescue(oop(old_obj), oop(old_obj)->forwardee()), "do not call otherwise");
  1019. +
  1020. + int size = oop(old_obj)->size();
  1021. + HeapWord* rescued_obj = NEW_RESOURCE_ARRAY(HeapWord, size);
  1022. + Copy::aligned_disjoint_words(old_obj, rescued_obj, size);
  1023. +
  1024. + if (MarkSweep::_rescued_oops == NULL) {
  1025. + MarkSweep::_rescued_oops = new GrowableArray<HeapWord*>(128);
  1026. + }
  1027. +
  1028. + MarkSweep::_rescued_oops->append(rescued_obj);
  1029. + return rescued_obj;
  1030. +}
  1031. +
  1032. void CompactibleSpace::adjust_pointers() {
  1033. // Check first is there is any work to do.
  1034. if (used() == 0) {
  1035. @@ -497,7 +665,12 @@
  1036. }
  1037. void CompactibleSpace::compact() {
  1038. - SCAN_AND_COMPACT(obj_size);
  1039. + if(!Universe::is_redefining_gc_run()) {
  1040. + SCAN_AND_COMPACT(obj_size, false);
  1041. + } else {
  1042. + // Redefinition run
  1043. + SCAN_AND_COMPACT(obj_size, true)
  1044. + }
  1045. }
  1046. void Space::print_short() const { print_short_on(tty); }
  1047. diff -r 8a6717910608 src/share/vm/memory/space.hpp
  1048. --- a/src/share/vm/memory/space.hpp Tue Mar 11 13:02:13 2014 -0700
  1049. +++ b/src/share/vm/memory/space.hpp Wed Apr 30 11:27:18 2014 -0700
  1050. @@ -450,6 +450,9 @@
  1051. // indicates when the next such action should be taken.
  1052. virtual void prepare_for_compaction(CompactPoint* cp);
  1053. // MarkSweep support phase3
  1054. + DEBUG_ONLY(int space_index(oop obj));
  1055. + bool must_rescue(oop old_obj, oop new_obj);
  1056. + HeapWord* rescue(HeapWord* old_obj);
  1057. virtual void adjust_pointers();
  1058. // MarkSweep support phase4
  1059. virtual void compact();
  1060. @@ -479,6 +482,15 @@
  1061. // accordingly".
  1062. virtual HeapWord* forward(oop q, size_t size, CompactPoint* cp,
  1063. HeapWord* compact_top);
  1064. + // (DCEVM) same as forwad, but can rescue objects. Invoked only during
  1065. + // redefinition runs
  1066. + HeapWord* forward_with_rescue(HeapWord* q, size_t size, CompactPoint* cp,
  1067. + HeapWord* compact_top);
  1068. +
  1069. + HeapWord* forward_rescued(CompactPoint* cp, HeapWord* compact_top);
  1070. +
  1071. + // (tw) Compute new compact top without actually forwarding the object.
  1072. + virtual HeapWord* forward_compact_top(size_t size, CompactPoint* cp, HeapWord* compact_top);
  1073. // Return a size with adjusments as required of the space.
  1074. virtual size_t adjust_object_size_v(size_t size) const { return size; }
  1075. @@ -509,7 +521,7 @@
  1076. size_t word_len);
  1077. };
  1078. -#define SCAN_AND_FORWARD(cp,scan_limit,block_is_obj,block_size) { \
  1079. +#define SCAN_AND_FORWARD(cp,scan_limit,block_is_obj,block_size,redefinition_run) { \
  1080. /* Compute the new addresses for the live objects and store it in the mark \
  1081. * Used by universe::mark_sweep_phase2() \
  1082. */ \
  1083. @@ -567,7 +579,17 @@
  1084. /* prefetch beyond q */ \
  1085. Prefetch::write(q, interval); \
  1086. size_t size = block_size(q); \
  1087. + if (redefinition_run) { \
  1088. + compact_top = cp->space->forward_with_rescue(q, size, \
  1089. + cp, compact_top); \
  1090. + if (q < first_dead && oop(q)->is_gc_marked()) { \
  1091. + /* Was moved (otherwise, forward would reset mark), \
  1092. + set first_dead to here */ \
  1093. + first_dead = q; \
  1094. + } \
  1095. + } else { \
  1096. compact_top = cp->space->forward(oop(q), size, cp, compact_top); \
  1097. + } \
  1098. q += size; \
  1099. end_of_live = q; \
  1100. } else { \
  1101. @@ -616,6 +638,8 @@
  1102. } \
  1103. } \
  1104. \
  1105. + if (redefinition_run) { compact_top = forward_rescued(cp, compact_top); } \
  1106. + \
  1107. assert(q == t, "just checking"); \
  1108. if (liveRange != NULL) { \
  1109. liveRange->set_end(q); \
  1110. @@ -662,13 +686,8 @@
  1111. q += size; \
  1112. } \
  1113. \
  1114. - if (_first_dead == t) { \
  1115. - q = t; \
  1116. - } else { \
  1117. - /* $$$ This is funky. Using this to read the previously written \
  1118. - * LiveRange. See also use below. */ \
  1119. - q = (HeapWord*)oop(_first_dead)->mark()->decode_pointer(); \
  1120. - } \
  1121. + /* (DCEVM) first_dead can be live object if we move/rescue resized objects */ \
  1122. + q = _first_dead; \
  1123. } \
  1124. \
  1125. const intx interval = PrefetchScanIntervalInBytes; \
  1126. @@ -696,7 +715,7 @@
  1127. assert(q == t, "just checking"); \
  1128. }
  1129. -#define SCAN_AND_COMPACT(obj_size) { \
  1130. +#define SCAN_AND_COMPACT(obj_size, redefinition_run) { \
  1131. /* Copy all live objects to their new location \
  1132. * Used by MarkSweep::mark_sweep_phase4() */ \
  1133. \
  1134. @@ -721,13 +740,9 @@
  1135. } \
  1136. ) /* debug_only */ \
  1137. \
  1138. - if (_first_dead == t) { \
  1139. - q = t; \
  1140. - } else { \
  1141. - /* $$$ Funky */ \
  1142. - q = (HeapWord*) oop(_first_dead)->mark()->decode_pointer(); \
  1143. + /* (DCEVM) first_dead can be live object if we move/rescue resized objects */ \
  1144. + q = _first_dead; \
  1145. } \
  1146. - } \
  1147. \
  1148. const intx scan_interval = PrefetchScanIntervalInBytes; \
  1149. const intx copy_interval = PrefetchCopyIntervalInBytes; \
  1150. @@ -745,11 +760,34 @@
  1151. size_t size = obj_size(q); \
  1152. HeapWord* compaction_top = (HeapWord*)oop(q)->forwardee(); \
  1153. \
  1154. + if (redefinition_run && must_rescue(oop(q), oop(q)->forwardee())) { \
  1155. + rescue(q); \
  1156. + debug_only(Copy::fill_to_words(q, size, 0)); \
  1157. + q += size; \
  1158. + continue; \
  1159. + } \
  1160. + \
  1161. /* prefetch beyond compaction_top */ \
  1162. Prefetch::write(compaction_top, copy_interval); \
  1163. \
  1164. /* copy object and reinit its mark */ \
  1165. - assert(q != compaction_top, "everything in this pass should be moving"); \
  1166. + assert(q != compaction_top || oop(q)->klass()->new_version() != NULL, \
  1167. + "everything in this pass should be moving"); \
  1168. + if (redefinition_run && oop(q)->klass()->new_version() != NULL) { \
  1169. + Klass* new_version = oop(q)->klass()->new_version(); \
  1170. + if (new_version->update_information() == NULL) { \
  1171. + Copy::aligned_conjoint_words(q, compaction_top, size); \
  1172. + oop(compaction_top)->set_klass(new_version); \
  1173. + } else { \
  1174. + MarkSweep::update_fields(oop(q), oop(compaction_top)); \
  1175. + } \
  1176. + oop(compaction_top)->init_mark(); \
  1177. + assert(oop(compaction_top)->klass() != NULL, "should have a class"); \
  1178. + \
  1179. + debug_only(prev_q = q); \
  1180. + q += size; \
  1181. + continue; \
  1182. + } \
  1183. Copy::aligned_conjoint_words(q, compaction_top, size); \
  1184. oop(compaction_top)->init_mark(); \
  1185. assert(oop(compaction_top)->klass() != NULL, "should have a class"); \
  1186. diff -r 8a6717910608 src/share/vm/memory/universe.cpp
  1187. --- a/src/share/vm/memory/universe.cpp Tue Mar 11 13:02:13 2014 -0700
  1188. +++ b/src/share/vm/memory/universe.cpp Wed Apr 30 11:27:18 2014 -0700
  1189. @@ -78,6 +78,8 @@
  1190. #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
  1191. #endif // INCLUDE_ALL_GCS
  1192. +bool Universe::_is_redefining_gc_run = false;
  1193. +
  1194. // Known objects
  1195. Klass* Universe::_boolArrayKlassObj = NULL;
  1196. Klass* Universe::_byteArrayKlassObj = NULL;
  1197. @@ -157,6 +159,42 @@
  1198. f(doubleArrayKlassObj());
  1199. }
  1200. +// (DCEVM) This method should iterate all pointers that are not within heap objects.
  1201. +void Universe::root_oops_do(OopClosure *oopClosure) {
  1202. +
  1203. + class AlwaysTrueClosure: public BoolObjectClosure {
  1204. + public:
  1205. + void do_object(oop p) { ShouldNotReachHere(); }
  1206. + bool do_object_b(oop p) { return true; }
  1207. + };
  1208. + AlwaysTrueClosure always_true;
  1209. +
  1210. + Universe::oops_do(oopClosure);
  1211. +// ReferenceProcessor::oops_do(oopClosure); (tw) check why no longer there
  1212. + JNIHandles::oops_do(oopClosure); // Global (strong) JNI handles
  1213. + Threads::oops_do(oopClosure, NULL, NULL);
  1214. + ObjectSynchronizer::oops_do(oopClosure);
  1215. + FlatProfiler::oops_do(oopClosure);
  1216. + JvmtiExport::oops_do(oopClosure);
  1217. +
  1218. + // Now adjust pointers in remaining weak roots. (All of which should
  1219. + // have been cleared if they pointed to non-surviving objects.)
  1220. + // Global (weak) JNI handles
  1221. + JNIHandles::weak_oops_do(&always_true, oopClosure);
  1222. +
  1223. + CodeCache::oops_do(oopClosure);
  1224. + StringTable::oops_do(oopClosure);
  1225. +
  1226. + // (DCEVM) TODO: Check if this is correct?
  1227. + //CodeCache::scavenge_root_nmethods_oops_do(oopClosure);
  1228. + //Management::oops_do(oopClosure);
  1229. + //ref_processor()->weak_oops_do(&oopClosure);
  1230. + //PSScavenge::reference_processor()->weak_oops_do(&oopClosure);
  1231. +
  1232. + // SO_AllClasses
  1233. + SystemDictionary::oops_do(oopClosure);
  1234. +}
  1235. +
  1236. void Universe::oops_do(OopClosure* f, bool do_all) {
  1237. f->do_oop((oop*) &_int_mirror);
  1238. diff -r 8a6717910608 src/share/vm/memory/universe.hpp
  1239. --- a/src/share/vm/memory/universe.hpp Tue Mar 11 13:02:13 2014 -0700
  1240. +++ b/src/share/vm/memory/universe.hpp Wed Apr 30 11:27:18 2014 -0700
  1241. @@ -248,7 +248,13 @@
  1242. static void compute_verify_oop_data();
  1243. + static bool _is_redefining_gc_run;
  1244. +
  1245. public:
  1246. +
  1247. + static bool is_redefining_gc_run() { return _is_redefining_gc_run; }
  1248. + static void set_redefining_gc_run(bool b) { _is_redefining_gc_run = b; }
  1249. +
  1250. // Known classes in the VM
  1251. static Klass* boolArrayKlassObj() { return _boolArrayKlassObj; }
  1252. static Klass* byteArrayKlassObj() { return _byteArrayKlassObj; }
  1253. @@ -401,6 +407,7 @@
  1254. static void run_finalizers_on_exit();
  1255. // Iteration
  1256. + static void root_oops_do(OopClosure *f);
  1257. // Apply "f" to the addresses of all the direct heap pointers maintained
  1258. // as static fields of "Universe".
  1259. diff -r 8a6717910608 src/share/vm/oops/cpCache.cpp
  1260. --- a/src/share/vm/oops/cpCache.cpp Tue Mar 11 13:02:13 2014 -0700
  1261. +++ b/src/share/vm/oops/cpCache.cpp Wed Apr 30 11:27:18 2014 -0700
  1262. @@ -336,7 +336,8 @@
  1263. if (has_appendix) {
  1264. const int appendix_index = f2_as_index() + _indy_resolved_references_appendix_offset;
  1265. assert(appendix_index >= 0 && appendix_index < resolved_references->length(), "oob");
  1266. - assert(resolved_references->obj_at(appendix_index) == NULL, "init just once");
  1267. + // FIXME (DCEVM) relaxing for now...
  1268. + //assert(resolved_references->obj_at(appendix_index) == NULL, "init just once");
  1269. resolved_references->obj_at_put(appendix_index, appendix());
  1270. }
  1271. @@ -344,7 +345,8 @@
  1272. if (has_method_type) {
  1273. const int method_type_index = f2_as_index() + _indy_resolved_references_method_type_offset;
  1274. assert(method_type_index >= 0 && method_type_index < resolved_references->length(), "oob");
  1275. - assert(resolved_references->obj_at(method_type_index) == NULL, "init just once");
  1276. + // FIXME (DCEVM) relaxing for now...
  1277. + //assert(resolved_references->obj_at(method_type_index) == NULL, "init just once");
  1278. resolved_references->obj_at_put(method_type_index, method_type());
  1279. }
  1280. @@ -532,6 +534,26 @@
  1281. // the method is in the interesting class so the entry is interesting
  1282. return true;
  1283. }
  1284. +
  1285. +// Enhanced RedefineClasses() API support (DCEVM):
  1286. +// Clear cached entry, let it be re-resolved
  1287. +void ConstantPoolCacheEntry::clear_entry() {
  1288. + // Clear entry during class redefinition. Note that we still keep flags.
  1289. + if (has_appendix()) {
  1290. + // (DCEVM): Now this gets really ugly. If this entry is used by invokehandle, we cannot
  1291. + // clear it just like that (data is used by _invokehandle bytecode which wouldn't re-resolve anything).
  1292. + // FIXME: (DCEVM) need to figure out if we need to rewrite it somehow or it should be fine...
  1293. + return;
  1294. + }
  1295. + _indices = constant_pool_index();
  1296. + _f1 = NULL;
  1297. + _f2 = 0;
  1298. +
  1299. + // FIXME: (DCEVM) we want to clear flags, but parameter size is actually used
  1300. + // after we return from the method, before entry is re-initialized. So let's
  1301. + // keep parameter size the same.
  1302. + _flags &= 0x0000000f;
  1303. +}
  1304. #endif // INCLUDE_JVMTI
  1305. void ConstantPoolCacheEntry::print(outputStream* st, int index) const {
  1306. @@ -660,6 +682,14 @@
  1307. }
  1308. }
  1309. }
  1310. +
  1311. +// Enhanced RedefineClasses() API support (DCEVM):
  1312. +// Clear all entries
  1313. +void ConstantPoolCache::clear_entries() {
  1314. + for (int i = 0; i < length(); i++) {
  1315. + entry_at(i)->clear_entry();
  1316. + }
  1317. +}
  1318. #endif // INCLUDE_JVMTI
  1319. diff -r 8a6717910608 src/share/vm/oops/cpCache.hpp
  1320. --- a/src/share/vm/oops/cpCache.hpp Tue Mar 11 13:02:13 2014 -0700
  1321. +++ b/src/share/vm/oops/cpCache.hpp Wed Apr 30 11:27:18 2014 -0700
  1322. @@ -373,6 +373,10 @@
  1323. bool * trace_name_printed);
  1324. bool check_no_old_or_obsolete_entries();
  1325. bool is_interesting_method_entry(Klass* k);
  1326. +
  1327. + // Enhanced RedefineClasses() API support (DCEVM):
  1328. + // Clear cached entry, let it be re-resolved
  1329. + void clear_entry();
  1330. #endif // INCLUDE_JVMTI
  1331. // Debugging & Printing
  1332. @@ -472,6 +476,10 @@
  1333. int methods_length, bool * trace_name_printed);
  1334. bool check_no_old_or_obsolete_entries();
  1335. void dump_cache();
  1336. +
  1337. + // Enhanced RedefineClasses() API support (DCEVM):
  1338. + // Clear all entries
  1339. + void clear_entries();
  1340. #endif // INCLUDE_JVMTI
  1341. // Deallocate - no fields to deallocate
  1342. diff -r 8a6717910608 src/share/vm/oops/instanceKlass.cpp
  1343. --- a/src/share/vm/oops/instanceKlass.cpp Tue Mar 11 13:02:13 2014 -0700
  1344. +++ b/src/share/vm/oops/instanceKlass.cpp Wed Apr 30 11:27:18 2014 -0700
  1345. @@ -718,7 +718,8 @@
  1346. }
  1347. #endif
  1348. this_oop->set_init_state(linked);
  1349. - if (JvmtiExport::should_post_class_prepare()) {
  1350. + // (DCEVM) Must check for old version in order to prevent infinite loops.
  1351. + if (JvmtiExport::should_post_class_prepare() && this_oop->old_version() == NULL /* JVMTI deadlock otherwise */) {
  1352. Thread *thread = THREAD;
  1353. assert(thread->is_Java_thread(), "thread->is_Java_thread()");
  1354. JvmtiExport::post_class_prepare((JavaThread *) thread, this_oop());
  1355. @@ -795,7 +796,9 @@
  1356. // If we were to use wait() instead of waitInterruptibly() then
  1357. // we might end up throwing IE from link/symbol resolution sites
  1358. // that aren't expected to throw. This would wreak havoc. See 6320309.
  1359. - while(this_oop->is_being_initialized() && !this_oop->is_reentrant_initialization(self)) {
  1360. + // (DCEVM) Wait also for the old class version to be fully initialized.
  1361. + while((this_oop->is_being_initialized() && !this_oop->is_reentrant_initialization(self))
  1362. + || (this_oop->old_version() != NULL && InstanceKlass::cast(this_oop->old_version())->is_being_initialized())) {
  1363. wait = true;
  1364. ol.waitUninterruptibly(CHECK);
  1365. }
  1366. @@ -1051,6 +1054,18 @@
  1367. return false;
  1368. }
  1369. +bool InstanceKlass::implements_interface_any_version(Klass* k) const {
  1370. + k = k->newest_version();
  1371. + if (this->newest_version() == k) return true;
  1372. + assert(k->is_interface(), "should be an interface class");
  1373. + for (int i = 0; i < transitive_interfaces()->length(); i++) {
  1374. + if (transitive_interfaces()->at(i)->newest_version() == k) {
  1375. + return true;
  1376. + }
  1377. + }
  1378. + return false;
  1379. +}
  1380. +
  1381. bool InstanceKlass::is_same_or_direct_interface(Klass *k) const {
  1382. // Verify direct super interface
  1383. if (this == k) return true;
  1384. @@ -1314,6 +1329,18 @@
  1385. }
  1386. }
  1387. +void InstanceKlass::store_update_information(GrowableArray<int> &values) {
  1388. + int *arr = NEW_C_HEAP_ARRAY(int, values.length(), mtClass);
  1389. + for (int i=0; i<values.length(); i++) {
  1390. + arr[i] = values.at(i);
  1391. + }
  1392. + set_update_information(arr);
  1393. +}
  1394. +
  1395. +void InstanceKlass::clear_update_information() {
  1396. + FREE_C_HEAP_ARRAY(int, update_information(), mtClass);
  1397. + set_update_information(NULL);
  1398. +}
  1399. void InstanceKlass::do_local_static_fields(FieldClosure* cl) {
  1400. for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
  1401. @@ -1797,6 +1824,18 @@
  1402. return id;
  1403. }
  1404. +bool InstanceKlass::update_jmethod_id(Method* method, jmethodID newMethodID) {
  1405. + size_t idnum = (size_t)method->method_idnum();
  1406. + jmethodID* jmeths = methods_jmethod_ids_acquire();
  1407. + size_t length; // length assigned as debugging crumb
  1408. + jmethodID id = NULL;
  1409. + if (jmeths != NULL && // If there is a cache
  1410. + (length = (size_t)jmeths[0]) > idnum) { // and if it is long enough,
  1411. + jmeths[idnum+1] = newMethodID; // Set method id (may be NULL)
  1412. + return true;
  1413. + }
  1414. + return false;
  1415. +}
  1416. //
  1417. // Walk the list of dependent nmethods searching for nmethods which
  1418. @@ -1875,6 +1914,13 @@
  1419. last = b;
  1420. b = b->next();
  1421. }
  1422. +
  1423. + // (DCEVM) Hack as dependencies get wrong version of Klass*
  1424. + if (this->old_version() != NULL) {
  1425. + InstanceKlass::cast(this->old_version())->remove_dependent_nmethod(nm);
  1426. + return;
  1427. + }
  1428. +
  1429. #ifdef ASSERT
  1430. tty->print_cr("### %s can't find dependent nmethod:", this->external_name());
  1431. nm->print();
  1432. @@ -2884,6 +2930,24 @@
  1433. assert(is_klass(), "must be klass");
  1434. Klass::print_on(st);
  1435. + // (DCEVM) Output revision number and revision numbers of older / newer and oldest / newest version of this class.
  1436. + if (AllowEnhancedClassRedefinition) {
  1437. + st->print(BULLET"revision: %d", revision_number());
  1438. + if (new_version() != NULL) {
  1439. + st->print(" (newer=%d)", new_version()->revision_number());
  1440. + }
  1441. + if (newest_version() != new_version() && newest_version() != this) {
  1442. + st->print(" (newest=%d)", newest_version()->revision_number());
  1443. + }
  1444. + if (old_version() != NULL) {
  1445. + st->print(" (old=%d)", old_version()->revision_number());
  1446. + }
  1447. + if (oldest_version() != old_version() && oldest_version() != this) {
  1448. + st->print(" (oldest=%d)", oldest_version()->revision_number());
  1449. + }
  1450. + st->cr();
  1451. + }
  1452. +
  1453. st->print(BULLET"instance size: %d", size_helper()); st->cr();
  1454. st->print(BULLET"klass size: %d", size()); st->cr();
  1455. st->print(BULLET"access: "); access_flags().print_on(st); st->cr();
  1456. @@ -3219,7 +3283,7 @@
  1457. }
  1458. guarantee(sib->is_klass(), "should be klass");
  1459. - guarantee(sib->super() == super, "siblings should have same superklass");
  1460. + guarantee(sib->super() == super || super->newest_version() == SystemDictionary::Object_klass(), "siblings should have same superklass");
  1461. }
  1462. // Verify implementor fields
  1463. @@ -3384,6 +3448,7 @@
  1464. // Purge previous versions
  1465. static void purge_previous_versions_internal(InstanceKlass* ik, int emcp_method_count) {
  1466. + // FIXME: (DCEVM) Should we purge something?
  1467. if (ik->previous_versions() != NULL) {
  1468. // This klass has previous versions so see what we can cleanup
  1469. // while it is safe to do so.
  1470. @@ -3621,7 +3686,7 @@
  1471. // Determine if InstanceKlass has a previous version.
  1472. bool InstanceKlass::has_previous_version() const {
  1473. - return (_previous_versions != NULL && _previous_versions->length() > 0);
  1474. + return _old_version != NULL || (_previous_versions != NULL && _previous_versions->length() > 0);
  1475. } // end has_previous_version()
  1476. diff -r 8a6717910608 src/share/vm/oops/instanceKlass.hpp
  1477. --- a/src/share/vm/oops/instanceKlass.hpp Tue Mar 11 13:02:13 2014 -0700
  1478. +++ b/src/share/vm/oops/instanceKlass.hpp Wed Apr 30 11:27:18 2014 -0700
  1479. @@ -139,6 +139,7 @@
  1480. friend class VMStructs;
  1481. friend class ClassFileParser;
  1482. friend class CompileReplay;
  1483. + friend class VM_EnhancedRedefineClasses;
  1484. protected:
  1485. // Constructor
  1486. @@ -637,7 +638,7 @@
  1487. // If the _previous_versions array is non-NULL, then this klass
  1488. // has been redefined at least once even if we aren't currently
  1489. // tracking a previous version.
  1490. - bool has_been_redefined() const { return _previous_versions != NULL; }
  1491. + bool has_been_redefined() const { return _old_version != NULL || _previous_versions != NULL; }
  1492. bool has_previous_version() const;
  1493. void init_previous_versions() {
  1494. _previous_versions = NULL;
  1495. @@ -711,6 +712,7 @@
  1496. static void get_jmethod_id_length_value(jmethodID* cache, size_t idnum,
  1497. size_t *length_p, jmethodID* id_p);
  1498. jmethodID jmethod_id_or_null(Method* method);
  1499. + bool update_jmethod_id(Method* method, jmethodID newMethodID);
  1500. // annotations support
  1501. Annotations* annotations() const { return _annotations; }
  1502. @@ -780,6 +782,7 @@
  1503. // subclass/subinterface checks
  1504. bool implements_interface(Klass* k) const;
  1505. bool is_same_or_direct_interface(Klass* k) const;
  1506. + bool implements_interface_any_version(Klass* k) const;
  1507. // Access to the implementor of an interface.
  1508. Klass* implementor() const
  1509. @@ -831,6 +834,10 @@
  1510. void do_nonstatic_fields(FieldClosure* cl); // including inherited fields
  1511. void do_local_static_fields(void f(fieldDescriptor*, TRAPS), TRAPS);
  1512. + // (DCEVM) instance update information to be used in GC run
  1513. + void store_update_information(GrowableArray<int> &values);
  1514. + void clear_update_information();
  1515. +
  1516. void methods_do(void f(Method* method));
  1517. void array_klasses_do(void f(Klass* k));
  1518. void array_klasses_do(void f(Klass* k, TRAPS), TRAPS);
  1519. diff -r 8a6717910608 src/share/vm/oops/klass.cpp
  1520. --- a/src/share/vm/oops/klass.cpp Tue Mar 11 13:02:13 2014 -0700
  1521. +++ b/src/share/vm/oops/klass.cpp Wed Apr 30 11:27:18 2014 -0700
  1522. @@ -170,6 +170,13 @@
  1523. set_next_link(NULL);
  1524. TRACE_INIT_ID(this);
  1525. + set_redefinition_flags(Klass::NoRedefinition);
  1526. + set_redefining(false);
  1527. + set_new_version(NULL);
  1528. + set_old_version(NULL);
  1529. + set_redefinition_index(-1);
  1530. + set_revision_number(-1);
  1531. +
  1532. set_prototype_header(markOopDesc::prototype());
  1533. set_biased_lock_revocation_count(0);
  1534. set_last_biased_lock_bulk_revocation_time(0);
  1535. @@ -375,6 +382,24 @@
  1536. debug_only(verify();)
  1537. }
  1538. +// (DCEVM)
  1539. +void Klass::remove_from_sibling_list() {
  1540. + debug_only(verify();)
  1541. + // remove ourselves to superklass' subklass list
  1542. + InstanceKlass* super = superklass();
  1543. + assert(super != NULL, "should have super");
  1544. + if (super->subklass() == this) {
  1545. + // first subklass
  1546. + super->set_subklass(next_sibling());
  1547. + } else {
  1548. + Klass* sib = super->subklass();
  1549. + while (sib->next_sibling() != this) {
  1550. + sib = sib->next_sibling();
  1551. + };
  1552. + sib->set_next_sibling(next_sibling());
  1553. + }
  1554. +}
  1555. +
  1556. bool Klass::is_loader_alive(BoolObjectClosure* is_alive) {
  1557. assert(ClassLoaderDataGraph::contains((address)this), "is in the metaspace");
  1558. diff -r 8a6717910608 src/share/vm/oops/klass.hpp
  1559. --- a/src/share/vm/oops/klass.hpp Tue Mar 11 13:02:13 2014 -0700
  1560. +++ b/src/share/vm/oops/klass.hpp Wed Apr 30 11:27:18 2014 -0700
  1561. @@ -149,6 +149,10 @@
  1562. oop _java_mirror;
  1563. // Superclass
  1564. Klass* _super;
  1565. + // Old class
  1566. + Klass* _old_version;
  1567. + // New class
  1568. + Klass* _new_version;
  1569. // First subclass (NULL if none); _subklass->next_sibling() is next one
  1570. Klass* _subklass;
  1571. // Sibling link (or NULL); links all subklasses of a klass
  1572. @@ -164,6 +168,16 @@
  1573. jint _modifier_flags; // Processed access flags, for use by Class.getModifiers.
  1574. AccessFlags _access_flags; // Access flags. The class/interface distinction is stored here.
  1575. + // (DCEVM) fields for enhanced class redefinition
  1576. + jint _revision_number; // The revision number for redefined classes
  1577. + jint _redefinition_index; // Index of this class when performing the redefinition
  1578. + bool _subtype_changed;
  1579. + int _redefinition_flags; // Level of class redefinition
  1580. + bool _is_copying_backwards; // Does the class need to copy fields backwards? => possibly overwrite itself?
  1581. + bool _original_field_offsets_changed; // Did the original field offsets of this class change during class redefinition?
  1582. + int * _update_information; // Update information
  1583. + bool _is_redefining;
  1584. +
  1585. // Biased locking implementation and statistics
  1586. // (the 64-bit chunk goes first, to avoid some fragmentation)
  1587. jlong _last_biased_lock_bulk_revocation_time;
  1588. @@ -208,6 +222,53 @@
  1589. Array<Klass*>* secondary_supers() const { return _secondary_supers; }
  1590. void set_secondary_supers(Array<Klass*>* k) { _secondary_supers = k; }
  1591. + // BEGIN class redefinition utilities
  1592. +
  1593. + // double links between new and old version of a class
  1594. + Klass* old_version() const { return _old_version; }
  1595. + void set_old_version(Klass* klass) { assert(_old_version == NULL || klass == NULL, "Can only be set once!"); _old_version = klass; }
  1596. + Klass* new_version() const { return _new_version; }
  1597. + void set_new_version(Klass* klass) { assert(_new_version == NULL || klass == NULL, "Can only be set once!"); _new_version = klass; }
  1598. +
  1599. + // A subtype of this class is no longer a subtype
  1600. + bool has_subtype_changed() const { return _subtype_changed; }
  1601. + void set_subtype_changed(bool b) { assert(is_newest_version() || new_version()->is_newest_version(), "must be newest or second newest version");
  1602. + _subtype_changed = b; }
  1603. + // state of being redefined
  1604. + int redefinition_index() const { return _redefinition_index; }
  1605. + void set_redefinition_index(int index) { _redefinition_index = index; }
  1606. + void set_redefining(bool b) { _is_redefining = b; }
  1607. + bool is_redefining() const { return _is_redefining; }
  1608. + int redefinition_flags() const { return _redefinition_flags; }
  1609. + bool check_redefinition_flag(int flags) const { return (_redefinition_flags & flags) != 0; }
  1610. + void set_redefinition_flags(int flags) { _redefinition_flags = flags; }
  1611. + void set_redefinition_flag(int flag) { _redefinition_flags |= flag; }
  1612. + void clear_redefinition_flag(int flag) { _redefinition_flags &= ~flag; }
  1613. + bool is_copying_backwards() const { return _is_copying_backwards; }
  1614. + void set_copying_backwards(bool b) { _is_copying_backwards = b; }
  1615. +
  1616. + // update information
  1617. + int *update_information() const { return _update_information; }
  1618. + void set_update_information(int *info) { _update_information = info; }
  1619. +
  1620. + // Revision number for redefined classes, -1 for originally loaded classes
  1621. + bool was_redefined() const { return _revision_number != -1; }
  1622. + jint revision_number() const { return _revision_number; }
  1623. + void set_revision_number(jint number) { _revision_number = number; }
  1624. +
  1625. + const Klass* oldest_version() const { return _old_version == NULL ? this : _old_version->oldest_version(); }
  1626. + Klass* oldest_version() { return _old_version == NULL ? this : _old_version->oldest_version(); }
  1627. +
  1628. + const Klass* newest_version() const { return _new_version == NULL ? this : _new_version->newest_version(); }
  1629. + Klass* newest_version() { return _new_version == NULL ? this : _new_version->newest_version(); }
  1630. +
  1631. + const Klass* active_version() const { return _new_version == NULL || _new_version->is_redefining() ? this : _new_version->active_version(); }
  1632. + Klass* active_version() { return _new_version == NULL || _new_version->is_redefining() ? this : _new_version->active_version(); }
  1633. +
  1634. + bool is_newest_version() const { return _new_version == NULL; }
  1635. +
  1636. + // END class redefinition utilities
  1637. +
  1638. // Return the element of the _super chain of the given depth.
  1639. // If there is no such element, return either NULL or this.
  1640. Klass* primary_super_of_depth(juint i) const {
  1641. @@ -261,6 +322,7 @@
  1642. Klass* subklass() const;
  1643. Klass* next_sibling() const;
  1644. void append_to_sibling_list(); // add newly created receiver to superklass' subklass list
  1645. + void remove_from_sibling_list(); // (DCEVM) remove receiver from sibling list
  1646. void set_next_link(Klass* k) { _next_link = k; }
  1647. Klass* next_link() const { return _next_link; } // The next klass defined by the class loader.
  1648. @@ -287,6 +349,16 @@
  1649. void set_next_sibling(Klass* s);
  1650. public:
  1651. + // (DCEVM) Different class redefinition flags of code evolution.
  1652. + enum RedefinitionFlags {
  1653. + NoRedefinition, // This class is not redefined at all!
  1654. + ModifyClass = 1, // There are changes to the class meta data.
  1655. + ModifyClassSize = ModifyClass << 1, // The size of the class meta data changes.
  1656. + ModifyInstances = ModifyClassSize << 1, // There are change to the instance format.
  1657. + ModifyInstanceSize = ModifyInstances << 1, // The size of instances changes.
  1658. + RemoveSuperType = ModifyInstanceSize << 1, // A super type of this class is removed.
  1659. + MarkedAsAffected = RemoveSuperType << 1 // This class has been marked as an affected class.
  1660. + };
  1661. // Compiler support
  1662. static ByteSize super_offset() { return in_ByteSize(offset_of(Klass, _super)); }
  1663. diff -r 8a6717910608 src/share/vm/oops/klassVtable.cpp
  1664. --- a/src/share/vm/oops/klassVtable.cpp Tue Mar 11 13:02:13 2014 -0700
  1665. +++ b/src/share/vm/oops/klassVtable.cpp Wed Apr 30 11:27:18 2014 -0700
  1666. @@ -1409,6 +1409,8 @@
  1667. void klassVtable::verify_against(outputStream* st, klassVtable* vt, int index) {
  1668. vtableEntry* vte = &vt->table()[index];
  1669. + // (DCEVM) FIXME-isd: do we need the following line?
  1670. + if (vte->method() == NULL || table()[index].method() == NULL) return;
  1671. if (vte->method()->name() != table()[index].method()->name() ||
  1672. vte->method()->signature() != table()[index].method()->signature()) {
  1673. fatal("mismatched name/signature of vtable entries");
  1674. @@ -1428,6 +1430,8 @@
  1675. void vtableEntry::verify(klassVtable* vt, outputStream* st) {
  1676. NOT_PRODUCT(FlagSetting fs(IgnoreLockingAssertions, true));
  1677. + // FIXME: (DCEVM) does not hold?
  1678. + if (method() != NULL) {
  1679. assert(method() != NULL, "must have set method");
  1680. method()->verify();
  1681. // we sub_type, because it could be a miranda method
  1682. @@ -1435,7 +1439,9 @@
  1683. #ifndef PRODUCT
  1684. print();
  1685. #endif
  1686. - fatal(err_msg("vtableEntry " PTR_FORMAT ": method is from subclass", this));
  1687. + // (DCEVM) the following fatal does not work for old versions of classes
  1688. + //fatal(err_msg("vtableEntry " PTR_FORMAT ": method is from subclass", this));
  1689. + }
  1690. }
  1691. }
  1692. diff -r 8a6717910608 src/share/vm/oops/method.cpp
  1693. --- a/src/share/vm/oops/method.cpp Tue Mar 11 13:02:13 2014 -0700
  1694. +++ b/src/share/vm/oops/method.cpp Wed Apr 30 11:27:18 2014 -0700
  1695. @@ -1185,6 +1185,8 @@
  1696. // Reset correct method/const method, method size, and parameter info
  1697. newm->set_constMethod(newcm);
  1698. + newm->set_new_version(newm->new_version());
  1699. + newm->set_old_version(newm->old_version());
  1700. newm->constMethod()->set_code_size(new_code_length);
  1701. newm->constMethod()->set_constMethod_size(new_const_method_size);
  1702. newm->set_method_size(new_method_size);
  1703. @@ -1788,6 +1790,10 @@
  1704. // Add a method id to the jmethod_ids
  1705. jmethodID Method::make_jmethod_id(ClassLoaderData* loader_data, Method* m) {
  1706. + // FIXME: (DCEVM) ???
  1707. + if (m != m->newest_version()) {
  1708. + m = m->newest_version();
  1709. + }
  1710. ClassLoaderData* cld = loader_data;
  1711. if (!SafepointSynchronize::is_at_safepoint()) {
  1712. diff -r 8a6717910608 src/share/vm/oops/method.hpp
  1713. --- a/src/share/vm/oops/method.hpp Tue Mar 11 13:02:13 2014 -0700
  1714. +++ b/src/share/vm/oops/method.hpp Wed Apr 30 11:27:18 2014 -0700
  1715. @@ -105,6 +105,10 @@
  1716. AccessFlags _access_flags; // Access flags
  1717. int _vtable_index; // vtable index of this method (see VtableIndexFlag)
  1718. // note: can have vtables with >2**16 elements (because of inheritance)
  1719. + // (DCEVM) Newer version of method available?
  1720. + Method* _new_version;
  1721. + Method* _old_version;
  1722. +
  1723. #ifdef CC_INTERP
  1724. int _result_index; // C++ interpreter needs for converting results to/from stack
  1725. #endif
  1726. @@ -175,6 +179,23 @@
  1727. int name_index() const { return constMethod()->name_index(); }
  1728. void set_name_index(int index) { constMethod()->set_name_index(index); }
  1729. + Method* new_version() const { return _new_version; }
  1730. + void set_new_version(Method* m) { _new_version = m; }
  1731. + Method* newest_version() { return (_new_version == NULL) ? this : _new_version->newest_version(); }
  1732. +
  1733. + Method* old_version() const { return _old_version; }
  1734. + void set_old_version(Method* m) {
  1735. + /*if (m == NULL) {
  1736. + _old_version = NULL;
  1737. + return;
  1738. + }*/
  1739. +
  1740. + assert(_old_version == NULL, "may only be set once");
  1741. + assert(this->code_size() == m->code_size(), "must have same code length");
  1742. + _old_version = m;
  1743. + }
  1744. + const Method* oldest_version() const { return (_old_version == NULL) ? this : _old_version->oldest_version(); }
  1745. +
  1746. // signature
  1747. Symbol* signature() const { return constants()->symbol_at(signature_index()); }
  1748. int signature_index() const { return constMethod()->signature_index(); }
  1749. diff -r 8a6717910608 src/share/vm/prims/jni.cpp
  1750. --- a/src/share/vm/prims/jni.cpp Tue Mar 11 13:02:13 2014 -0700
  1751. +++ b/src/share/vm/prims/jni.cpp Wed Apr 30 11:27:18 2014 -0700
  1752. @@ -406,6 +406,7 @@
  1753. }
  1754. Klass* k = SystemDictionary::resolve_from_stream(class_name, class_loader,
  1755. Handle(), &st, true,
  1756. + KlassHandle(),
  1757. CHECK_NULL);
  1758. if (TraceClassResolution && k != NULL) {
  1759. diff -r 8a6717910608 src/share/vm/prims/jvm.cpp
  1760. --- a/src/share/vm/prims/jvm.cpp Tue Mar 11 13:02:13 2014 -0700
  1761. +++ b/src/share/vm/prims/jvm.cpp Wed Apr 30 11:27:18 2014 -0700
  1762. @@ -904,6 +904,7 @@
  1763. Klass* k = SystemDictionary::resolve_from_stream(class_name, class_loader,
  1764. protection_domain, &st,
  1765. verify != 0,
  1766. + KlassHandle(),
  1767. CHECK_NULL);
  1768. if (TraceClassResolution && k != NULL) {
  1769. diff -r 8a6717910608 src/share/vm/prims/jvmtiEnv.cpp
  1770. --- a/src/share/vm/prims/jvmtiEnv.cpp Tue Mar 11 13:02:13 2014 -0700
  1771. +++ b/src/share/vm/prims/jvmtiEnv.cpp Wed Apr 30 11:27:18 2014 -0700
  1772. @@ -42,6 +42,7 @@
  1773. #include "prims/jvmtiManageCapabilities.hpp"
  1774. #include "prims/jvmtiRawMonitor.hpp"
  1775. #include "prims/jvmtiRedefineClasses.hpp"
  1776. +#include "prims/jvmtiRedefineClasses2.hpp"
  1777. #include "prims/jvmtiTagMap.hpp"
  1778. #include "prims/jvmtiThreadState.inline.hpp"
  1779. #include "prims/jvmtiUtil.hpp"
  1780. @@ -206,8 +207,10 @@
  1781. // is_modifiable_class_ptr - pre-checked for NULL
  1782. jvmtiError
  1783. JvmtiEnv::IsModifiableClass(oop k_mirror, jboolean* is_modifiable_class_ptr) {
  1784. - *is_modifiable_class_ptr = VM_RedefineClasses::is_modifiable_class(k_mirror)?
  1785. - JNI_TRUE : JNI_FALSE;
  1786. + bool is_modifiable_class = AllowEnhancedClassRedefinition ?
  1787. + VM_EnhancedRedefineClasses::is_modifiable_class(k_mirror) :
  1788. + VM_RedefineClasses::is_modifiable_class(k_mirror);
  1789. + *is_modifiable_class_ptr = is_modifiable_class ? JNI_TRUE : JNI_FALSE;
  1790. return JVMTI_ERROR_NONE;
  1791. } /* end IsModifiableClass */
  1792. @@ -276,6 +279,11 @@
  1793. }
  1794. class_definitions[index].klass = jcls;
  1795. }
  1796. + if (AllowEnhancedClassRedefinition) {
  1797. + VM_EnhancedRedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_retransform);
  1798. + VMThread::execute(&op);
  1799. + return (op.check_error());
  1800. + }
  1801. VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_retransform);
  1802. VMThread::execute(&op);
  1803. return (op.check_error());
  1804. @@ -287,6 +295,11 @@
  1805. jvmtiError
  1806. JvmtiEnv::RedefineClasses(jint class_count, const jvmtiClassDefinition* class_definitions) {
  1807. //TODO: add locking
  1808. + if (AllowEnhancedClassRedefinition) {
  1809. + VM_EnhancedRedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_redefine);
  1810. + VMThread::execute(&op);
  1811. + return (op.check_error());
  1812. + }
  1813. VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_redefine);
  1814. VMThread::execute(&op);
  1815. return (op.check_error());
  1816. diff -r 8a6717910608 src/share/vm/prims/jvmtiExport.hpp
  1817. --- a/src/share/vm/prims/jvmtiExport.hpp Tue Mar 11 13:02:13 2014 -0700
  1818. +++ b/src/share/vm/prims/jvmtiExport.hpp Wed Apr 30 11:27:18 2014 -0700
  1819. @@ -188,6 +188,7 @@
  1820. // systems as needed to relax invariant checks.
  1821. static bool _has_redefined_a_class;
  1822. friend class VM_RedefineClasses;
  1823. + friend class VM_EnhancedRedefineClasses;
  1824. inline static void set_has_redefined_a_class() {
  1825. JVMTI_ONLY(_has_redefined_a_class = true;)
  1826. }
  1827. diff -r 8a6717910608 src/share/vm/prims/jvmtiImpl.cpp
  1828. --- a/src/share/vm/prims/jvmtiImpl.cpp Tue Mar 11 13:02:13 2014 -0700
  1829. +++ b/src/share/vm/prims/jvmtiImpl.cpp Wed Apr 30 11:27:18 2014 -0700
  1830. @@ -289,6 +289,11 @@
  1831. Symbol* m_name = _method->name();
  1832. Symbol* m_signature = _method->signature();
  1833. + // (DCEVM) Go through old versions of method
  1834. + for (Method* m = _method->old_version(); m != NULL; m = m->old_version()) {
  1835. + (m->*meth_act)(_bci);
  1836. + }
  1837. +
  1838. // search previous versions if they exist
  1839. PreviousVersionWalker pvw(thread, (InstanceKlass *)ikh());
  1840. for (PreviousVersionNode * pv_node = pvw.next_previous_version();
  1841. diff -r 8a6717910608 src/share/vm/prims/jvmtiRedefineClasses2.cpp
  1842. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  1843. +++ b/src/share/vm/prims/jvmtiRedefineClasses2.cpp Wed Apr 30 11:27:18 2014 -0700
  1844. @@ -0,0 +1,2034 @@
  1845. +/*
  1846. + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  1847. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  1848. + *
  1849. + * This code is free software; you can redistribute it and/or modify it
  1850. + * under the terms of the GNU General Public License version 2 only, as
  1851. + * published by the Free Software Foundation.
  1852. + *
  1853. + * This code is distributed in the hope that it will be useful, but WITHOUT
  1854. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  1855. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  1856. + * version 2 for more details (a copy is included in the LICENSE file that
  1857. + * accompanied this code).
  1858. + *
  1859. + * You should have received a copy of the GNU General Public License version
  1860. + * 2 along with this work; if not, write to the Free Software Foundation,
  1861. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  1862. + *
  1863. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  1864. + * or visit www.oracle.com if you need additional information or have any
  1865. + * questions.
  1866. + *
  1867. + */
  1868. +
  1869. +#include "precompiled.hpp"
  1870. +#include "classfile/systemDictionary.hpp"
  1871. +#include "classfile/verifier.hpp"
  1872. +#include "code/codeCache.hpp"
  1873. +#include "interpreter/oopMapCache.hpp"
  1874. +#include "interpreter/rewriter.hpp"
  1875. +#include "memory/gcLocker.hpp"
  1876. +#include "memory/universe.inline.hpp"
  1877. +#include "memory/metaspaceShared.hpp"
  1878. +#include "oops/fieldStreams.hpp"
  1879. +#include "oops/klassVtable.hpp"
  1880. +#include "prims/jvmtiImpl.hpp"
  1881. +#include "prims/jvmtiRedefineClasses2.hpp"
  1882. +#include "prims/methodComparator.hpp"
  1883. +#include "prims/jvmtiClassFileReconstituter.hpp"
  1884. +#include "runtime/deoptimization.hpp"
  1885. +#include "runtime/relocator.hpp"
  1886. +#include "utilities/bitMap.inline.hpp"
  1887. +#include "compiler/compileBroker.hpp"
  1888. +#include "oops/instanceMirrorKlass.hpp"
  1889. +#include "utilities/pair.hpp"
  1890. +
  1891. +
  1892. +Array<Method*>* VM_EnhancedRedefineClasses::_old_methods = NULL;
  1893. +Array<Method*>* VM_EnhancedRedefineClasses::_new_methods = NULL;
  1894. +int* VM_EnhancedRedefineClasses::_matching_old_methods = NULL;
  1895. +int* VM_EnhancedRedefineClasses::_matching_new_methods = NULL;
  1896. +int* VM_EnhancedRedefineClasses::_deleted_methods = NULL;
  1897. +int* VM_EnhancedRedefineClasses::_added_methods = NULL;
  1898. +int VM_EnhancedRedefineClasses::_matching_methods_length = 0;
  1899. +int VM_EnhancedRedefineClasses::_deleted_methods_length = 0;
  1900. +int VM_EnhancedRedefineClasses::_added_methods_length = 0;
  1901. +GrowableArray<instanceKlassHandle>* VM_EnhancedRedefineClasses::_affected_klasses = NULL;
  1902. +
  1903. +
  1904. +// Holds the revision number of the current class redefinition
  1905. +int VM_EnhancedRedefineClasses::_revision_number = -1;
  1906. +
  1907. +VM_EnhancedRedefineClasses::VM_EnhancedRedefineClasses(jint class_count, const jvmtiClassDefinition *class_defs, JvmtiClassLoadKind class_load_kind)
  1908. + : VM_GC_Operation(Universe::heap()->total_full_collections(), GCCause::_heap_inspection) {
  1909. + RC_TIMER_START(_timer_total);
  1910. + _class_count = class_count;
  1911. + _class_defs = class_defs;
  1912. + _class_load_kind = class_load_kind;
  1913. + _result = JVMTI_ERROR_NONE;
  1914. +}
  1915. +
  1916. +VM_EnhancedRedefineClasses::~VM_EnhancedRedefineClasses() {
  1917. + RC_TIMER_STOP(_timer_total);
  1918. +}
  1919. +
  1920. +void VM_EnhancedRedefineClasses::swap_all_method_annotations(ConstMethod* old_method, ConstMethod* new_method) {
  1921. + return; // FIXME-isd: swap annotations!
  1922. +
  1923. + AnnotationArray* save;
  1924. +
  1925. + save = old_method->method_annotations();
  1926. + old_method->set_method_annotations(new_method->method_annotations());
  1927. + new_method->set_method_annotations(save);
  1928. +
  1929. + save = old_method->parameter_annotations();
  1930. + old_method->set_parameter_annotations(new_method->parameter_annotations());
  1931. + new_method->set_parameter_annotations(save);
  1932. +
  1933. + save = old_method->default_annotations();
  1934. + old_method->set_default_annotations(new_method->default_annotations());
  1935. + new_method->set_default_annotations(save);
  1936. +
  1937. + save = old_method->type_annotations();
  1938. + old_method->set_type_annotations(new_method->type_annotations());
  1939. + new_method->set_type_annotations(save);
  1940. +}
  1941. +
  1942. +void VM_EnhancedRedefineClasses::add_affected_klasses( Klass* klass )
  1943. +{
  1944. + assert(!_affected_klasses->contains(klass), "must not occur more than once!");
  1945. + assert(klass->new_version() == NULL, "Only last version is valid entry in system dictionary");
  1946. +
  1947. + Klass* k = klass;
  1948. +
  1949. + if (k->check_redefinition_flag(Klass::MarkedAsAffected)) {
  1950. + _affected_klasses->append(klass);
  1951. + return;
  1952. + }
  1953. +
  1954. + for (juint i = 0; i < k->super_depth(); i++) {
  1955. + Klass* primary = k->primary_super_of_depth(i);
  1956. + // super_depth returns "8" for interfaces, but they don't have primaries other than Object.
  1957. + if (primary == NULL) break;
  1958. + if (primary->check_redefinition_flag(Klass::MarkedAsAffected)) {
  1959. + RC_TRACE(0x00000001, ("Found affected class: %s", k->name()->as_C_string()));
  1960. + k->set_redefinition_flag(Klass::MarkedAsAffected);
  1961. + _affected_klasses->append(klass);
  1962. + return;
  1963. + }
  1964. + }
  1965. +
  1966. + // Check secondary supers
  1967. + int cnt = k->secondary_supers()->length();
  1968. + for (int i = 0; i < cnt; i++) {
  1969. + Klass* secondary = k->secondary_supers()->at(i);
  1970. + if (secondary->check_redefinition_flag(Klass::MarkedAsAffected)) {
  1971. + RC_TRACE(0x00000001, ("Found affected class: %s", k->name()->as_C_string()));
  1972. + k->set_redefinition_flag(Klass::MarkedAsAffected);
  1973. + _affected_klasses->append(klass);
  1974. + return;
  1975. + }
  1976. + }
  1977. +}
  1978. +
  1979. +
  1980. +// Searches for all affected classes and performs a sorting such that a supertype is always before a subtype.
  1981. +jvmtiError VM_EnhancedRedefineClasses::find_sorted_affected_classes() {
  1982. +
  1983. + assert(_affected_klasses, "");
  1984. + for (int i = 0; i < _class_count; i++) {
  1985. + oop mirror = JNIHandles::resolve_non_null(_class_defs[i].klass);
  1986. + instanceKlassHandle klass_handle(Thread::current(), java_lang_Class::as_Klass(mirror));
  1987. + klass_handle->set_redefinition_flag(Klass::MarkedAsAffected);
  1988. + assert(klass_handle->new_version() == NULL, "Must be new class");
  1989. + }
  1990. +
  1991. + // Find classes not directly redefined, but affected by a redefinition (because one of its supertypes is redefined)
  1992. + SystemDictionary::classes_do(VM_EnhancedRedefineClasses::add_affected_klasses);
  1993. + RC_TRACE(0x00000001, ("%d classes affected", _affected_klasses->length()));
  1994. +
  1995. + // Sort the affected klasses such that a supertype is always on a smaller array index than its subtype.
  1996. + jvmtiError result = do_topological_class_sorting(_class_defs, _class_count, Thread::current());
  1997. + if (RC_TRACE_ENABLED(0x00000001)) {
  1998. + RC_TRACE(0x00000001, ("Redefine order: "));
  1999. + for (int i = 0; i < _affected_klasses->length(); i++) {
  2000. + RC_TRACE(0x00000001, ("%s", _affected_klasses->at(i)->name()->as_C_string()));
  2001. + }
  2002. + }
  2003. +
  2004. + return result;
  2005. +}
  2006. +
  2007. +// Searches for the class bytes of the given class and returns them as a byte array.
  2008. +jvmtiError VM_EnhancedRedefineClasses::find_class_bytes(instanceKlassHandle the_class, const unsigned char **class_bytes, jint *class_byte_count, jboolean *not_changed) {
  2009. +
  2010. + *not_changed = false;
  2011. +
  2012. + // Search for the index in the redefinition array that corresponds to the current class
  2013. + int j;
  2014. + for (j=0; j<_class_count; j++) {
  2015. + oop mirror = JNIHandles::resolve_non_null(_class_defs[j].klass);
  2016. + Klass* the_class_oop = java_lang_Class::as_Klass(mirror);
  2017. + if (the_class_oop == the_class()) {
  2018. + break;
  2019. + }
  2020. + }
  2021. +
  2022. + if (j == _class_count) {
  2023. +
  2024. + *not_changed = true;
  2025. +
  2026. + // Redefine with same bytecodes. This is a class that is only indirectly affected by redefinition,
  2027. + // so the user did not specify a different bytecode for that class.
  2028. +
  2029. + if (the_class->get_cached_class_file_bytes() == NULL) {
  2030. + // not cached, we need to reconstitute the class file from VM representation
  2031. + constantPoolHandle constants(Thread::current(), the_class->constants());
  2032. + MonitorLockerEx ml(constants->lock()); // lock constant pool while we query it
  2033. + //ObjectLocker ol(constants, Thread::current()); // lock constant pool while we query it
  2034. +
  2035. + JvmtiClassFileReconstituter reconstituter(the_class);
  2036. + if (reconstituter.get_error() != JVMTI_ERROR_NONE) {
  2037. + return reconstituter.get_error();
  2038. + }
  2039. +
  2040. + *class_byte_count = (jint)reconstituter.class_file_size();
  2041. + *class_bytes = (unsigned char*)reconstituter.class_file_bytes();
  2042. + } else {
  2043. +
  2044. + // it is cached, get it from the cache
  2045. + *class_byte_count = the_class->get_cached_class_file_len();
  2046. + *class_bytes = the_class->get_cached_class_file_bytes();
  2047. + }
  2048. +
  2049. + } else {
  2050. +
  2051. + // Redefine with bytecodes at index j
  2052. + *class_bytes = _class_defs[j].class_bytes;
  2053. + *class_byte_count = _class_defs[j].class_byte_count;
  2054. + }
  2055. +
  2056. + return JVMTI_ERROR_NONE;
  2057. + }
  2058. +
  2059. +// Prologue of the VM operation, called on the Java thread in parallel to normal program execution
  2060. +bool VM_EnhancedRedefineClasses::doit_prologue() {
  2061. +
  2062. + _revision_number++;
  2063. + RC_TRACE(0x00000001,
  2064. + ("Redefinition with revision number %d started!", _revision_number));
  2065. +
  2066. + assert(Thread::current()->is_Java_thread(), "must be Java thread");
  2067. + RC_TIMER_START(_timer_prologue);
  2068. +
  2069. + if (!check_arguments()) {
  2070. + RC_TIMER_STOP(_timer_prologue);
  2071. + return false;
  2072. + }
  2073. +
  2074. + // We first load new class versions in the prologue, because somewhere down the
  2075. + // call chain it is required that the current thread is a Java thread.
  2076. + _new_classes = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<instanceKlassHandle>(5, true);
  2077. +
  2078. + assert(_affected_klasses == NULL, "");
  2079. + _affected_klasses = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<instanceKlassHandle>(_class_count, true);
  2080. +
  2081. + _result = load_new_class_versions(Thread::current());
  2082. +
  2083. + RC_TRACE(0x00000001,
  2084. + ("Loaded new class versions!"));
  2085. + if (_result != JVMTI_ERROR_NONE) {
  2086. + RC_TRACE(0x00000001,
  2087. + ("error occured: %d!", _result));
  2088. + delete _new_classes;
  2089. + _new_classes = NULL;
  2090. + delete _affected_klasses;
  2091. + _affected_klasses = NULL;
  2092. + RC_TIMER_STOP(_timer_prologue);
  2093. + return false;
  2094. + }
  2095. +
  2096. + VM_GC_Operation::doit_prologue();
  2097. + RC_TIMER_STOP(_timer_prologue);
  2098. +
  2099. + RC_TRACE(0x00000001, ("doit_prologue finished!"));
  2100. + return true;
  2101. +}
  2102. +
  2103. +// Checks basic properties of the arguments of the redefinition command.
  2104. +jvmtiError VM_EnhancedRedefineClasses::check_arguments_error() {
  2105. + if (_class_defs == NULL) return JVMTI_ERROR_NULL_POINTER;
  2106. + for (int i = 0; i < _class_count; i++) {
  2107. + if (_class_defs[i].klass == NULL) return JVMTI_ERROR_INVALID_CLASS;
  2108. + if (_class_defs[i].class_byte_count == 0) return JVMTI_ERROR_INVALID_CLASS_FORMAT;
  2109. + if (_class_defs[i].class_bytes == NULL) return JVMTI_ERROR_NULL_POINTER;
  2110. + }
  2111. + return JVMTI_ERROR_NONE;
  2112. + }
  2113. +
  2114. +// Returns false and sets an result error code if the redefinition should be aborted.
  2115. +bool VM_EnhancedRedefineClasses::check_arguments() {
  2116. + jvmtiError error = check_arguments_error();
  2117. + if (error != JVMTI_ERROR_NONE || _class_count == 0) {
  2118. + _result = error;
  2119. + return false;
  2120. + }
  2121. + return true;
  2122. +}
  2123. +
  2124. +jvmtiError VM_EnhancedRedefineClasses::check_exception() const {
  2125. + Thread* THREAD = Thread::current();
  2126. + if (HAS_PENDING_EXCEPTION) {
  2127. +
  2128. + Symbol* ex_name = PENDING_EXCEPTION->klass()->name();
  2129. + RC_TRACE_WITH_THREAD(0x00000002, THREAD, ("parse_stream exception: '%s'", ex_name->as_C_string()));
  2130. + CLEAR_PENDING_EXCEPTION;
  2131. +
  2132. + if (ex_name == vmSymbols::java_lang_UnsupportedClassVersionError()) {
  2133. + return JVMTI_ERROR_UNSUPPORTED_VERSION;
  2134. + } else if (ex_name == vmSymbols::java_lang_ClassFormatError()) {
  2135. + return JVMTI_ERROR_INVALID_CLASS_FORMAT;
  2136. + } else if (ex_name == vmSymbols::java_lang_ClassCircularityError()) {
  2137. + return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  2138. + } else if (ex_name == vmSymbols::java_lang_NoClassDefFoundError()) {
  2139. + // The message will be "XXX (wrong name: YYY)"
  2140. + return JVMTI_ERROR_NAMES_DONT_MATCH;
  2141. + } else if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  2142. + return JVMTI_ERROR_OUT_OF_MEMORY;
  2143. + } else {
  2144. + // Just in case more exceptions can be thrown..
  2145. + return JVMTI_ERROR_FAILS_VERIFICATION;
  2146. + }
  2147. + }
  2148. +
  2149. + return JVMTI_ERROR_NONE;
  2150. +}
  2151. +
  2152. +// Loads all new class versions and stores the InstanceKlass handles in an array.
  2153. +jvmtiError VM_EnhancedRedefineClasses::load_new_class_versions(TRAPS) {
  2154. +
  2155. + ResourceMark rm(THREAD);
  2156. +
  2157. + RC_TRACE(0x00000001,
  2158. + ("loading new class versions (%d)", _class_count));
  2159. +
  2160. + // Retrieve an array of all classes that need to be redefined
  2161. + jvmtiError err = find_sorted_affected_classes();
  2162. + if (err != JVMTI_ERROR_NONE) {
  2163. + RC_TRACE(0x00000001,
  2164. + ("Error finding sorted affected classes: %d", (int)err));
  2165. + return err;
  2166. + }
  2167. +
  2168. +
  2169. + JvmtiThreadState *state = JvmtiThreadState::state_for(JavaThread::current());
  2170. +
  2171. + _max_redefinition_flags = Klass::NoRedefinition;
  2172. + jvmtiError result = JVMTI_ERROR_NONE;
  2173. +
  2174. + for (int i = 0; i < _affected_klasses->length(); i++) {
  2175. + instanceKlassHandle the_class = _affected_klasses->at(i);
  2176. +
  2177. + RC_TRACE(0x00000001,
  2178. + ("Processing affected class %s (%d of %d)",
  2179. + the_class->name()->as_C_string(),
  2180. + i + 1,
  2181. + _affected_klasses->length()));
  2182. +
  2183. + the_class->link_class(THREAD);
  2184. + result = check_exception();
  2185. + if (result != JVMTI_ERROR_NONE) break;
  2186. +
  2187. + // Find new class bytes
  2188. + const unsigned char* class_bytes;
  2189. + jint class_byte_count;
  2190. + jvmtiError error;
  2191. + jboolean not_changed;
  2192. + if ((error = find_class_bytes(the_class, &class_bytes, &class_byte_count, &not_changed)) != JVMTI_ERROR_NONE) {
  2193. + RC_TRACE_WITH_THREAD(0x00000002, THREAD,
  2194. + ("Error finding class bytes: %d", (int)error));
  2195. + result = error;
  2196. + break;
  2197. + }
  2198. + assert(class_bytes != NULL && class_byte_count != 0, "Class bytes defined at this point!");
  2199. +
  2200. +
  2201. + // Set redefined class handle in JvmtiThreadState class.
  2202. + // This redefined class is sent to agent event handler for class file
  2203. + // load hook event.
  2204. + state->set_class_being_redefined(&the_class, _class_load_kind);
  2205. +
  2206. + RC_TIMER_STOP(_timer_prologue);
  2207. + RC_TIMER_START(_timer_class_loading);
  2208. +
  2209. + // Parse the stream.
  2210. + Handle the_class_loader(THREAD, the_class->class_loader());
  2211. + Handle protection_domain(THREAD, the_class->protection_domain());
  2212. + ClassFileStream st((u1*) class_bytes, class_byte_count, (char *)"__VM_EhnancedRedefineClasses__");
  2213. +
  2214. + Klass* klass =
  2215. + SystemDictionary::resolve_from_stream(
  2216. + the_class->name(),
  2217. + the_class_loader,
  2218. + protection_domain,
  2219. + &st,
  2220. + true,
  2221. + the_class,
  2222. + THREAD);
  2223. + instanceKlassHandle new_class(THREAD, klass);
  2224. +
  2225. + RC_TIMER_STOP(_timer_class_loading);
  2226. + RC_TIMER_START(_timer_prologue);
  2227. +
  2228. + // Clear class_being_redefined just to be sure.
  2229. + state->clear_class_being_redefined();
  2230. +
  2231. + result = check_exception();
  2232. + if (result != JVMTI_ERROR_NONE) break;
  2233. +
  2234. + not_changed = false;
  2235. +
  2236. +#ifdef ASSERT
  2237. +
  2238. + assert(new_class() != NULL, "Class could not be loaded!");
  2239. + assert(new_class() != the_class(), "must be different");
  2240. + assert(new_class->new_version() == NULL && new_class->old_version() != NULL, "");
  2241. +
  2242. +
  2243. + Array<Klass*>* k_interfaces = new_class->local_interfaces();
  2244. + for (int j = 0; j < k_interfaces->length(); j++) {
  2245. + assert(k_interfaces->at(j)->is_newest_version(), "just checking");
  2246. + }
  2247. +
  2248. + if (!THREAD->is_Compiler_thread()) {
  2249. + RC_TRACE(0x00000001, ("name=%s loader="INTPTR_FORMAT" protection_domain="INTPTR_FORMAT,
  2250. + the_class->name()->as_C_string(),
  2251. + (intptr_t) (oopDesc*) the_class->class_loader(),
  2252. + (intptr_t) (oopDesc*) the_class->protection_domain()));
  2253. + // If we are on the compiler thread, we must not try to resolve a class.
  2254. + Klass* systemLookup = SystemDictionary::resolve_or_null(the_class->name(), the_class->class_loader(), the_class->protection_domain(), THREAD);
  2255. +
  2256. + if (systemLookup != NULL) {
  2257. + assert(systemLookup == new_class->old_version(), "Old class must be in system dictionary!");
  2258. + Klass *subklass = new_class()->subklass();
  2259. + while (subklass != NULL) {
  2260. + assert(subklass->new_version() == NULL, "Most recent version of class!");
  2261. + subklass = subklass->next_sibling();
  2262. + }
  2263. + } else {
  2264. + // This can happen for reflection generated classes.. ?
  2265. + CLEAR_PENDING_EXCEPTION;
  2266. + }
  2267. + }
  2268. +
  2269. +#endif
  2270. +
  2271. + if (RC_TRACE_ENABLED(0x00000001)) {
  2272. + if (new_class->layout_helper() != the_class->layout_helper()) {
  2273. + RC_TRACE(0x00000001,
  2274. + ("Instance size change for class %s: new=%d old=%d",
  2275. + new_class->name()->as_C_string(),
  2276. + new_class->layout_helper(),
  2277. + the_class->layout_helper()));
  2278. + }
  2279. + }
  2280. +
  2281. + // Set the new version of the class
  2282. + new_class->set_revision_number(_revision_number);
  2283. + new_class->set_redefinition_index(i);
  2284. + the_class->set_new_version(new_class());
  2285. + _new_classes->append(new_class);
  2286. +
  2287. + assert(new_class->new_version() == NULL, "");
  2288. +
  2289. + int redefinition_flags = Klass::NoRedefinition;
  2290. +
  2291. + if (not_changed) {
  2292. + redefinition_flags = Klass::NoRedefinition;
  2293. + } else {
  2294. + redefinition_flags = calculate_redefinition_flags(new_class);
  2295. + if (redefinition_flags >= Klass::RemoveSuperType) {
  2296. + result = JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  2297. + break;
  2298. + }
  2299. + }
  2300. +
  2301. + if (new_class->super() != NULL) {
  2302. + redefinition_flags = redefinition_flags | new_class->super()->redefinition_flags();
  2303. + }
  2304. +
  2305. + for (int j = 0; j<new_class->local_interfaces()->length(); j++) {
  2306. + redefinition_flags = redefinition_flags | (new_class->local_interfaces()->at(j))->redefinition_flags();
  2307. + }
  2308. +
  2309. + new_class->set_redefinition_flags(redefinition_flags);
  2310. +
  2311. + _max_redefinition_flags = _max_redefinition_flags | redefinition_flags;
  2312. +
  2313. + if ((redefinition_flags & Klass::ModifyInstances) != 0) {
  2314. + // TODO: Check if watch access flags of static fields are updated correctly.
  2315. + calculate_instance_update_information(_new_classes->at(i)());
  2316. + } else {
  2317. + // Fields were not changed, transfer special flags only
  2318. + assert(new_class->layout_helper() >> 1 == new_class->old_version()->layout_helper() >> 1, "must be equal");
  2319. + assert(new_class->fields()->length() == InstanceKlass::cast(new_class->old_version())->fields()->length(), "must be equal");
  2320. +
  2321. + JavaFieldStream old_fs(the_class);
  2322. + JavaFieldStream new_fs(new_class);
  2323. + for (; !old_fs.done() && !new_fs.done(); old_fs.next(), new_fs.next()) {
  2324. + AccessFlags flags = new_fs.access_flags();
  2325. + flags.set_is_field_modification_watched(old_fs.access_flags().is_field_modification_watched());
  2326. + flags.set_is_field_access_watched(old_fs.access_flags().is_field_access_watched());
  2327. + new_fs.set_access_flags(flags);
  2328. + }
  2329. + }
  2330. +
  2331. + if (RC_TRACE_ENABLED(0x00000001)) {
  2332. + RC_TRACE(0x00000001,
  2333. + ("Super class is %s", new_class->super()->name()->as_C_string()));
  2334. + }
  2335. +
  2336. +#ifdef ASSERT
  2337. + assert(new_class->super() == NULL || new_class->super()->new_version() == NULL, "Super klass must be newest version!");
  2338. +
  2339. + the_class->vtable()->verify(tty);
  2340. + new_class->vtable()->verify(tty);
  2341. +#endif
  2342. +
  2343. + if (i == _affected_klasses->length() - 1) {
  2344. + // This was the last class processed => check if additional classes have been loaded in the meantime
  2345. + for (int j = 0; j<_affected_klasses->length(); j++) {
  2346. +
  2347. + Klass* initial_klass = _affected_klasses->at(j)();
  2348. + Klass *initial_subklass = initial_klass->subklass();
  2349. + Klass *cur_klass = initial_subklass;
  2350. + while(cur_klass != NULL) {
  2351. +
  2352. + if(cur_klass->oop_is_instance() && cur_klass->is_newest_version() && !cur_klass->is_redefining()) {
  2353. + instanceKlassHandle handle(THREAD, cur_klass);
  2354. + if (!_affected_klasses->contains(handle)) {
  2355. +
  2356. + int k = i + 1;
  2357. + for (; k<_affected_klasses->length(); k++) {
  2358. + if (_affected_klasses->at(k)->is_subtype_of(cur_klass)) {
  2359. + break;
  2360. + }
  2361. + }
  2362. + _affected_klasses->insert_before(k, handle);
  2363. + RC_TRACE(0x00000001,
  2364. + ("Adding newly loaded class to affected classes: %s", cur_klass->name()->as_C_string()));
  2365. + }
  2366. + }
  2367. +
  2368. + cur_klass = cur_klass->next_sibling();
  2369. + }
  2370. + }
  2371. +
  2372. + int new_count = _affected_klasses->length() - 1 - i;
  2373. + if (new_count != 0) {
  2374. + RC_TRACE(0x00000001,
  2375. + ("Found new number of affected classes: %d", new_count));
  2376. + }
  2377. + }
  2378. + }
  2379. +
  2380. + if (result != JVMTI_ERROR_NONE) {
  2381. + rollback();
  2382. + return result;
  2383. + }
  2384. +
  2385. + RC_TIMER_STOP(_timer_prologue);
  2386. + RC_TIMER_START(_timer_class_linking);
  2387. + // Link and verify new classes _after_ all classes have been updated in the system dictionary!
  2388. + for (int i=0; i<_affected_klasses->length(); i++) {
  2389. + instanceKlassHandle the_class = _affected_klasses->at(i);
  2390. + instanceKlassHandle new_class(the_class->new_version());
  2391. +
  2392. + RC_TRACE(0x00000001,
  2393. + ("Linking class %d/%d %s", i, _affected_klasses->length(), the_class->name()->as_C_string()));
  2394. + new_class->link_class(THREAD);
  2395. +
  2396. + result = check_exception();
  2397. + if (result != JVMTI_ERROR_NONE) break;
  2398. + }
  2399. + RC_TIMER_STOP(_timer_class_linking);
  2400. + RC_TIMER_START(_timer_prologue);
  2401. +
  2402. + if (result != JVMTI_ERROR_NONE) {
  2403. + rollback();
  2404. + return result;
  2405. + }
  2406. +
  2407. + RC_TRACE(0x00000001, ("All classes loaded!"));
  2408. +
  2409. +#ifdef ASSERT
  2410. + for (int i=0; i<_affected_klasses->length(); i++) {
  2411. + instanceKlassHandle the_class = _affected_klasses->at(i);
  2412. + assert(the_class->new_version() != NULL, "Must have been redefined");
  2413. + instanceKlassHandle new_version = instanceKlassHandle(THREAD, the_class->new_version());
  2414. + assert(new_version->new_version() == NULL, "Must be newest version");
  2415. +
  2416. + if (!(new_version->super() == NULL || new_version->super()->new_version() == NULL)) {
  2417. + new_version()->print();
  2418. + new_version->super()->print();
  2419. + }
  2420. + assert(new_version->super() == NULL || new_version->super()->new_version() == NULL, "Super class must be newest version");
  2421. + }
  2422. +
  2423. + SystemDictionary::classes_do(check_class, THREAD);
  2424. +
  2425. +#endif
  2426. +
  2427. + RC_TRACE(0x00000001, ("Finished verification!"));
  2428. + return JVMTI_ERROR_NONE;
  2429. +}
  2430. +
  2431. +int VM_EnhancedRedefineClasses::calculate_redefinition_flags(instanceKlassHandle new_class) {
  2432. +
  2433. + int result = Klass::NoRedefinition;
  2434. + RC_TRACE(0x00000001,
  2435. + ("Comparing different class versions of class %s", new_class->name()->as_C_string()));
  2436. +
  2437. + assert(new_class->old_version() != NULL, "must have old version");
  2438. + instanceKlassHandle the_class(new_class->old_version());
  2439. +
  2440. + // Check whether class is in the error init state.
  2441. + if (the_class->is_in_error_state()) {
  2442. + // TBD #5057930: special error code is needed in 1.6
  2443. + //result = Klass::union_redefinition_level(result, Klass::Invalid);
  2444. + }
  2445. +
  2446. + int i;
  2447. +
  2448. + //////////////////////////////////////////////////////////////////////////////////////////////////////////
  2449. + // Check superclasses
  2450. + assert(new_class->super() == NULL || new_class->super()->is_newest_version(), "");
  2451. + if (the_class->super() != new_class->super()) {
  2452. + // Super class changed
  2453. + Klass* cur_klass = the_class->super();
  2454. + while (cur_klass != NULL) {
  2455. + if (!new_class->is_subclass_of(cur_klass->newest_version())) {
  2456. + RC_TRACE(0x00000001,
  2457. + ("Removed super class %s", cur_klass->name()->as_C_string()));
  2458. + result = result | Klass::RemoveSuperType | Klass::ModifyInstances | Klass::ModifyClass;
  2459. +
  2460. + if (!cur_klass->has_subtype_changed()) {
  2461. + RC_TRACE(0x00000001,
  2462. + ("Subtype changed of class %s", cur_klass->name()->as_C_string()));
  2463. + cur_klass->set_subtype_changed(true);
  2464. + }
  2465. + }
  2466. +
  2467. + cur_klass = cur_klass->super();
  2468. + }
  2469. +
  2470. + cur_klass = new_class->super();
  2471. + while (cur_klass != NULL) {
  2472. + if (!the_class->is_subclass_of(cur_klass->old_version())) {
  2473. + RC_TRACE(0x00000001,
  2474. + ("Added super class %s", cur_klass->name()->as_C_string()));
  2475. + result = result | Klass::ModifyClass | Klass::ModifyInstances;
  2476. + }
  2477. + cur_klass = cur_klass->super();
  2478. + }
  2479. + }
  2480. +
  2481. + //////////////////////////////////////////////////////////////////////////////////////////////////////////
  2482. + // Check interfaces
  2483. +
  2484. + // Interfaces removed?
  2485. + Array<Klass*>* old_interfaces = the_class->transitive_interfaces();
  2486. + for (i = 0; i<old_interfaces->length(); i++) {
  2487. + instanceKlassHandle old_interface(old_interfaces->at(i));
  2488. + if (!new_class->implements_interface_any_version(old_interface())) {
  2489. + result = result | Klass::RemoveSuperType | Klass::ModifyClass;
  2490. + RC_TRACE(0x00000001,
  2491. + ("Removed interface %s", old_interface->name()->as_C_string()));
  2492. +
  2493. + if (!old_interface->has_subtype_changed()) {
  2494. + RC_TRACE(0x00000001,
  2495. + ("Subtype changed of interface %s", old_interface->name()->as_C_string()));
  2496. + old_interface->set_subtype_changed(true);
  2497. + }
  2498. + }
  2499. + }
  2500. +
  2501. + // Interfaces added?
  2502. + Array<Klass*>* new_interfaces = new_class->transitive_interfaces();
  2503. + for (i = 0; i<new_interfaces->length(); i++) {
  2504. + if (!the_class->implements_interface_any_version(new_interfaces->at(i))) {
  2505. + result = result | Klass::ModifyClass;
  2506. + RC_TRACE(0x00000001,
  2507. + ("Added interface %s", new_interfaces->at(i)->name()->as_C_string()));
  2508. + }
  2509. + }
  2510. +
  2511. +
  2512. + // Check whether class modifiers are the same.
  2513. + jushort old_flags = (jushort) the_class->access_flags().get_flags();
  2514. + jushort new_flags = (jushort) new_class->access_flags().get_flags();
  2515. + if (old_flags != new_flags) {
  2516. + // TODO Can this have any effects?
  2517. + }
  2518. +
  2519. + // Check if the number, names, types and order of fields declared in these classes
  2520. + // are the same.
  2521. + JavaFieldStream old_fs(the_class);
  2522. + JavaFieldStream new_fs(new_class);
  2523. + for (; !old_fs.done() && !new_fs.done(); old_fs.next(), new_fs.next()) {
  2524. + // access
  2525. + old_flags = old_fs.access_flags().as_short();
  2526. + new_flags = new_fs.access_flags().as_short();
  2527. + if ((old_flags ^ new_flags) & JVM_RECOGNIZED_FIELD_MODIFIERS) {
  2528. + // TODO can this have any effect?
  2529. + }
  2530. + // offset
  2531. + if (old_fs.offset() != new_fs.offset()) {
  2532. + result = result | Klass::ModifyInstances;
  2533. + }
  2534. + // name and signature
  2535. + Symbol* name_sym1 = the_class->constants()->symbol_at(old_fs.name_index());
  2536. + Symbol* sig_sym1 = the_class->constants()->symbol_at(old_fs.signature_index());
  2537. + Symbol* name_sym2 = new_class->constants()->symbol_at(new_fs.name_index());
  2538. + Symbol* sig_sym2 = new_class->constants()->symbol_at(new_fs.signature_index());
  2539. + if (name_sym1 != name_sym2 || sig_sym1 != sig_sym2) {
  2540. + result = result | Klass::ModifyInstances;
  2541. + }
  2542. + }
  2543. +
  2544. + // If both streams aren't done then we have a differing number of
  2545. + // fields.
  2546. + if (!old_fs.done() || !new_fs.done()) {
  2547. + result = result | Klass::ModifyInstances;
  2548. + }
  2549. +
  2550. + // Do a parallel walk through the old and new methods. Detect
  2551. + // cases where they match (exist in both), have been added in
  2552. + // the new methods, or have been deleted (exist only in the
  2553. + // old methods). The class file parser places methods in order
  2554. + // by method name, but does not order overloaded methods by
  2555. + // signature. In order to determine what fate befell the methods,
  2556. + // this code places the overloaded new methods that have matching
  2557. + // old methods in the same order as the old methods and places
  2558. + // new overloaded methods at the end of overloaded methods of
  2559. + // that name. The code for this order normalization is adapted
  2560. + // from the algorithm used in InstanceKlass::find_method().
  2561. + // Since we are swapping out of order entries as we find them,
  2562. + // we only have to search forward through the overloaded methods.
  2563. + // Methods which are added and have the same name as an existing
  2564. + // method (but different signature) will be put at the end of
  2565. + // the methods with that name, and the name mismatch code will
  2566. + // handle them.
  2567. + Array<Method*>* k_old_methods(the_class->methods()); // FIXME-isd: handles???
  2568. + Array<Method*>* k_new_methods(new_class->methods());
  2569. + int n_old_methods = k_old_methods->length();
  2570. + int n_new_methods = k_new_methods->length();
  2571. +
  2572. + int ni = 0;
  2573. + int oi = 0;
  2574. + while (true) {
  2575. + Method* k_old_method;
  2576. + Method* k_new_method;
  2577. + enum { matched, added, deleted, undetermined } method_was = undetermined;
  2578. +
  2579. + if (oi >= n_old_methods) {
  2580. + if (ni >= n_new_methods) {
  2581. + break; // we've looked at everything, done
  2582. + }
  2583. + // New method at the end
  2584. + k_new_method = k_new_methods->at(ni);
  2585. + method_was = added;
  2586. + } else if (ni >= n_new_methods) {
  2587. + // Old method, at the end, is deleted
  2588. + k_old_method = k_old_methods->at(oi);
  2589. + method_was = deleted;
  2590. + } else {
  2591. + // There are more methods in both the old and new lists
  2592. + k_old_method = k_old_methods->at(oi);
  2593. + k_new_method = k_new_methods->at(ni);
  2594. + if (k_old_method->name() != k_new_method->name()) {
  2595. + // Methods are sorted by method name, so a mismatch means added
  2596. + // or deleted
  2597. + if (k_old_method->name()->fast_compare(k_new_method->name()) > 0) {
  2598. + method_was = added;
  2599. + } else {
  2600. + method_was = deleted;
  2601. + }
  2602. + } else if (k_old_method->signature() == k_new_method->signature()) {
  2603. + // Both the name and signature match
  2604. + method_was = matched;
  2605. + } else {
  2606. + // The name matches, but the signature doesn't, which means we have to
  2607. + // search forward through the new overloaded methods.
  2608. + int nj; // outside the loop for post-loop check
  2609. + for (nj = ni + 1; nj < n_new_methods; nj++) {
  2610. + Method* m = k_new_methods->at(nj);
  2611. + if (k_old_method->name() != m->name()) {
  2612. + // reached another method name so no more overloaded methods
  2613. + method_was = deleted;
  2614. + break;
  2615. + }
  2616. + if (k_old_method->signature() == m->signature()) {
  2617. + // found a match so swap the methods
  2618. + k_new_methods->at_put(ni, m);
  2619. + k_new_methods->at_put(nj, k_new_method);
  2620. + k_new_method = m;
  2621. + method_was = matched;
  2622. + break;
  2623. + }
  2624. + }
  2625. +
  2626. + if (nj >= n_new_methods) {
  2627. + // reached the end without a match; so method was deleted
  2628. + method_was = deleted;
  2629. + }
  2630. + }
  2631. + }
  2632. +
  2633. + switch (method_was) {
  2634. + case matched:
  2635. + // methods match, be sure modifiers do too
  2636. + old_flags = (jushort) k_old_method->access_flags().get_flags();
  2637. + new_flags = (jushort) k_new_method->access_flags().get_flags();
  2638. + if ((old_flags ^ new_flags) & ~(JVM_ACC_NATIVE)) {
  2639. + // TODO Can this have any effects? Probably yes on vtables?
  2640. + result = result | Klass::ModifyClass;
  2641. + }
  2642. + {
  2643. + u2 new_num = k_new_method->method_idnum();
  2644. + u2 old_num = k_old_method->method_idnum();
  2645. + if (new_num != old_num) {
  2646. + Method* idnum_owner = new_class->method_with_idnum(old_num);
  2647. + if (idnum_owner != NULL) {
  2648. + // There is already a method assigned this idnum -- switch them
  2649. + idnum_owner->set_method_idnum(new_num);
  2650. + }
  2651. + k_new_method->set_method_idnum(old_num);
  2652. + RC_TRACE(0x00008000,
  2653. + ("swapping idnum of new and old method %d / %d!", new_num, old_num);
  2654. + swap_all_method_annotations(k_old_method->constMethod(), k_new_method->constMethod()));
  2655. + }
  2656. + }
  2657. + RC_TRACE(0x00008000, ("Method matched: new: %s [%d] == old: %s [%d]",
  2658. + k_new_method->name_and_sig_as_C_string(), ni,
  2659. + k_old_method->name_and_sig_as_C_string(), oi));
  2660. + // advance to next pair of methods
  2661. + ++oi;
  2662. + ++ni;
  2663. + break;
  2664. + case added:
  2665. + // method added, see if it is OK
  2666. + new_flags = (jushort) k_new_method->access_flags().get_flags();
  2667. + if ((new_flags & JVM_ACC_PRIVATE) == 0
  2668. + // hack: private should be treated as final, but alas
  2669. + || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0) {
  2670. + // new methods must be private
  2671. + result = result | Klass::ModifyClass;
  2672. + }
  2673. + {
  2674. + u2 num = the_class->next_method_idnum();
  2675. + if (num == ConstMethod::UNSET_IDNUM) {
  2676. + // cannot add any more methods
  2677. + result = result | Klass::ModifyClass;
  2678. + }
  2679. + u2 new_num = k_new_method->method_idnum();
  2680. + Method* idnum_owner = new_class->method_with_idnum(num);
  2681. + if (idnum_owner != NULL) {
  2682. + // There is already a method assigned this idnum -- switch them
  2683. + idnum_owner->set_method_idnum(new_num);
  2684. + }
  2685. + k_new_method->set_method_idnum(num);
  2686. + swap_all_method_annotations(k_old_method->constMethod(), k_new_method->constMethod());
  2687. + }
  2688. + RC_TRACE(0x00008000, ("Method added: new: %s [%d]",
  2689. + k_new_method->name_and_sig_as_C_string(), ni));
  2690. + ++ni; // advance to next new method
  2691. + break;
  2692. + case deleted:
  2693. + // method deleted, see if it is OK
  2694. + old_flags = (jushort) k_old_method->access_flags().get_flags();
  2695. + if ((old_flags & JVM_ACC_PRIVATE) == 0
  2696. + // hack: private should be treated as final, but alas
  2697. + || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  2698. + ) {
  2699. + // deleted methods must be private
  2700. + result = result | Klass::ModifyClass;
  2701. + }
  2702. + RC_TRACE(0x00008000, ("Method deleted: old: %s [%d]",
  2703. + k_old_method->name_and_sig_as_C_string(), oi));
  2704. + ++oi; // advance to next old method
  2705. + break;
  2706. + default:
  2707. + ShouldNotReachHere();
  2708. + }
  2709. + }
  2710. +
  2711. + if (new_class()->size() != new_class->old_version()->size()) {
  2712. + result |= Klass::ModifyClassSize;
  2713. + }
  2714. +
  2715. + if (new_class->size_helper() != ((InstanceKlass*)(new_class->old_version()))->size_helper()) {
  2716. + result |= Klass::ModifyInstanceSize;
  2717. + }
  2718. +
  2719. + // TODO Check method bodies to be able to return NoChange?
  2720. + return result;
  2721. +}
  2722. +
  2723. +void VM_EnhancedRedefineClasses::calculate_instance_update_information(Klass* new_version) {
  2724. +
  2725. + class CalculateFieldUpdates : public FieldClosure {
  2726. +
  2727. + private:
  2728. + InstanceKlass* _old_ik;
  2729. + GrowableArray<int> _update_info;
  2730. + int _position;
  2731. + bool _copy_backwards;
  2732. +
  2733. + public:
  2734. +
  2735. + bool does_copy_backwards() {
  2736. + return _copy_backwards;
  2737. + }
  2738. +
  2739. + CalculateFieldUpdates(InstanceKlass* old_ik) :
  2740. + _old_ik(old_ik), _position(instanceOopDesc::base_offset_in_bytes()), _copy_backwards(false) {
  2741. + _update_info.append(_position);
  2742. + _update_info.append(0);
  2743. + }
  2744. +
  2745. + GrowableArray<int> &finish() {
  2746. + _update_info.append(0);
  2747. + return _update_info;
  2748. + }
  2749. +
  2750. + void do_field(fieldDescriptor* fd) {
  2751. + int alignment = fd->offset() - _position;
  2752. + if (alignment > 0) {
  2753. + // This field was aligned, so we need to make sure that we fill the gap
  2754. + fill(alignment);
  2755. + }
  2756. +
  2757. + assert(_position == fd->offset(), "must be correct offset!");
  2758. +
  2759. + fieldDescriptor old_fd;
  2760. + if (_old_ik->find_field(fd->name(), fd->signature(), false, &old_fd) != NULL) {
  2761. + // Found field in the old class, copy
  2762. + copy(old_fd.offset(), type2aelembytes(fd->field_type()));
  2763. +
  2764. + if (old_fd.offset() < fd->offset()) {
  2765. + _copy_backwards = true;
  2766. + }
  2767. +
  2768. + // Transfer special flags
  2769. + fd->set_is_field_modification_watched(old_fd.is_field_modification_watched());
  2770. + fd->set_is_field_access_watched(old_fd.is_field_access_watched());
  2771. + } else {
  2772. + // New field, fill
  2773. + fill(type2aelembytes(fd->field_type()));
  2774. + }
  2775. + }
  2776. +
  2777. + private:
  2778. +
  2779. + void fill(int size) {
  2780. + if (_update_info.length() > 0 && _update_info.at(_update_info.length() - 1) < 0) {
  2781. + (*_update_info.adr_at(_update_info.length() - 1)) -= size;
  2782. + } else {
  2783. + _update_info.append(-size);
  2784. + }
  2785. + _position += size;
  2786. + }
  2787. +
  2788. + void copy(int offset, int size) {
  2789. + int prev_end = -1;
  2790. + if (_update_info.length() > 0 && _update_info.at(_update_info.length() - 1) > 0) {
  2791. + prev_end = _update_info.at(_update_info.length() - 2) + _update_info.at(_update_info.length() - 1);
  2792. + }
  2793. +
  2794. + if (prev_end == offset) {
  2795. + (*_update_info.adr_at(_update_info.length() - 2)) += size;
  2796. + } else {
  2797. + _update_info.append(size);
  2798. + _update_info.append(offset);
  2799. + }
  2800. +
  2801. + _position += size;
  2802. + }
  2803. + };
  2804. +
  2805. + InstanceKlass* ik = InstanceKlass::cast(new_version);
  2806. + InstanceKlass* old_ik = InstanceKlass::cast(new_version->old_version());
  2807. + CalculateFieldUpdates cl(old_ik);
  2808. + ik->do_nonstatic_fields(&cl);
  2809. +
  2810. + GrowableArray<int> result = cl.finish();
  2811. + ik->store_update_information(result);
  2812. + ik->set_copying_backwards(cl.does_copy_backwards());
  2813. +
  2814. +
  2815. + if (RC_TRACE_ENABLED(0x00000001)) {
  2816. + RC_TRACE(0x00000001, ("Instance update information for %s:", new_version->name()->as_C_string()));
  2817. + if (cl.does_copy_backwards()) {
  2818. + RC_TRACE(0x00000001, ("\tDoes copy backwards!"));
  2819. + }
  2820. + for (int i=0; i<result.length(); i++) {
  2821. + int curNum = result.at(i);
  2822. + if (curNum < 0) {
  2823. + RC_TRACE(0x00000001, ("\t%d CLEAN", curNum));
  2824. + } else if (curNum > 0) {
  2825. + RC_TRACE(0x00000001, ("\t%d COPY from %d", curNum, result.at(i + 1)));
  2826. + i++;
  2827. + } else {
  2828. + RC_TRACE(0x00000001, ("\tEND"));
  2829. + }
  2830. + }
  2831. + }
  2832. +}
  2833. +
  2834. +void VM_EnhancedRedefineClasses::rollback() {
  2835. + RC_TRACE(0x00000001, ("Rolling back redefinition!"));
  2836. + SystemDictionary::rollback_redefinition();
  2837. +
  2838. + for (int i=0; i<_new_classes->length(); i++) {
  2839. + SystemDictionary::remove_from_hierarchy(_new_classes->at(i));
  2840. + }
  2841. +
  2842. + for (int i=0; i<_new_classes->length(); i++) {
  2843. + instanceKlassHandle new_class = _new_classes->at(i);
  2844. + new_class->set_redefining(false);
  2845. + new_class->old_version()->set_new_version(NULL);
  2846. + new_class->set_old_version(NULL);
  2847. + }
  2848. +
  2849. +}
  2850. +
  2851. +void VM_EnhancedRedefineClasses::swap_marks(oop first, oop second) {
  2852. + markOop first_mark = first->mark();
  2853. + markOop second_mark = second->mark();
  2854. + first->set_mark(second_mark);
  2855. + second->set_mark(first_mark);
  2856. +}
  2857. +
  2858. +class FieldCopier : public FieldClosure {
  2859. + public:
  2860. + void do_field(fieldDescriptor* fd) {
  2861. + InstanceKlass* cur = InstanceKlass::cast(fd->field_holder());
  2862. + oop cur_oop = cur->java_mirror();
  2863. +
  2864. + InstanceKlass* old = InstanceKlass::cast(cur->old_version());
  2865. + oop old_oop = old->java_mirror();
  2866. +
  2867. + fieldDescriptor result;
  2868. + bool found = old->find_local_field(fd->name(), fd->signature(), &result);
  2869. + if (found && result.is_static()) {
  2870. + RC_TRACE(0x00000001, ("Copying static field value for field %s old_offset=%d new_offset=%d",
  2871. + fd->name()->as_C_string(), result.offset(), fd->offset()));
  2872. + memcpy(cur_oop->obj_field_addr<HeapWord>(fd->offset()),
  2873. + old_oop->obj_field_addr<HeapWord>(result.offset()),
  2874. + type2aelembytes(fd->field_type()));
  2875. +
  2876. + // Static fields may have references to java.lang.Class
  2877. + if (fd->field_type() == T_OBJECT) {
  2878. + oop oop = cur_oop->obj_field(fd->offset());
  2879. + if (oop != NULL && oop->is_instanceMirror()) {
  2880. + Klass* klass = java_lang_Class::as_Klass(oop);
  2881. + if (klass != NULL && klass->oop_is_instance()) {
  2882. + assert(oop == InstanceKlass::cast(klass)->java_mirror(), "just checking");
  2883. + if (klass->new_version() != NULL) {
  2884. + oop = InstanceKlass::cast(klass->new_version())->java_mirror();
  2885. + cur_oop->obj_field_put(fd->offset(), oop);
  2886. + }
  2887. + }
  2888. + }
  2889. + }
  2890. + }
  2891. + }
  2892. +};
  2893. +
  2894. +void VM_EnhancedRedefineClasses::mark_as_scavengable(nmethod* nm) {
  2895. + if (!nm->on_scavenge_root_list()) {
  2896. + CodeCache::add_scavenge_root_nmethod(nm);
  2897. + }
  2898. +}
  2899. +
  2900. +struct StoreBarrier {
  2901. + template <class T> static void oop_store(T* p, oop v) { ::oop_store(p, v); }
  2902. +};
  2903. +
  2904. +struct StoreNoBarrier {
  2905. + template <class T> static void oop_store(T* p, oop v) { oopDesc::encode_store_heap_oop_not_null(p, v); }
  2906. +};
  2907. +
  2908. +template <class S>
  2909. +class ChangePointersOopClosure : public ExtendedOopClosure {
  2910. + // Forward pointers to InstanceKlass and mirror class to new versions
  2911. + template <class T>
  2912. + inline void do_oop_work(T* p) {
  2913. + oop oop = oopDesc::load_decode_heap_oop(p);
  2914. + if (oop == NULL) {
  2915. + return;
  2916. + }
  2917. + if (oop->is_instanceMirror()) {
  2918. + Klass* klass = java_lang_Class::as_Klass(oop);
  2919. + if (klass != NULL && klass->oop_is_instance()) {
  2920. + assert(oop == InstanceKlass::cast(klass)->java_mirror(), "just checking");
  2921. + if (klass->new_version() != NULL) {
  2922. + oop = InstanceKlass::cast(klass->new_version())->java_mirror();
  2923. + S::oop_store(p, oop);
  2924. + }
  2925. + }
  2926. + }
  2927. + }
  2928. +
  2929. + virtual void do_oop(oop* o) {
  2930. + do_oop_work(o);
  2931. + }
  2932. +
  2933. + virtual void do_oop(narrowOop* o) {
  2934. + do_oop_work(o);
  2935. + }
  2936. +};
  2937. +
  2938. +void VM_EnhancedRedefineClasses::doit() {
  2939. +
  2940. + Thread *thread = Thread::current();
  2941. +
  2942. + assert((_max_redefinition_flags & Klass::RemoveSuperType) == 0, "removing super types not allowed");
  2943. +
  2944. + if (UseSharedSpaces) {
  2945. + // Sharing is enabled so we remap the shared readonly space to
  2946. + // shared readwrite, private just in case we need to redefine
  2947. + // a shared class. We do the remap during the doit() phase of
  2948. + // the safepoint to be safer.
  2949. + if (!MetaspaceShared::remap_shared_readonly_as_readwrite()) {
  2950. + RC_TRACE(0x00000001,
  2951. + ("failed to remap shared readonly space to readwrite, private"));
  2952. + _result = JVMTI_ERROR_INTERNAL;
  2953. + return;
  2954. + }
  2955. + }
  2956. +
  2957. + RC_TIMER_START(_timer_prepare_redefinition);
  2958. + for (int i = 0; i < _new_classes->length(); i++) {
  2959. + redefine_single_class(_new_classes->at(i), thread);
  2960. + }
  2961. +
  2962. + // Deoptimize all compiled code that depends on this class
  2963. + flush_dependent_code(instanceKlassHandle(Thread::current(), (Klass*)NULL), Thread::current());
  2964. +
  2965. + // Adjust constantpool caches and vtables for all classes
  2966. + // that reference methods of the evolved class.
  2967. + SystemDictionary::classes_do(adjust_cpool_cache, Thread::current());
  2968. +
  2969. + RC_TIMER_STOP(_timer_prepare_redefinition);
  2970. + RC_TIMER_START(_timer_heap_iteration);
  2971. +
  2972. + class ChangePointersObjectClosure : public ObjectClosure {
  2973. +
  2974. + private:
  2975. +
  2976. + OopClosure *_closure;
  2977. + bool _needs_instance_update;
  2978. + oop _tmp_obj;
  2979. + int _tmp_obj_size;
  2980. +
  2981. + public:
  2982. + ChangePointersObjectClosure(OopClosure *closure) : _closure(closure), _needs_instance_update(false), _tmp_obj(NULL), _tmp_obj_size(0) {}
  2983. +
  2984. + bool needs_instance_update() {
  2985. + return _needs_instance_update;
  2986. + }
  2987. +
  2988. + void copy_to_tmp(oop o) {
  2989. + int size = o->size();
  2990. + if (_tmp_obj_size < size) {
  2991. + _tmp_obj_size = size;
  2992. + _tmp_obj = (oop)resource_allocate_bytes(size * HeapWordSize);
  2993. + }
  2994. + Copy::aligned_disjoint_words((HeapWord*)o, (HeapWord*)_tmp_obj, size);
  2995. + }
  2996. +
  2997. + virtual void do_object(oop obj) {
  2998. + // FIXME: if (obj->is_instanceKlass()) return;
  2999. + if (obj->is_instanceMirror()) {
  3000. + // static fields may have references to old java.lang.Class instances, update them
  3001. + // at the same time, we don't want to update other oops in the java.lang.Class
  3002. + // Causes SIGSEGV?
  3003. + //instanceMirrorKlass::oop_fields_iterate(obj, _closure);
  3004. + } else {
  3005. + obj->oop_iterate_no_header(_closure);
  3006. + }
  3007. +
  3008. + if (obj->klass()->new_version() != NULL) {
  3009. + Klass* new_klass = obj->klass()->new_version();
  3010. + /* FIXME: if (obj->is_perm()) {
  3011. + _needs_instance_update = true;
  3012. + } else */if(new_klass->update_information() != NULL) {
  3013. + int size_diff = obj->size() - obj->size_given_klass(new_klass);
  3014. +
  3015. + // Either new size is bigger or gap is to small to be filled
  3016. + if (size_diff < 0 || (size_diff > 0 && (size_t) size_diff < CollectedHeap::min_fill_size())) {
  3017. + // We need an instance update => set back to old klass
  3018. + _needs_instance_update = true;
  3019. + } else {
  3020. + oop src = obj;
  3021. + if (new_klass->is_copying_backwards()) {
  3022. + copy_to_tmp(obj);
  3023. + src = _tmp_obj;
  3024. + }
  3025. + src->set_klass(obj->klass()->new_version());
  3026. + MarkSweep::update_fields(obj, src, new_klass->update_information());
  3027. +
  3028. + if (size_diff > 0) {
  3029. + HeapWord* dead_space = ((HeapWord *)obj) + obj->size();
  3030. + CollectedHeap::fill_with_object(dead_space, size_diff);
  3031. + }
  3032. + }
  3033. + } else {
  3034. + obj->set_klass(obj->klass()->new_version());
  3035. + }
  3036. + }
  3037. + }
  3038. + };
  3039. +
  3040. + ChangePointersOopClosure<StoreNoBarrier> oopClosureNoBarrier;
  3041. + ChangePointersOopClosure<StoreBarrier> oopClosure;
  3042. + ChangePointersObjectClosure objectClosure(&oopClosure);
  3043. +
  3044. + RC_TRACE(0x00000001, ("Before updating instances"));
  3045. + {
  3046. + // Since we may update oops inside nmethod's code blob to point to java.lang.Class in new generation, we need to
  3047. + // make sure such references are properly recognized by GC. For that, If ScavengeRootsInCode is true, we need to
  3048. + // mark such nmethod's as "scavengable".
  3049. + // For now, mark all nmethod's as scavengable that are not scavengable already
  3050. + if (ScavengeRootsInCode) {
  3051. + CodeCache::nmethods_do(mark_as_scavengable);
  3052. + }
  3053. +
  3054. + SharedHeap::heap()->gc_prologue(true);
  3055. + Universe::heap()->object_iterate(&objectClosure);
  3056. + Universe::root_oops_do(&oopClosureNoBarrier);
  3057. + SharedHeap::heap()->gc_epilogue(false);
  3058. + }
  3059. + RC_TRACE(0x00000001, ("After updating instances"));
  3060. +
  3061. + for (int i = 0; i < _new_classes->length(); i++) {
  3062. + InstanceKlass* cur = InstanceKlass::cast(_new_classes->at(i)());
  3063. + InstanceKlass* old = InstanceKlass::cast(cur->old_version());
  3064. +
  3065. + // Swap marks to have same hashcodes
  3066. + markOop cur_mark = cur->prototype_header();
  3067. + markOop old_mark = old->prototype_header();
  3068. + cur->set_prototype_header(old_mark);
  3069. + old->set_prototype_header(cur_mark);
  3070. +
  3071. + //swap_marks(cur, old);
  3072. + swap_marks(cur->java_mirror(), old->java_mirror());
  3073. +
  3074. + // Revert pool holder for old version of klass (it was updated by one of ours closure!)
  3075. + old->constants()->set_pool_holder(old);
  3076. +
  3077. + Klass* array_klasses = old->array_klasses();
  3078. + if (array_klasses != NULL) {
  3079. + assert(cur->array_klasses() == NULL, "just checking");
  3080. +
  3081. + // Transfer the array classes, otherwise we might get cast exceptions when casting array types.
  3082. + // Also, set array klasses element klass.
  3083. + cur->set_array_klasses(array_klasses);
  3084. + ObjArrayKlass::cast(array_klasses)->set_element_klass(cur);
  3085. + }
  3086. +
  3087. + // Initialize the new class! Special static initialization that does not execute the
  3088. + // static constructor but copies static field values from the old class if name
  3089. + // and signature of a static field match.
  3090. + FieldCopier copier;
  3091. + cur->do_local_static_fields(&copier); // TODO (tw): What about internal static fields??
  3092. + //java_lang_Class::set_klass(old->java_mirror(), cur); // FIXME-isd: is that correct?
  3093. + //FIXME-isd: do we need this: ??? old->set_java_mirror(cur->java_mirror());
  3094. +
  3095. + // Transfer init state
  3096. + InstanceKlass::ClassState state = old->init_state();
  3097. + if (state > InstanceKlass::linked) {
  3098. + cur->set_init_state(state);
  3099. + }
  3100. + }
  3101. +
  3102. + RC_TIMER_STOP(_timer_heap_iteration);
  3103. + RC_TIMER_START(_timer_redefinition);
  3104. + if (objectClosure.needs_instance_update()) {
  3105. + // Do a full garbage collection to update the instance sizes accordingly
  3106. + RC_TRACE(0x00000001, ("Before performing full GC!"));
  3107. + Universe::set_redefining_gc_run(true);
  3108. + notify_gc_begin(true);
  3109. + Universe::heap()->collect_as_vm_thread(GCCause::_heap_inspection);
  3110. + notify_gc_end();
  3111. + Universe::set_redefining_gc_run(false);
  3112. + RC_TRACE(0x00000001, ("GC done!"));
  3113. + }
  3114. +
  3115. + // Unmark Klass*s as "redefining"
  3116. + for (int i=0; i<_new_classes->length(); i++) {
  3117. + Klass* cur_klass = _new_classes->at(i)();
  3118. + InstanceKlass* cur = (InstanceKlass*)cur_klass;
  3119. + cur->set_redefining(false);
  3120. + cur->clear_update_information();
  3121. + }
  3122. +
  3123. + // Disable any dependent concurrent compilations
  3124. + SystemDictionary::notice_modification();
  3125. +
  3126. + // Set flag indicating that some invariants are no longer true.
  3127. + // See jvmtiExport.hpp for detailed explanation.
  3128. + JvmtiExport::set_has_redefined_a_class();
  3129. +
  3130. + // Clean up caches in the compiler interface and compiler threads
  3131. + ciObjectFactory::resort_shared_ci_metadata();
  3132. +
  3133. +#ifdef ASSERT
  3134. +
  3135. + // Universe::verify();
  3136. + // JNIHandles::verify();
  3137. +
  3138. + SystemDictionary::classes_do(check_class, thread);
  3139. +#endif
  3140. +
  3141. + RC_TIMER_STOP(_timer_redefinition);
  3142. +
  3143. + if (TraceRedefineClasses > 0) {
  3144. + tty->flush();
  3145. + }
  3146. +}
  3147. +
  3148. +void VM_EnhancedRedefineClasses::doit_epilogue() {
  3149. +
  3150. + RC_TIMER_START(_timer_vm_op_epilogue);
  3151. +
  3152. + ResourceMark mark;
  3153. +
  3154. + VM_GC_Operation::doit_epilogue();
  3155. + RC_TRACE(0x00000001, ("GC Operation epilogue finished!"));
  3156. +
  3157. + // Free the array of scratch classes
  3158. + delete _new_classes;
  3159. + _new_classes = NULL;
  3160. +
  3161. + // Free the array of affected classes
  3162. + delete _affected_klasses;
  3163. + _affected_klasses = NULL;
  3164. +
  3165. + RC_TRACE(0x00000001, ("Redefinition finished!"));
  3166. +
  3167. + RC_TIMER_STOP(_timer_vm_op_epilogue);
  3168. +}
  3169. +
  3170. +bool VM_EnhancedRedefineClasses::is_modifiable_class(oop klass_mirror) {
  3171. + // classes for primitives cannot be redefined
  3172. + if (java_lang_Class::is_primitive(klass_mirror)) {
  3173. + return false;
  3174. + }
  3175. + Klass* klass = java_lang_Class::as_Klass(klass_mirror);
  3176. + // classes for arrays cannot be redefined
  3177. + if (klass == NULL || !klass->oop_is_instance()) {
  3178. + return false;
  3179. + }
  3180. + return true;
  3181. +}
  3182. +
  3183. +#ifdef ASSERT
  3184. +
  3185. +void VM_EnhancedRedefineClasses::verify_classes(Klass* k_oop_latest, oop initiating_loader, TRAPS) {
  3186. + Klass* k_oop = k_oop_latest;
  3187. + while (k_oop != NULL) {
  3188. +
  3189. + instanceKlassHandle k_handle(THREAD, k_oop);
  3190. + Verifier::verify(k_handle, Verifier::ThrowException, true, THREAD);
  3191. + k_oop = k_oop->old_version();
  3192. + }
  3193. +}
  3194. +
  3195. +#endif
  3196. +
  3197. +// Rewrite faster byte-codes back to their slower equivalent. Undoes rewriting happening in templateTable_xxx.cpp
  3198. +// The reason is that once we zero cpool caches, we need to re-resolve all entries again. Faster bytecodes do not
  3199. +// do that, they assume that cache entry is resolved already.
  3200. +void VM_EnhancedRedefineClasses::unpatch_bytecode(Method* method) {
  3201. + RawBytecodeStream bcs(method);
  3202. + Bytecodes::Code code;
  3203. + Bytecodes::Code java_code;
  3204. + while (!bcs.is_last_bytecode()) {
  3205. + code = bcs.raw_next();
  3206. + address bcp = bcs.bcp();
  3207. +
  3208. + if (code == Bytecodes::_breakpoint) {
  3209. + int bci = method->bci_from(bcp);
  3210. + code = method->orig_bytecode_at(bci);
  3211. + java_code = Bytecodes::java_code(code);
  3212. + if (code != java_code &&
  3213. + (java_code == Bytecodes::_getfield ||
  3214. + java_code == Bytecodes::_putfield ||
  3215. + java_code == Bytecodes::_aload_0)) {
  3216. + // Let breakpoint table handling unpatch bytecode
  3217. + method->set_orig_bytecode_at(bci, java_code);
  3218. + }
  3219. + } else {
  3220. + java_code = Bytecodes::java_code(code);
  3221. + if (code != java_code &&
  3222. + (java_code == Bytecodes::_getfield ||
  3223. + java_code == Bytecodes::_putfield ||
  3224. + java_code == Bytecodes::_aload_0)) {
  3225. + *bcp = java_code;
  3226. + }
  3227. + }
  3228. +
  3229. + // Additionally, we need to unpatch bytecode at bcp+1 for fast_xaccess (which would be fast field access)
  3230. + if (code == Bytecodes::_fast_iaccess_0 || code == Bytecodes::_fast_aaccess_0 || code == Bytecodes::_fast_faccess_0) {
  3231. + Bytecodes::Code code2 = Bytecodes::code_or_bp_at(bcp + 1);
  3232. + assert(code2 == Bytecodes::_fast_igetfield ||
  3233. + code2 == Bytecodes::_fast_agetfield ||
  3234. + code2 == Bytecodes::_fast_fgetfield, "");
  3235. + *(bcp + 1) = Bytecodes::java_code(code2);
  3236. + }
  3237. + }
  3238. + }
  3239. +
  3240. +// Unevolving classes may point to old methods directly
  3241. +// from their constant pool caches, itables, and/or vtables. We
  3242. +// use the SystemDictionary::classes_do() facility and this helper
  3243. +// to fix up these pointers. Additional field offsets and vtable indices
  3244. +// in the constant pool cache entries are fixed.
  3245. +//
  3246. +// Note: We currently don't support updating the vtable in
  3247. +// arrayKlassOops. See Open Issues in jvmtiRedefineClasses.hpp.
  3248. +void VM_EnhancedRedefineClasses::adjust_cpool_cache(Klass* klass_latest, TRAPS) {
  3249. + Klass* k = klass_latest;
  3250. + while (k != NULL) {
  3251. + if (k->oop_is_instance()) {
  3252. + HandleMark hm(THREAD);
  3253. + InstanceKlass *ik = InstanceKlass::cast(k);
  3254. +
  3255. + constantPoolHandle other_cp;
  3256. + ConstantPoolCache* cp_cache;
  3257. + other_cp = constantPoolHandle(ik->constants());
  3258. +
  3259. + for (int i = 0; i < other_cp->length(); i++) {
  3260. + if (other_cp->tag_at(i).is_klass()) {
  3261. + Klass* klass = other_cp->klass_at(i, THREAD);
  3262. + if (klass->new_version() != NULL) {
  3263. + // (DCEVM) TODO: check why/if this is necessary
  3264. + other_cp->klass_at_put(i, klass->new_version());
  3265. + }
  3266. + klass = other_cp->klass_at(i, THREAD);
  3267. + assert(klass->new_version() == NULL, "Must be new klass!");
  3268. + }
  3269. + }
  3270. +
  3271. + cp_cache = other_cp->cache();
  3272. +
  3273. + if (cp_cache != NULL) {
  3274. + cp_cache->clear_entries();
  3275. + }
  3276. +
  3277. + // If bytecode rewriting is enabled, we also need to unpatch bytecode to force resolution of zeroed entries
  3278. + if (RewriteBytecodes) {
  3279. + ik->methods_do(unpatch_bytecode);
  3280. + }
  3281. + }
  3282. + k = k->old_version();
  3283. + }
  3284. +}
  3285. +
  3286. +void VM_EnhancedRedefineClasses::update_jmethod_ids() {
  3287. + for (int j = 0; j < _matching_methods_length; ++j) {
  3288. + Method* old_method = _old_methods->at(_matching_old_methods[j]);
  3289. + jmethodID jmid = old_method->find_jmethod_id_or_null();
  3290. + RC_TRACE(0x00008000, ("matching method %s, jmid %d", old_method->name_and_sig_as_C_string(), jmid));
  3291. + if (old_method->new_version() != NULL && jmid == NULL) {
  3292. + // (DCEVM) Have to create jmethodID in this case
  3293. + jmid = old_method->jmethod_id();
  3294. + }
  3295. +
  3296. + if (jmid != NULL) {
  3297. + // There is a jmethodID, change it to point to the new method
  3298. + methodHandle new_method_h(_new_methods->at(_matching_new_methods[j]));
  3299. + if (old_method->new_version() == NULL) {
  3300. + methodHandle old_method_h(_old_methods->at(_matching_old_methods[j]));
  3301. + jmethodID new_jmethod_id = Method::make_jmethod_id(old_method_h->method_holder()->class_loader_data(), old_method_h());
  3302. + bool result = InstanceKlass::cast(old_method_h->method_holder())->update_jmethod_id(old_method_h(), new_jmethod_id);
  3303. + } else {
  3304. + jmethodID mid = new_method_h->jmethod_id();
  3305. + bool result = InstanceKlass::cast(new_method_h->method_holder())->update_jmethod_id(new_method_h(), jmid);
  3306. + }
  3307. + Method::change_method_associated_with_jmethod_id(jmid, new_method_h());
  3308. + assert(Method::resolve_jmethod_id(jmid) == _new_methods->at(_matching_new_methods[j]), "should be replaced");
  3309. + jmethodID mid = (_new_methods->at(_matching_new_methods[j]))->jmethod_id();
  3310. + //assert(JNIHandles::resolve_non_null((jobject)mid) == new_method_h(), "must match!");
  3311. + }
  3312. + }
  3313. +}
  3314. +
  3315. +
  3316. +// Deoptimize all compiled code that depends on this class.
  3317. +//
  3318. +// If the can_redefine_classes capability is obtained in the onload
  3319. +// phase then the compiler has recorded all dependencies from startup.
  3320. +// In that case we need only deoptimize and throw away all compiled code
  3321. +// that depends on the class.
  3322. +//
  3323. +// If can_redefine_classes is obtained sometime after the onload
  3324. +// phase then the dependency information may be incomplete. In that case
  3325. +// the first call to RedefineClasses causes all compiled code to be
  3326. +// thrown away. As can_redefine_classes has been obtained then
  3327. +// all future compilations will record dependencies so second and
  3328. +// subsequent calls to RedefineClasses need only throw away code
  3329. +// that depends on the class.
  3330. +//
  3331. +void VM_EnhancedRedefineClasses::flush_dependent_code(instanceKlassHandle k_h, TRAPS) {
  3332. + assert_locked_or_safepoint(Compile_lock);
  3333. +
  3334. + // All dependencies have been recorded from startup or this is a second or
  3335. + // subsequent use of RedefineClasses
  3336. +
  3337. + // For now deopt all
  3338. + // (tw) TODO: Improve the dependency system such that we can safely deopt only a subset of the methods
  3339. + if (0 && JvmtiExport::all_dependencies_are_recorded()) {
  3340. + Universe::flush_evol_dependents_on(k_h);
  3341. + } else {
  3342. + CodeCache::mark_all_nmethods_for_deoptimization();
  3343. +
  3344. + ResourceMark rm(THREAD);
  3345. + DeoptimizationMarker dm;
  3346. +
  3347. + // Deoptimize all activations depending on marked nmethods
  3348. + Deoptimization::deoptimize_dependents();
  3349. +
  3350. + // Make the dependent methods not entrant (in VM_Deoptimize they are made zombies)
  3351. + CodeCache::make_marked_nmethods_not_entrant();
  3352. +
  3353. + // From now on we know that the dependency information is complete
  3354. + JvmtiExport::set_all_dependencies_are_recorded(true);
  3355. + }
  3356. + }
  3357. +
  3358. +void VM_EnhancedRedefineClasses::compute_added_deleted_matching_methods() {
  3359. + Method* old_method;
  3360. + Method* new_method;
  3361. +
  3362. + _matching_old_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  3363. + _matching_new_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  3364. + _added_methods = NEW_RESOURCE_ARRAY(int, _new_methods->length());
  3365. + _deleted_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  3366. +
  3367. + _matching_methods_length = 0;
  3368. + _deleted_methods_length = 0;
  3369. + _added_methods_length = 0;
  3370. +
  3371. + int nj = 0;
  3372. + int oj = 0;
  3373. + while (true) {
  3374. + if (oj >= _old_methods->length()) {
  3375. + if (nj >= _new_methods->length()) {
  3376. + break; // we've looked at everything, done
  3377. + }
  3378. + // New method at the end
  3379. + new_method = _new_methods->at(nj);
  3380. + _added_methods[_added_methods_length++] = nj;
  3381. + ++nj;
  3382. + } else if (nj >= _new_methods->length()) {
  3383. + // Old method, at the end, is deleted
  3384. + old_method = _old_methods->at(oj);
  3385. + _deleted_methods[_deleted_methods_length++] = oj;
  3386. + ++oj;
  3387. + } else {
  3388. + old_method = _old_methods->at(oj);
  3389. + new_method = _new_methods->at(nj);
  3390. + if (old_method->name() == new_method->name()) {
  3391. + if (old_method->signature() == new_method->signature()) {
  3392. + _matching_old_methods[_matching_methods_length] = oj;//old_method;
  3393. + _matching_new_methods[_matching_methods_length] = nj;//new_method;
  3394. + _matching_methods_length++;
  3395. + ++nj;
  3396. + ++oj;
  3397. + } else {
  3398. + // added overloaded have already been moved to the end,
  3399. + // so this is a deleted overloaded method
  3400. + _deleted_methods[_deleted_methods_length++] = oj;//old_method;
  3401. + ++oj;
  3402. + }
  3403. + } else { // names don't match
  3404. + if (old_method->name()->fast_compare(new_method->name()) > 0) {
  3405. + // new method
  3406. + _added_methods[_added_methods_length++] = nj;//new_method;
  3407. + ++nj;
  3408. + } else {
  3409. + // deleted method
  3410. + _deleted_methods[_deleted_methods_length++] = oj;//old_method;
  3411. + ++oj;
  3412. + }
  3413. + }
  3414. + }
  3415. + }
  3416. + assert(_matching_methods_length + _deleted_methods_length == _old_methods->length(), "sanity");
  3417. + assert(_matching_methods_length + _added_methods_length == _new_methods->length(), "sanity");
  3418. + RC_TRACE(0x00008000, ("Matching methods = %d / deleted methods = %d / added methods = %d",
  3419. + _matching_methods_length, _deleted_methods_length, _added_methods_length));
  3420. +}
  3421. +
  3422. +
  3423. +
  3424. +// Install the redefinition of a class:
  3425. +// - house keeping (flushing breakpoints and caches, deoptimizing
  3426. +// dependent compiled code)
  3427. +// - adjusting constant pool caches and vtables in other classes
  3428. +void VM_EnhancedRedefineClasses::redefine_single_class(instanceKlassHandle the_new_class, TRAPS) {
  3429. +
  3430. + ResourceMark rm(THREAD);
  3431. +
  3432. + assert(the_new_class->old_version() != NULL, "Must not be null");
  3433. + assert(the_new_class->old_version()->new_version() == the_new_class(), "Must equal");
  3434. +
  3435. + instanceKlassHandle the_old_class = instanceKlassHandle(THREAD, the_new_class->old_version());
  3436. +
  3437. +#ifndef JVMTI_KERNEL
  3438. + // Remove all breakpoints in methods of this class
  3439. + JvmtiBreakpoints& jvmti_breakpoints = JvmtiCurrentBreakpoints::get_jvmti_breakpoints();
  3440. + jvmti_breakpoints.clearall_in_class_at_safepoint(the_old_class());
  3441. +#endif // !JVMTI_KERNEL
  3442. +
  3443. + /* FIXME
  3444. + if (the_old_class() == Universe::reflect_invoke_cache()->klass()) {
  3445. + // We are redefining java.lang.reflect.Method. Method.invoke() is
  3446. + // cached and users of the cache care about each active version of
  3447. + // the method so we have to track this previous version.
  3448. + // Do this before methods get switched
  3449. + Universe::reflect_invoke_cache()->add_previous_version(
  3450. + the_old_class->method_with_idnum(Universe::reflect_invoke_cache()->method_idnum()));
  3451. + }*/
  3452. +
  3453. + _old_methods = the_old_class->methods();
  3454. + _new_methods = the_new_class->methods();
  3455. + compute_added_deleted_matching_methods();
  3456. +
  3457. + // track which methods are EMCP for add_previous_version() call below
  3458. +
  3459. + // TODO: Check if we need the concept of EMCP?
  3460. + BitMap emcp_methods(_old_methods->length());
  3461. + int emcp_method_count = 0;
  3462. + emcp_methods.clear(); // clears 0..(length() - 1)
  3463. +
  3464. + // We need to mark methods as old!!
  3465. + check_methods_and_mark_as_obsolete(&emcp_methods, &emcp_method_count);
  3466. + update_jmethod_ids();
  3467. +
  3468. + // TODO:
  3469. + transfer_old_native_function_registrations(the_old_class);
  3470. +
  3471. +
  3472. + // JSR-292 support
  3473. +
  3474. + // Transfer method handles
  3475. + MemberNameTable* mnt = the_old_class->member_names();
  3476. + the_new_class->set_member_names(mnt);
  3477. + the_old_class->set_member_names(NULL);
  3478. + if (mnt != NULL) {
  3479. + for (int i = 0; i < mnt->length(); i++) {
  3480. + oop mem_name = mnt->get_member_name(i);
  3481. + if (mem_name != NULL) {
  3482. + Method* method = (Method*) java_lang_invoke_MemberName::vmtarget(mem_name);
  3483. +
  3484. + // Replace the method with matching one from the new class
  3485. + Method* new_method = the_new_class->find_method(method->name(), method->signature());
  3486. + java_lang_invoke_MemberName::set_vmtarget(mem_name, new_method);
  3487. + }
  3488. + }
  3489. + }
  3490. +
  3491. +
  3492. +#ifdef ASSERT
  3493. +
  3494. +// Klass* systemLookup1 = SystemDictionary::resolve_or_null(the_old_class->name(), the_old_class->class_loader(), the_old_class->protection_domain(), THREAD);
  3495. +// assert(systemLookup1 == the_new_class(), "New class must be in system dictionary!");
  3496. +
  3497. + //JNIHandles::verify();
  3498. +
  3499. +// Klass* systemLookup = SystemDictionary::resolve_or_null(the_old_class->name(), the_old_class->class_loader(), the_old_class->protection_domain(), THREAD);
  3500. +
  3501. +// assert(systemLookup == the_new_class(), "New class must be in system dictionary!");
  3502. + assert(the_new_class->old_version() != NULL, "Must not be null");
  3503. + assert(the_new_class->old_version()->new_version() == the_new_class(), "Must equal");
  3504. +
  3505. + for (int i=0; i<the_new_class->methods()->length(); i++) {
  3506. + assert((the_new_class->methods()->at(i))->method_holder() == the_new_class(), "method holder must match!");
  3507. + }
  3508. +
  3509. + // FIXME:
  3510. + //_old_methods->verify();
  3511. + //_new_methods->verify();
  3512. +
  3513. + the_new_class->vtable()->verify(tty);
  3514. + the_old_class->vtable()->verify(tty);
  3515. +
  3516. +#endif
  3517. +
  3518. + // increment the classRedefinedCount field in the_class and in any
  3519. + // direct and indirect subclasses of the_class
  3520. + increment_class_counter((InstanceKlass *)the_old_class(), THREAD);
  3521. +
  3522. +}
  3523. +
  3524. +
  3525. +void VM_EnhancedRedefineClasses::check_methods_and_mark_as_obsolete(BitMap *emcp_methods, int * emcp_method_count_p) {
  3526. + RC_TRACE(0x00000100, ("Checking matching methods for EMCP"));
  3527. + *emcp_method_count_p = 0;
  3528. + int obsolete_count = 0;
  3529. + int old_index = 0;
  3530. + for (int j = 0; j < _matching_methods_length; ++j, ++old_index) {
  3531. + Method* old_method = _old_methods->at(_matching_old_methods[j]);
  3532. + Method* new_method = _new_methods->at(_matching_new_methods[j]);
  3533. + Method* old_array_method;
  3534. +
  3535. + // Maintain an old_index into the _old_methods array by skipping
  3536. + // deleted methods
  3537. + while ((old_array_method = _old_methods->at(old_index)) != old_method) {
  3538. + ++old_index;
  3539. + }
  3540. +
  3541. + if (MethodComparator::methods_EMCP(old_method, new_method)) {
  3542. + // The EMCP definition from JSR-163 requires the bytecodes to be
  3543. + // the same with the exception of constant pool indices which may
  3544. + // differ. However, the constants referred to by those indices
  3545. + // must be the same.
  3546. + //
  3547. + // We use methods_EMCP() for comparison since constant pool
  3548. + // merging can remove duplicate constant pool entries that were
  3549. + // present in the old method and removed from the rewritten new
  3550. + // method. A faster binary comparison function would consider the
  3551. + // old and new methods to be different when they are actually
  3552. + // EMCP.
  3553. +
  3554. + // track which methods are EMCP for add_previous_version() call
  3555. + emcp_methods->set_bit(old_index);
  3556. + (*emcp_method_count_p)++;
  3557. +
  3558. + // An EMCP method is _not_ obsolete. An obsolete method has a
  3559. + // different jmethodID than the current method. An EMCP method
  3560. + // has the same jmethodID as the current method. Having the
  3561. + // same jmethodID for all EMCP versions of a method allows for
  3562. + // a consistent view of the EMCP methods regardless of which
  3563. + // EMCP method you happen to have in hand. For example, a
  3564. + // breakpoint set in one EMCP method will work for all EMCP
  3565. + // versions of the method including the current one.
  3566. +
  3567. + old_method->set_new_version(new_method);
  3568. + new_method->set_old_version(old_method);
  3569. +
  3570. + RC_TRACE(0x00000100, ("Found EMCP method %s", old_method->name_and_sig_as_C_string()));
  3571. +
  3572. + // Transfer breakpoints
  3573. + InstanceKlass *ik = InstanceKlass::cast(old_method->method_holder());
  3574. + for (BreakpointInfo* bp = ik->breakpoints(); bp != NULL; bp = bp->next()) {
  3575. + RC_TRACE(0x00000100, ("Checking breakpoint: %d / %d",
  3576. + bp->match(old_method), bp->match(new_method)));
  3577. + if (bp->match(old_method)) {
  3578. + assert(bp->match(new_method), "if old method is method, then new method must match too");
  3579. + RC_TRACE(0x00000100, ("Found a breakpoint in an old EMCP method"));
  3580. + new_method->set_breakpoint(bp->bci());
  3581. + }
  3582. + }
  3583. + } else {
  3584. + // mark obsolete methods as such
  3585. + old_method->set_is_obsolete();
  3586. + obsolete_count++;
  3587. +
  3588. + // With tracing we try not to "yack" too much. The position of
  3589. + // this trace assumes there are fewer obsolete methods than
  3590. + // EMCP methods.
  3591. + RC_TRACE(0x00000100, ("mark %s(%s) as obsolete",
  3592. + old_method->name()->as_C_string(),
  3593. + old_method->signature()->as_C_string()));
  3594. + }
  3595. + old_method->set_is_old();
  3596. + }
  3597. + for (int i = 0; i < _deleted_methods_length; ++i) {
  3598. + Method* old_method = _old_methods->at(_deleted_methods[i]);
  3599. +
  3600. + //assert(old_method->vtable_index() < 0,
  3601. + // "cannot delete methods with vtable entries");;
  3602. +
  3603. + // Mark all deleted methods as old and obsolete
  3604. + old_method->set_is_old();
  3605. + old_method->set_is_obsolete();
  3606. + ++obsolete_count;
  3607. + // With tracing we try not to "yack" too much. The position of
  3608. + // this trace assumes there are fewer obsolete methods than
  3609. + // EMCP methods.
  3610. + RC_TRACE(0x00000100, ("mark deleted %s(%s) as obsolete",
  3611. + old_method->name()->as_C_string(),
  3612. + old_method->signature()->as_C_string()));
  3613. + }
  3614. + //assert((*emcp_method_count_p + obsolete_count) == _old_methods->length(), "sanity check");
  3615. + RC_TRACE(0x00000100, ("EMCP_cnt=%d, obsolete_cnt=%d !",
  3616. + *emcp_method_count_p, obsolete_count));
  3617. +}
  3618. +
  3619. +// Increment the classRedefinedCount field in the specific InstanceKlass
  3620. +// and in all direct and indirect subclasses.
  3621. +void VM_EnhancedRedefineClasses::increment_class_counter(Klass* klass, TRAPS) {
  3622. + oop class_mirror = klass->java_mirror();
  3623. + int new_count = java_lang_Class::classRedefinedCount(class_mirror) + 1;
  3624. + java_lang_Class::set_classRedefinedCount(class_mirror, new_count);
  3625. + RC_TRACE(0x00000008, ("updated count for class=%s to %d", klass->external_name(), new_count));
  3626. +}
  3627. +
  3628. +#ifndef PRODUCT
  3629. +void VM_EnhancedRedefineClasses::check_class(Klass* k_oop, TRAPS) {
  3630. + Klass *k = k_oop;
  3631. + if (k->oop_is_instance()) {
  3632. + HandleMark hm(THREAD);
  3633. + InstanceKlass *ik = (InstanceKlass *) k;
  3634. + assert(ik->is_newest_version(), "must be latest version in system dictionary");
  3635. +
  3636. + if (ik->vtable_length() > 0) {
  3637. + ResourceMark rm(THREAD);
  3638. + assert(ik->vtable()->check_no_old_or_obsolete_entries(), "old method found");
  3639. + ik->vtable()->verify(tty, true);
  3640. + }
  3641. + }
  3642. +}
  3643. +
  3644. +#endif
  3645. +
  3646. +static bool match_second(void* value, Pair<Klass*, Klass*> elem) {
  3647. + return elem.second == value;
  3648. +}
  3649. +
  3650. +jvmtiError VM_EnhancedRedefineClasses::do_topological_class_sorting( const jvmtiClassDefinition *class_defs, int class_count, TRAPS) {
  3651. + ResourceMark mark(THREAD);
  3652. + GrowableArray<Pair<Klass*, Klass*> > links;
  3653. +
  3654. + for (int i=0; i<class_count; i++) {
  3655. +
  3656. + oop mirror = JNIHandles::resolve_non_null(class_defs[i].klass);
  3657. + instanceKlassHandle the_class(THREAD, java_lang_Class::as_Klass(mirror));
  3658. + Handle the_class_loader(THREAD, the_class->class_loader());
  3659. + Handle protection_domain(THREAD, the_class->protection_domain());
  3660. +
  3661. + ClassFileStream st((u1*) class_defs[i].class_bytes,
  3662. + class_defs[i].class_byte_count, (char *)"__VM_EnhancedRedefineClasses__");
  3663. + ClassFileParser cfp(&st);
  3664. +
  3665. +
  3666. +
  3667. + TempNewSymbol parsed_name;
  3668. + GrowableArray<Symbol*>* super_symbols = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<Symbol*>(0, true);
  3669. + cfp.parseClassFile(the_class->name(),
  3670. + the_class->class_loader_data(),
  3671. + protection_domain,
  3672. + the_class, KlassHandle(),
  3673. + NULL,
  3674. + super_symbols,
  3675. + parsed_name,
  3676. + false,
  3677. + THREAD);
  3678. +
  3679. + for (int j = 0; j < super_symbols->length(); j++) {
  3680. + Symbol* sym = super_symbols->at(j);
  3681. + Klass* super_klass = SystemDictionary::resolve_or_null(sym, the_class_loader, protection_domain, THREAD);
  3682. + if (super_klass != NULL) {
  3683. + instanceKlassHandle the_super_class(THREAD, super_klass);
  3684. + if (_affected_klasses->contains(the_super_class)) {
  3685. + links.append(Pair<Klass*, Klass*>(super_klass, the_class()));
  3686. + }
  3687. + }
  3688. + }
  3689. + delete super_symbols;
  3690. +
  3691. + assert(the_class->check_redefinition_flag(Klass::MarkedAsAffected), "");
  3692. + the_class->clear_redefinition_flag(Klass::MarkedAsAffected);
  3693. + }
  3694. +
  3695. + for (int i=0; i < _affected_klasses->length(); i++) {
  3696. + instanceKlassHandle klass = _affected_klasses->at(i);
  3697. +
  3698. + if (klass->check_redefinition_flag(Klass::MarkedAsAffected)) {
  3699. + klass->clear_redefinition_flag(Klass::MarkedAsAffected);
  3700. + Klass* superKlass = klass->super();
  3701. + if (_affected_klasses->contains(superKlass)) {
  3702. + links.append(Pair<Klass*, Klass*>(superKlass, klass()));
  3703. + }
  3704. +
  3705. + Array<Klass*>* superInterfaces = klass->local_interfaces();
  3706. + for (int j=0; j<superInterfaces->length(); j++) {
  3707. + Klass* interfaceKlass = superInterfaces->at(j);
  3708. + if (_affected_klasses->contains(interfaceKlass)) {
  3709. + links.append(Pair<Klass*, Klass*>(interfaceKlass, klass()));
  3710. + }
  3711. + }
  3712. + }
  3713. + }
  3714. +
  3715. + for (int i = 0; i < _affected_klasses->length(); i++) {
  3716. + int j;
  3717. + for (j = i; j < _affected_klasses->length(); j++) {
  3718. + // Search for node with no incoming edges
  3719. + Klass* oop = _affected_klasses->at(j)();
  3720. + int k = links.find(oop, match_second);
  3721. + if (k == -1) break;
  3722. + }
  3723. + if (j == _affected_klasses->length()) {
  3724. + return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  3725. + }
  3726. +
  3727. + // Remove all links from this node
  3728. + Klass* oop = _affected_klasses->at(j)();
  3729. + int k = 0;
  3730. + while (k < links.length()) {
  3731. + if (links.adr_at(k)->first == oop) {
  3732. + links.delete_at(k);
  3733. + } else {
  3734. + k++;
  3735. + }
  3736. + }
  3737. +
  3738. + // Swap node
  3739. + instanceKlassHandle tmp = _affected_klasses->at(j);
  3740. + _affected_klasses->at_put(j, _affected_klasses->at(i));
  3741. + _affected_klasses->at_put(i, tmp);
  3742. + }
  3743. +
  3744. + return JVMTI_ERROR_NONE;
  3745. +}
  3746. +
  3747. +// This internal class transfers the native function registration from old methods
  3748. +// to new methods. It is designed to handle both the simple case of unchanged
  3749. +// native methods and the complex cases of native method prefixes being added and/or
  3750. +// removed.
  3751. +// It expects only to be used during the VM_EnhancedRedefineClasses op (a safepoint).
  3752. +//
  3753. +// This class is used after the new methods have been installed in "the_class".
  3754. +//
  3755. +// So, for example, the following must be handled. Where 'm' is a method and
  3756. +// a number followed by an underscore is a prefix.
  3757. +//
  3758. +// Old Name New Name
  3759. +// Simple transfer to new method m -> m
  3760. +// Add prefix m -> 1_m
  3761. +// Remove prefix 1_m -> m
  3762. +// Simultaneous add of prefixes m -> 3_2_1_m
  3763. +// Simultaneous removal of prefixes 3_2_1_m -> m
  3764. +// Simultaneous add and remove 1_m -> 2_m
  3765. +// Same, caused by prefix removal only 3_2_1_m -> 3_2_m
  3766. +//
  3767. +class TransferNativeFunctionRegistration {
  3768. + private:
  3769. + instanceKlassHandle the_class;
  3770. + int prefix_count;
  3771. + char** prefixes;
  3772. +
  3773. + // Recursively search the binary tree of possibly prefixed method names.
  3774. + // Iteration could be used if all agents were well behaved. Full tree walk is
  3775. + // more resilent to agents not cleaning up intermediate methods.
  3776. + // Branch at each depth in the binary tree is:
  3777. + // (1) without the prefix.
  3778. + // (2) with the prefix.
  3779. + // where 'prefix' is the prefix at that 'depth' (first prefix, second prefix,...)
  3780. + Method* search_prefix_name_space(int depth, char* name_str, size_t name_len,
  3781. + Symbol* signature) {
  3782. + Symbol* name_symbol = SymbolTable::probe(name_str, (int)name_len);
  3783. + if (name_symbol != NULL) {
  3784. + Method* method = the_class()->new_version()->lookup_method(name_symbol, signature);
  3785. + if (method != NULL) {
  3786. + // Even if prefixed, intermediate methods must exist.
  3787. + if (method->is_native()) {
  3788. + // Wahoo, we found a (possibly prefixed) version of the method, return it.
  3789. + return method;
  3790. + }
  3791. + if (depth < prefix_count) {
  3792. + // Try applying further prefixes (other than this one).
  3793. + method = search_prefix_name_space(depth+1, name_str, name_len, signature);
  3794. + if (method != NULL) {
  3795. + return method; // found
  3796. + }
  3797. +
  3798. + // Try adding this prefix to the method name and see if it matches
  3799. + // another method name.
  3800. + char* prefix = prefixes[depth];
  3801. + size_t prefix_len = strlen(prefix);
  3802. + size_t trial_len = name_len + prefix_len;
  3803. + char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1);
  3804. + strcpy(trial_name_str, prefix);
  3805. + strcat(trial_name_str, name_str);
  3806. + method = search_prefix_name_space(depth+1, trial_name_str, trial_len,
  3807. + signature);
  3808. + if (method != NULL) {
  3809. + // If found along this branch, it was prefixed, mark as such
  3810. + method->set_is_prefixed_native();
  3811. + return method; // found
  3812. + }
  3813. + }
  3814. + }
  3815. + }
  3816. + return NULL; // This whole branch bore nothing
  3817. + }
  3818. +
  3819. + // Return the method name with old prefixes stripped away.
  3820. + char* method_name_without_prefixes(Method* method) {
  3821. + Symbol* name = method->name();
  3822. + char* name_str = name->as_utf8();
  3823. +
  3824. + // Old prefixing may be defunct, strip prefixes, if any.
  3825. + for (int i = prefix_count-1; i >= 0; i--) {
  3826. + char* prefix = prefixes[i];
  3827. + size_t prefix_len = strlen(prefix);
  3828. + if (strncmp(prefix, name_str, prefix_len) == 0) {
  3829. + name_str += prefix_len;
  3830. + }
  3831. + }
  3832. + return name_str;
  3833. + }
  3834. +
  3835. + // Strip any prefixes off the old native method, then try to find a
  3836. + // (possibly prefixed) new native that matches it.
  3837. + Method* strip_and_search_for_new_native(Method* method) {
  3838. + ResourceMark rm;
  3839. + char* name_str = method_name_without_prefixes(method);
  3840. + return search_prefix_name_space(0, name_str, strlen(name_str),
  3841. + method->signature());
  3842. + }
  3843. +
  3844. + public:
  3845. +
  3846. + // Construct a native method transfer processor for this class.
  3847. + TransferNativeFunctionRegistration(instanceKlassHandle _the_class) {
  3848. + assert(SafepointSynchronize::is_at_safepoint(), "sanity check");
  3849. +
  3850. + the_class = _the_class;
  3851. + prefixes = JvmtiExport::get_all_native_method_prefixes(&prefix_count);
  3852. + }
  3853. +
  3854. + // Attempt to transfer any of the old or deleted methods that are native
  3855. + void transfer_registrations(instanceKlassHandle old_klass, int* old_methods, int methods_length) {
  3856. + for (int j = 0; j < methods_length; j++) {
  3857. + Method* old_method = old_klass->methods()->at(old_methods[j]);
  3858. +
  3859. + if (old_method->is_native() && old_method->has_native_function()) {
  3860. + Method* new_method = strip_and_search_for_new_native(old_method);
  3861. + if (new_method != NULL) {
  3862. + // Actually set the native function in the new method.
  3863. + // Redefine does not send events (except CFLH), certainly not this
  3864. + // behind the scenes re-registration.
  3865. + new_method->set_native_function(old_method->native_function(),
  3866. + !Method::native_bind_event_is_interesting);
  3867. + }
  3868. + }
  3869. + }
  3870. + }
  3871. +};
  3872. +
  3873. +// Don't lose the association between a native method and its JNI function.
  3874. +void VM_EnhancedRedefineClasses::transfer_old_native_function_registrations(instanceKlassHandle old_klass) {
  3875. + TransferNativeFunctionRegistration transfer(old_klass);
  3876. + transfer.transfer_registrations(old_klass, _deleted_methods, _deleted_methods_length);
  3877. + transfer.transfer_registrations(old_klass, _matching_old_methods, _matching_methods_length);
  3878. +}
  3879. diff -r 8a6717910608 src/share/vm/prims/jvmtiRedefineClasses2.hpp
  3880. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  3881. +++ b/src/share/vm/prims/jvmtiRedefineClasses2.hpp Wed Apr 30 11:27:18 2014 -0700
  3882. @@ -0,0 +1,156 @@
  3883. +/*
  3884. + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
  3885. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  3886. + *
  3887. + * This code is free software; you can redistribute it and/or modify it
  3888. + * under the terms of the GNU General Public License version 2 only, as
  3889. + * published by the Free Software Foundation.
  3890. + *
  3891. + * This code is distributed in the hope that it will be useful, but WITHOUT
  3892. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  3893. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  3894. + * version 2 for more details (a copy is included in the LICENSE file that
  3895. + * accompanied this code).
  3896. + *
  3897. + * You should have received a copy of the GNU General Public License version
  3898. + * 2 along with this work; if not, write to the Free Software Foundation,
  3899. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  3900. + *
  3901. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  3902. + * or visit www.oracle.com if you need additional information or have any
  3903. + * questions.
  3904. + *
  3905. + */
  3906. +
  3907. +#ifndef SHARE_VM_PRIMS_JVMTIENHANCEDREDEFINECLASSES_HPP
  3908. +#define SHARE_VM_PRIMS_JVMTIENHANCEDREDEFINECLASSES_HPP
  3909. +
  3910. +#include "jvmtifiles/jvmtiEnv.hpp"
  3911. +#include "memory/oopFactory.hpp"
  3912. +#include "memory/resourceArea.hpp"
  3913. +#include "oops/objArrayKlass.hpp"
  3914. +#include "oops/objArrayOop.hpp"
  3915. +#include "oops/fieldStreams.hpp"
  3916. +#include "prims/jvmtiRedefineClassesTrace.hpp"
  3917. +#include "gc_implementation/shared/vmGCOperations.hpp"
  3918. +
  3919. +// New version that allows arbitrary changes to already loaded classes.
  3920. +class VM_EnhancedRedefineClasses: public VM_GC_Operation {
  3921. + private:
  3922. +
  3923. + // These static fields are needed by SystemDictionary::classes_do()
  3924. + // facility and the adjust_cpool_cache_and_vtable() helper:
  3925. + static Array<Method*>* _old_methods;
  3926. + static Array<Method*>* _new_methods;
  3927. + static int* _matching_old_methods;
  3928. + static int* _matching_new_methods;
  3929. + static int* _deleted_methods;
  3930. + static int* _added_methods;
  3931. + static int _matching_methods_length;
  3932. + static int _deleted_methods_length;
  3933. + static int _added_methods_length;
  3934. +
  3935. + static int _revision_number;
  3936. +
  3937. + static GrowableArray<instanceKlassHandle>* _affected_klasses;
  3938. +
  3939. + // The instance fields are used to pass information from
  3940. + // doit_prologue() to doit() and doit_epilogue().
  3941. + jint _class_count;
  3942. + const jvmtiClassDefinition *_class_defs; // ptr to _class_count defs
  3943. +
  3944. + // This operation is used by both RedefineClasses and
  3945. + // RetransformClasses. Indicate which.
  3946. + JvmtiClassLoadKind _class_load_kind;
  3947. +
  3948. + GrowableArray<instanceKlassHandle>* _new_classes;
  3949. + jvmtiError _result;
  3950. + int _max_redefinition_flags;
  3951. +
  3952. + // Performance measurement support. These timers do not cover all
  3953. + // the work done for JVM/TI RedefineClasses() but they do cover
  3954. + // the heavy lifting.
  3955. + elapsedTimer _timer_total;
  3956. + elapsedTimer _timer_prologue;
  3957. + elapsedTimer _timer_class_linking;
  3958. + elapsedTimer _timer_class_loading;
  3959. + elapsedTimer _timer_prepare_redefinition;
  3960. + elapsedTimer _timer_heap_iteration;
  3961. + elapsedTimer _timer_redefinition;
  3962. + elapsedTimer _timer_vm_op_epilogue;
  3963. +
  3964. + jvmtiError find_sorted_affected_classes( );
  3965. + jvmtiError find_class_bytes(instanceKlassHandle the_class, const unsigned char **class_bytes, jint *class_byte_count, jboolean *not_changed);
  3966. + jvmtiError load_new_class_versions(TRAPS);
  3967. +
  3968. + // Figure out which new methods match old methods in name and signature,
  3969. + // which methods have been added, and which are no longer present
  3970. + void compute_added_deleted_matching_methods();
  3971. +
  3972. + // Change jmethodIDs to point to the new methods
  3973. + void update_jmethod_ids();
  3974. +
  3975. + void swap_all_method_annotations(ConstMethod* old_method, ConstMethod* new_method);
  3976. +
  3977. + static void add_affected_klasses( Klass* obj );
  3978. +
  3979. + static jvmtiError do_topological_class_sorting(const jvmtiClassDefinition *class_definitions, int class_count, TRAPS);
  3980. +
  3981. + // Install the redefinition of a class
  3982. + void redefine_single_class(instanceKlassHandle the_new_class, TRAPS);
  3983. +
  3984. + // Increment the classRedefinedCount field in the specific instanceKlass
  3985. + // and in all direct and indirect subclasses.
  3986. + void increment_class_counter(Klass* klass, TRAPS);
  3987. +
  3988. +
  3989. + void flush_dependent_code(instanceKlassHandle k_h, TRAPS);
  3990. +
  3991. + static void check_class(Klass* k_oop,/* oop initiating_loader,*/ TRAPS) PRODUCT_RETURN;
  3992. +
  3993. + static void adjust_cpool_cache(Klass* k_oop, TRAPS);
  3994. +
  3995. + static void unpatch_bytecode(Method* method);
  3996. +
  3997. +#ifdef ASSERT
  3998. + static void verify_classes(Klass* k_oop, oop initiating_loader, TRAPS);
  3999. +#endif
  4000. +
  4001. + int calculate_redefinition_flags(instanceKlassHandle new_version);
  4002. + void calculate_instance_update_information(Klass* new_version);
  4003. + void check_methods_and_mark_as_obsolete(BitMap *emcp_methods, int * emcp_method_count_p);
  4004. + static void mark_as_scavengable(nmethod* nm);
  4005. +
  4006. + bool check_arguments();
  4007. + jvmtiError check_arguments_error();
  4008. +
  4009. + public:
  4010. + VM_EnhancedRedefineClasses(jint class_count, const jvmtiClassDefinition *class_defs, JvmtiClassLoadKind class_load_kind);
  4011. + virtual ~VM_EnhancedRedefineClasses();
  4012. +
  4013. + bool doit_prologue();
  4014. + void doit();
  4015. + void doit_epilogue();
  4016. + void rollback();
  4017. +
  4018. + jvmtiError check_exception() const;
  4019. + VMOp_Type type() const { return VMOp_RedefineClasses; }
  4020. + bool skip_operation() const { return false; }
  4021. + bool allow_nested_vm_operations() const { return true; }
  4022. + jvmtiError check_error() { return _result; }
  4023. +
  4024. + // Modifiable test must be shared between IsModifiableClass query
  4025. + // and redefine implementation
  4026. + static bool is_modifiable_class(oop klass_mirror);
  4027. +
  4028. + // Utility methods for transfering field access flags
  4029. +
  4030. + static void transfer_special_access_flags(JavaFieldStream *from, JavaFieldStream *to);
  4031. + static void transfer_special_access_flags(fieldDescriptor *from, fieldDescriptor *to);
  4032. +
  4033. + void transfer_old_native_function_registrations(instanceKlassHandle the_class);
  4034. +
  4035. + static void swap_marks(oop first, oop second);
  4036. +};
  4037. +
  4038. +#endif // SHARE_VM_PRIMS_JVMTIENHANCEDREDEFINECLASSES_HPP
  4039. diff -r 8a6717910608 src/share/vm/runtime/arguments.cpp
  4040. --- a/src/share/vm/runtime/arguments.cpp Tue Mar 11 13:02:13 2014 -0700
  4041. +++ b/src/share/vm/runtime/arguments.cpp Wed Apr 30 11:27:18 2014 -0700
  4042. @@ -59,8 +59,8 @@
  4043. #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
  4044. #endif // INCLUDE_ALL_GCS
  4045. -// Note: This is a special bug reporting site for the JVM
  4046. -#define DEFAULT_VENDOR_URL_BUG "http://bugreport.sun.com/bugreport/crash.jsp"
  4047. +// (DCEVM) The DCE VM has its own JIRA bug tracking system.
  4048. +#define DEFAULT_VENDOR_URL_BUG "https://github.com/Guidewire/DCEVM/issues"
  4049. #define DEFAULT_JAVA_LAUNCHER "generic"
  4050. // Disable options not supported in this release, with a warning if they
  4051. @@ -1507,6 +1507,10 @@
  4052. void Arguments::set_ergonomics_flags() {
  4053. + if (AllowEnhancedClassRedefinition) {
  4054. + // (DCEVM) enforces serial GC
  4055. + FLAG_SET_ERGO(bool, UseSerialGC, true);
  4056. + }
  4057. if (os::is_server_class_machine()) {
  4058. // If no other collector is requested explicitly,
  4059. // let the VM select the collector based on
  4060. @@ -1948,6 +1952,17 @@
  4061. if (UseConcMarkSweepGC || UseParNewGC) i++;
  4062. if (UseParallelGC || UseParallelOldGC) i++;
  4063. if (UseG1GC) i++;
  4064. +
  4065. + if (AllowEnhancedClassRedefinition) {
  4066. + // (DCEVM) Must use serial GC. This limitation applies because the instance size changing GC modifications
  4067. + // are only built into the mark and compact algorithm.
  4068. + if (!UseSerialGC && i >= 1) {
  4069. + jio_fprintf(defaultStream::error_stream(),
  4070. + "Must use the serial GC in the DCEVM\n");
  4071. + status = false;
  4072. + }
  4073. + }
  4074. +
  4075. if (i > 1) {
  4076. jio_fprintf(defaultStream::error_stream(),
  4077. "Conflicting collector combinations in option list; "
  4078. diff -r 8a6717910608 src/share/vm/runtime/globals.hpp
  4079. --- a/src/share/vm/runtime/globals.hpp Tue Mar 11 13:02:13 2014 -0700
  4080. +++ b/src/share/vm/runtime/globals.hpp Wed Apr 30 11:27:18 2014 -0700
  4081. @@ -1273,6 +1273,9 @@
  4082. product(intx, TraceRedefineClasses, 0, \
  4083. "Trace level for JVMTI RedefineClasses") \
  4084. \
  4085. + product(bool, AllowEnhancedClassRedefinition, true, \
  4086. + "Allow enhanced class redefinition beyond swapping method bodies")\
  4087. + \
  4088. develop(bool, StressMethodComparator, false, \
  4089. "Run the MethodComparator on all loaded methods") \
  4090. \
  4091. diff -r 8a6717910608 src/share/vm/runtime/reflection.cpp
  4092. --- a/src/share/vm/runtime/reflection.cpp Tue Mar 11 13:02:13 2014 -0700
  4093. +++ b/src/share/vm/runtime/reflection.cpp Wed Apr 30 11:27:18 2014 -0700
  4094. @@ -519,6 +519,12 @@
  4095. AccessFlags access,
  4096. bool classloader_only,
  4097. bool protected_restriction) {
  4098. +
  4099. + // (DCEVM) Decide accessibility based on active version
  4100. + if (current_class != NULL) {
  4101. + current_class = current_class->active_version();
  4102. + }
  4103. +
  4104. // Verify that current_class can access a field of field_class, where that
  4105. // field's access bits are "access". We assume that we've already verified
  4106. // that current_class can access field_class.