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

light-jdk8u201-b09.patch 153KB

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