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-jdk8u112-b16.patch 153KB

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