< prev index next >

src/hotspot/share/prims/jvmtiRedefineClasses.cpp

Print this page


   1 /*
   2  * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 315     {
 316       int name_i = scratch_cp->klass_name_index_at(scratch_i);
 317       int new_name_i = find_or_append_indirect_entry(scratch_cp, name_i, merge_cp_p,
 318                                                      merge_cp_length_p, THREAD);
 319 
 320       if (new_name_i != name_i) {
 321         log_trace(redefine, class, constantpool)
 322           ("Class entry@%d name_index change: %d to %d",
 323            *merge_cp_length_p, name_i, new_name_i);
 324       }
 325 
 326       (*merge_cp_p)->temp_unresolved_klass_at_put(*merge_cp_length_p, new_name_i);
 327       if (scratch_i != *merge_cp_length_p) {
 328         // The new entry in *merge_cp_p is at a different index than
 329         // the new entry in scratch_cp so we need to map the index values.
 330         map_index(scratch_cp, scratch_i, *merge_cp_length_p);
 331       }
 332       (*merge_cp_length_p)++;
 333     } break;
 334 
 335     // this is an indirect CP entry so it needs special handling
 336     case JVM_CONSTANT_Value:
 337     case JVM_CONSTANT_UnresolvedValue:
 338     {
 339       int name_i = scratch_cp->klass_name_index_at(scratch_i);
 340       int new_name_i = find_or_append_indirect_entry(scratch_cp, name_i, merge_cp_p,
 341                                                      merge_cp_length_p, THREAD);
 342 
 343       if (new_name_i != name_i) {
 344         log_trace(redefine, class, constantpool)
 345           ("Value type entry@%d name_index change: %d to %d",
 346            *merge_cp_length_p, name_i, new_name_i);
 347       }
 348 
 349       (*merge_cp_p)->temp_unresolved_value_type_at_put(*merge_cp_length_p, new_name_i);
 350       if (scratch_i != *merge_cp_length_p) {
 351         // The new entry in *merge_cp_p is at a different index than
 352         // the new entry in scratch_cp so we need to map the index values.
 353         map_index(scratch_cp, scratch_i, *merge_cp_length_p);
 354       }
 355       (*merge_cp_length_p)++;
 356     } break;
 357 
 358     // these are direct CP entries so they can be directly appended,
 359     // but double and long take two constant pool entries
 360     case JVM_CONSTANT_Double:  // fall through
 361     case JVM_CONSTANT_Long:
 362     {
 363       ConstantPool::copy_entry_to(scratch_cp, scratch_i, *merge_cp_p, *merge_cp_length_p,
 364         THREAD);
 365 
 366       if (scratch_i != *merge_cp_length_p) {
 367         // The new entry in *merge_cp_p is at a different index than
 368         // the new entry in scratch_cp so we need to map the index values.
 369         map_index(scratch_cp, scratch_i, *merge_cp_length_p);
 370       }
 371       (*merge_cp_length_p) += 2;
 372     } break;
 373 
 374     // these are direct CP entries so they can be directly appended
 375     case JVM_CONSTANT_Float:   // fall through
 376     case JVM_CONSTANT_Integer: // fall through
 377     case JVM_CONSTANT_Utf8:    // fall through


 539       if (new_ref_i != old_ref_i) {
 540         log_trace(redefine, class, constantpool)
 541           ("Dynamic entry@%d name_and_type_index change: %d to %d", *merge_cp_length_p, old_ref_i, new_ref_i);
 542       }
 543 
 544       if (scratch_cp->tag_at(scratch_i).is_dynamic_constant())
 545         (*merge_cp_p)->dynamic_constant_at_put(*merge_cp_length_p, new_bs_i, new_ref_i);
 546       else
 547         (*merge_cp_p)->invoke_dynamic_at_put(*merge_cp_length_p, new_bs_i, new_ref_i);
 548       if (scratch_i != *merge_cp_length_p) {
 549         // The new entry in *merge_cp_p is at a different index than
 550         // the new entry in scratch_cp so we need to map the index values.
 551         map_index(scratch_cp, scratch_i, *merge_cp_length_p);
 552       }
 553       (*merge_cp_length_p)++;
 554     } break;
 555 
 556     // At this stage, Class or UnresolvedClass could be in scratch_cp, but not
 557     // ClassIndex
 558     case JVM_CONSTANT_ClassIndex: // fall through
 559     case JVM_CONSTANT_ValueIndex: // fall through
 560 
 561     // Invalid is used as the tag for the second constant pool entry
 562     // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should
 563     // not be seen by itself.
 564     case JVM_CONSTANT_Invalid: // fall through
 565 
 566     // At this stage, String could be here, but not StringIndex
 567     case JVM_CONSTANT_StringIndex: // fall through
 568 
 569     // At this stage JVM_CONSTANT_UnresolvedClassInError should not be here
 570     case JVM_CONSTANT_UnresolvedClassInError: // fall through
 571 
 572     // At this stage JVM_CONSTANT_UnresolvedValueInError should not be here
 573     case JVM_CONSTANT_UnresolvedValueInError: // fall through
 574 
 575     default:
 576     {
 577       // leave a breadcrumb
 578       jbyte bad_value = scratch_cp->tag_at(scratch_i).value();
 579       ShouldNotReachHere();
 580     } break;
 581   } // end switch tag value
 582 } // end append_entry()
 583 
 584 
 585 int VM_RedefineClasses::find_or_append_indirect_entry(const constantPoolHandle& scratch_cp,
 586       int ref_i, constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS) {
 587 
 588   int new_ref_i = ref_i;
 589   bool match = (ref_i < *merge_cp_length_p) &&
 590                scratch_cp->compare_entry_to(ref_i, *merge_cp_p, ref_i, THREAD);
 591 
 592   if (!match) {
 593     // forward reference in *merge_cp_p or not a direct match
 594     int found_i = scratch_cp->find_matching_entry(ref_i, *merge_cp_p, THREAD);


1002     // This should not happen in regular constant pool merging use.
1003     return -1;
1004   }
1005 
1006   int value = _operands_index_map_p->at(old_index);
1007   if (value == -1) {
1008     // the old_index is not mapped
1009     return -1;
1010   }
1011 
1012   return value;
1013 } // end find_new_operand_index()
1014 
1015 
1016 // Returns true if the current mismatch is due to a resolved/unresolved
1017 // class pair. Otherwise, returns false.
1018 bool VM_RedefineClasses::is_unresolved_class_mismatch(const constantPoolHandle& cp1,
1019        int index1, const constantPoolHandle& cp2, int index2) {
1020 
1021   jbyte t1 = cp1->tag_at(index1).value();
1022   if (t1 != JVM_CONSTANT_Class && t1 != JVM_CONSTANT_UnresolvedClass &&
1023       t1 != JVM_CONSTANT_Value && t1 != JVM_CONSTANT_UnresolvedValue) {
1024     return false;  // wrong entry type; not our special case
1025   }
1026 
1027   jbyte t2 = cp2->tag_at(index2).value();
1028   if (t2 != JVM_CONSTANT_Class && t2 != JVM_CONSTANT_UnresolvedClass &&
1029       t2 != JVM_CONSTANT_Value && t2 != JVM_CONSTANT_UnresolvedValue) {
1030     return false;  // wrong entry type; not our special case
1031   }
1032 
1033   if (t1 == t2) {
1034     return false;  // not a mismatch; not our special case
1035   }
1036 
1037   char *s1 = cp1->klass_name_at(index1)->as_C_string();
1038   char *s2 = cp2->klass_name_at(index2)->as_C_string();
1039   if (strcmp(s1, s2) != 0) {
1040     return false;  // strings don't match; not our special case
1041   }
1042 
1043   return true;  // made it through the gauntlet; this is our special case
1044 } // end is_unresolved_class_mismatch()
1045 
1046 
1047 jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) {
1048 
1049   // For consistency allocate memory using os::malloc wrapper.


1293     assert(false, "caller must provide scratch CP length");
1294     return false; // robustness
1295   }
1296   // Worst case we need old_cp->length() + scratch_cp()->length(),
1297   // but the caller might be smart so make sure we have at least
1298   // the minimum.
1299   if ((*merge_cp_p)->length() < old_cp->length()) {
1300     assert(false, "merge area too small");
1301     return false; // robustness
1302   }
1303 
1304   log_info(redefine, class, constantpool)("old_cp_len=%d, scratch_cp_len=%d", old_cp->length(), scratch_cp->length());
1305 
1306   {
1307     // Pass 0:
1308     // The old_cp is copied to *merge_cp_p; this means that any code
1309     // using old_cp does not have to change. This work looks like a
1310     // perfect fit for ConstantPool*::copy_cp_to(), but we need to
1311     // handle one special case:
1312     // - revert JVM_CONSTANT_Class to JVM_CONSTANT_UnresolvedClass
1313     // - revert JVM_CONSTANT_Value to JVM_CONSTANT_UnresolvedValue
1314     // This will make verification happy.
1315 
1316     int old_i;  // index into old_cp
1317 
1318     // index zero (0) is not used in constantPools
1319     for (old_i = 1; old_i < old_cp->length(); old_i++) {
1320       // leave debugging crumb
1321       jbyte old_tag = old_cp->tag_at(old_i).value();
1322       switch (old_tag) {
1323       case JVM_CONSTANT_Class:
1324       case JVM_CONSTANT_UnresolvedClass:
1325         // revert the copy to JVM_CONSTANT_UnresolvedClass
1326         // May be resolving while calling this so do the same for
1327         // JVM_CONSTANT_UnresolvedClass (klass_name_at() deals with transition)
1328         (*merge_cp_p)->temp_unresolved_klass_at_put(old_i,
1329           old_cp->klass_name_index_at(old_i));
1330         break;
1331 
1332       case JVM_CONSTANT_Value:
1333       case JVM_CONSTANT_UnresolvedValue:
1334         // revert the copy to JVM_CONSTANT_UnresolvedValue
1335         // May be resolving while calling this so do the same for
1336         // JVM_CONSTANT_UnresolvedValue (klass_name_at() deals with transition)
1337         (*merge_cp_p)->temp_unresolved_value_type_at_put(old_i,
1338           old_cp->klass_name_index_at(old_i));
1339         break;
1340 
1341       case JVM_CONSTANT_Double:
1342       case JVM_CONSTANT_Long:
1343         // just copy the entry to *merge_cp_p, but double and long take
1344         // two constant pool entries
1345         ConstantPool::copy_entry_to(old_cp, old_i, *merge_cp_p, old_i, CHECK_0);
1346         old_i++;
1347         break;
1348 
1349       default:
1350         // just copy the entry to *merge_cp_p
1351         ConstantPool::copy_entry_to(old_cp, old_i, *merge_cp_p, old_i, CHECK_0);
1352         break;
1353       }
1354     } // end for each old_cp entry
1355 
1356     ConstantPool::copy_operands(old_cp, *merge_cp_p, CHECK_0);
1357     (*merge_cp_p)->extend_operands(scratch_cp, CHECK_0);


   1 /*
   2  * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 315     {
 316       int name_i = scratch_cp->klass_name_index_at(scratch_i);
 317       int new_name_i = find_or_append_indirect_entry(scratch_cp, name_i, merge_cp_p,
 318                                                      merge_cp_length_p, THREAD);
 319 
 320       if (new_name_i != name_i) {
 321         log_trace(redefine, class, constantpool)
 322           ("Class entry@%d name_index change: %d to %d",
 323            *merge_cp_length_p, name_i, new_name_i);
 324       }
 325 
 326       (*merge_cp_p)->temp_unresolved_klass_at_put(*merge_cp_length_p, new_name_i);
 327       if (scratch_i != *merge_cp_length_p) {
 328         // The new entry in *merge_cp_p is at a different index than
 329         // the new entry in scratch_cp so we need to map the index values.
 330         map_index(scratch_cp, scratch_i, *merge_cp_length_p);
 331       }
 332       (*merge_cp_length_p)++;
 333     } break;
 334 























 335     // these are direct CP entries so they can be directly appended,
 336     // but double and long take two constant pool entries
 337     case JVM_CONSTANT_Double:  // fall through
 338     case JVM_CONSTANT_Long:
 339     {
 340       ConstantPool::copy_entry_to(scratch_cp, scratch_i, *merge_cp_p, *merge_cp_length_p,
 341         THREAD);
 342 
 343       if (scratch_i != *merge_cp_length_p) {
 344         // The new entry in *merge_cp_p is at a different index than
 345         // the new entry in scratch_cp so we need to map the index values.
 346         map_index(scratch_cp, scratch_i, *merge_cp_length_p);
 347       }
 348       (*merge_cp_length_p) += 2;
 349     } break;
 350 
 351     // these are direct CP entries so they can be directly appended
 352     case JVM_CONSTANT_Float:   // fall through
 353     case JVM_CONSTANT_Integer: // fall through
 354     case JVM_CONSTANT_Utf8:    // fall through


 516       if (new_ref_i != old_ref_i) {
 517         log_trace(redefine, class, constantpool)
 518           ("Dynamic entry@%d name_and_type_index change: %d to %d", *merge_cp_length_p, old_ref_i, new_ref_i);
 519       }
 520 
 521       if (scratch_cp->tag_at(scratch_i).is_dynamic_constant())
 522         (*merge_cp_p)->dynamic_constant_at_put(*merge_cp_length_p, new_bs_i, new_ref_i);
 523       else
 524         (*merge_cp_p)->invoke_dynamic_at_put(*merge_cp_length_p, new_bs_i, new_ref_i);
 525       if (scratch_i != *merge_cp_length_p) {
 526         // The new entry in *merge_cp_p is at a different index than
 527         // the new entry in scratch_cp so we need to map the index values.
 528         map_index(scratch_cp, scratch_i, *merge_cp_length_p);
 529       }
 530       (*merge_cp_length_p)++;
 531     } break;
 532 
 533     // At this stage, Class or UnresolvedClass could be in scratch_cp, but not
 534     // ClassIndex
 535     case JVM_CONSTANT_ClassIndex: // fall through

 536 
 537     // Invalid is used as the tag for the second constant pool entry
 538     // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should
 539     // not be seen by itself.
 540     case JVM_CONSTANT_Invalid: // fall through
 541 
 542     // At this stage, String could be here, but not StringIndex
 543     case JVM_CONSTANT_StringIndex: // fall through
 544 
 545     // At this stage JVM_CONSTANT_UnresolvedClassInError should not be here
 546     case JVM_CONSTANT_UnresolvedClassInError: // fall through
 547 



 548     default:
 549     {
 550       // leave a breadcrumb
 551       jbyte bad_value = scratch_cp->tag_at(scratch_i).value();
 552       ShouldNotReachHere();
 553     } break;
 554   } // end switch tag value
 555 } // end append_entry()
 556 
 557 
 558 int VM_RedefineClasses::find_or_append_indirect_entry(const constantPoolHandle& scratch_cp,
 559       int ref_i, constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS) {
 560 
 561   int new_ref_i = ref_i;
 562   bool match = (ref_i < *merge_cp_length_p) &&
 563                scratch_cp->compare_entry_to(ref_i, *merge_cp_p, ref_i, THREAD);
 564 
 565   if (!match) {
 566     // forward reference in *merge_cp_p or not a direct match
 567     int found_i = scratch_cp->find_matching_entry(ref_i, *merge_cp_p, THREAD);


 975     // This should not happen in regular constant pool merging use.
 976     return -1;
 977   }
 978 
 979   int value = _operands_index_map_p->at(old_index);
 980   if (value == -1) {
 981     // the old_index is not mapped
 982     return -1;
 983   }
 984 
 985   return value;
 986 } // end find_new_operand_index()
 987 
 988 
 989 // Returns true if the current mismatch is due to a resolved/unresolved
 990 // class pair. Otherwise, returns false.
 991 bool VM_RedefineClasses::is_unresolved_class_mismatch(const constantPoolHandle& cp1,
 992        int index1, const constantPoolHandle& cp2, int index2) {
 993 
 994   jbyte t1 = cp1->tag_at(index1).value();
 995   if (t1 != JVM_CONSTANT_Class && t1 != JVM_CONSTANT_UnresolvedClass) {

 996     return false;  // wrong entry type; not our special case
 997   }
 998 
 999   jbyte t2 = cp2->tag_at(index2).value();
1000   if (t2 != JVM_CONSTANT_Class && t2 != JVM_CONSTANT_UnresolvedClass) {

1001     return false;  // wrong entry type; not our special case
1002   }
1003 
1004   if (t1 == t2) {
1005     return false;  // not a mismatch; not our special case
1006   }
1007 
1008   char *s1 = cp1->klass_name_at(index1)->as_C_string();
1009   char *s2 = cp2->klass_name_at(index2)->as_C_string();
1010   if (strcmp(s1, s2) != 0) {
1011     return false;  // strings don't match; not our special case
1012   }
1013 
1014   return true;  // made it through the gauntlet; this is our special case
1015 } // end is_unresolved_class_mismatch()
1016 
1017 
1018 jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) {
1019 
1020   // For consistency allocate memory using os::malloc wrapper.


1264     assert(false, "caller must provide scratch CP length");
1265     return false; // robustness
1266   }
1267   // Worst case we need old_cp->length() + scratch_cp()->length(),
1268   // but the caller might be smart so make sure we have at least
1269   // the minimum.
1270   if ((*merge_cp_p)->length() < old_cp->length()) {
1271     assert(false, "merge area too small");
1272     return false; // robustness
1273   }
1274 
1275   log_info(redefine, class, constantpool)("old_cp_len=%d, scratch_cp_len=%d", old_cp->length(), scratch_cp->length());
1276 
1277   {
1278     // Pass 0:
1279     // The old_cp is copied to *merge_cp_p; this means that any code
1280     // using old_cp does not have to change. This work looks like a
1281     // perfect fit for ConstantPool*::copy_cp_to(), but we need to
1282     // handle one special case:
1283     // - revert JVM_CONSTANT_Class to JVM_CONSTANT_UnresolvedClass

1284     // This will make verification happy.
1285 
1286     int old_i;  // index into old_cp
1287 
1288     // index zero (0) is not used in constantPools
1289     for (old_i = 1; old_i < old_cp->length(); old_i++) {
1290       // leave debugging crumb
1291       jbyte old_tag = old_cp->tag_at(old_i).value();
1292       switch (old_tag) {
1293       case JVM_CONSTANT_Class:
1294       case JVM_CONSTANT_UnresolvedClass:
1295         // revert the copy to JVM_CONSTANT_UnresolvedClass
1296         // May be resolving while calling this so do the same for
1297         // JVM_CONSTANT_UnresolvedClass (klass_name_at() deals with transition)
1298         (*merge_cp_p)->temp_unresolved_klass_at_put(old_i,









1299           old_cp->klass_name_index_at(old_i));
1300         break;
1301 
1302       case JVM_CONSTANT_Double:
1303       case JVM_CONSTANT_Long:
1304         // just copy the entry to *merge_cp_p, but double and long take
1305         // two constant pool entries
1306         ConstantPool::copy_entry_to(old_cp, old_i, *merge_cp_p, old_i, CHECK_0);
1307         old_i++;
1308         break;
1309 
1310       default:
1311         // just copy the entry to *merge_cp_p
1312         ConstantPool::copy_entry_to(old_cp, old_i, *merge_cp_p, old_i, CHECK_0);
1313         break;
1314       }
1315     } // end for each old_cp entry
1316 
1317     ConstantPool::copy_operands(old_cp, *merge_cp_p, CHECK_0);
1318     (*merge_cp_p)->extend_operands(scratch_cp, CHECK_0);


< prev index next >