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-jdk8u66-b17.patch 153KB

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