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-jdk8u181-b13.patch 153KB

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