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-jdk8u92-b14.patch 153KB

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