您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

light-jdk8u5-b13.patch 155KB

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