src/share/vm/prims/jvmtiRedefineClasses.cpp

changeset 4037
da91efe96a93
parent 3921
e74da3c2b827
child 4142
d8ce2825b193
     1.1 --- a/src/share/vm/prims/jvmtiRedefineClasses.cpp	Fri Aug 31 16:39:35 2012 -0700
     1.2 +++ b/src/share/vm/prims/jvmtiRedefineClasses.cpp	Sat Sep 01 13:25:18 2012 -0400
     1.3 @@ -26,9 +26,12 @@
     1.4  #include "classfile/systemDictionary.hpp"
     1.5  #include "classfile/verifier.hpp"
     1.6  #include "code/codeCache.hpp"
     1.7 +#include "compiler/compileBroker.hpp"
     1.8  #include "interpreter/oopMapCache.hpp"
     1.9  #include "interpreter/rewriter.hpp"
    1.10  #include "memory/gcLocker.hpp"
    1.11 +#include "memory/metadataFactory.hpp"
    1.12 +#include "memory/metaspaceShared.hpp"
    1.13  #include "memory/universe.inline.hpp"
    1.14  #include "oops/fieldStreams.hpp"
    1.15  #include "oops/klassVtable.hpp"
    1.16 @@ -40,16 +43,16 @@
    1.17  #include "utilities/bitMap.inline.hpp"
    1.18  
    1.19  
    1.20 -objArrayOop VM_RedefineClasses::_old_methods = NULL;
    1.21 -objArrayOop VM_RedefineClasses::_new_methods = NULL;
    1.22 -methodOop*  VM_RedefineClasses::_matching_old_methods = NULL;
    1.23 -methodOop*  VM_RedefineClasses::_matching_new_methods = NULL;
    1.24 -methodOop*  VM_RedefineClasses::_deleted_methods      = NULL;
    1.25 -methodOop*  VM_RedefineClasses::_added_methods        = NULL;
    1.26 +Array<Method*>* VM_RedefineClasses::_old_methods = NULL;
    1.27 +Array<Method*>* VM_RedefineClasses::_new_methods = NULL;
    1.28 +Method**  VM_RedefineClasses::_matching_old_methods = NULL;
    1.29 +Method**  VM_RedefineClasses::_matching_new_methods = NULL;
    1.30 +Method**  VM_RedefineClasses::_deleted_methods      = NULL;
    1.31 +Method**  VM_RedefineClasses::_added_methods        = NULL;
    1.32  int         VM_RedefineClasses::_matching_methods_length = 0;
    1.33  int         VM_RedefineClasses::_deleted_methods_length  = 0;
    1.34  int         VM_RedefineClasses::_added_methods_length    = 0;
    1.35 -klassOop    VM_RedefineClasses::_the_class_oop = NULL;
    1.36 +Klass*      VM_RedefineClasses::_the_class_oop = NULL;
    1.37  
    1.38  
    1.39  VM_RedefineClasses::VM_RedefineClasses(jint class_count,
    1.40 @@ -93,6 +96,15 @@
    1.41    // call chain it is required that the current thread is a Java thread.
    1.42    _res = load_new_class_versions(Thread::current());
    1.43    if (_res != JVMTI_ERROR_NONE) {
    1.44 +    // free any successfully created classes, since none are redefined
    1.45 +    for (int i = 0; i < _class_count; i++) {
    1.46 +      if (_scratch_classes[i] != NULL) {
    1.47 +        ClassLoaderData* cld = _scratch_classes[i]->class_loader_data();
    1.48 +        // Free the memory for this class at class unloading time.  Not before
    1.49 +        // because CMS might think this is still live.
    1.50 +        cld->add_to_deallocate_list((InstanceKlass*)_scratch_classes[i]);
    1.51 +      }
    1.52 +    }
    1.53      // Free os::malloc allocated memory in load_new_class_version.
    1.54      os::free(_scratch_classes);
    1.55      RC_TIMER_STOP(_timer_vm_op_prologue);
    1.56 @@ -103,6 +115,43 @@
    1.57    return true;
    1.58  }
    1.59  
    1.60 +// Keep track of marked on-stack metadata so it can be cleared.
    1.61 +GrowableArray<Metadata*>* _marked_objects = NULL;
    1.62 +NOT_PRODUCT(bool MetadataOnStackMark::_is_active = false;)
    1.63 +
    1.64 +// Walk metadata on the stack and mark it so that redefinition doesn't delete
    1.65 +// it.  Class unloading also walks the previous versions and might try to
    1.66 +// delete it, so this class is used by class unloading also.
    1.67 +MetadataOnStackMark::MetadataOnStackMark() {
    1.68 +  assert(SafepointSynchronize::is_at_safepoint(), "sanity check");
    1.69 +  NOT_PRODUCT(_is_active = true;)
    1.70 +  if (_marked_objects == NULL) {
    1.71 +    _marked_objects = new (ResourceObj::C_HEAP, mtClass) GrowableArray<Metadata*>(1000, true);
    1.72 +  }
    1.73 +  Threads::metadata_do(Metadata::mark_on_stack);
    1.74 +  CodeCache::alive_nmethods_do(nmethod::mark_on_stack);
    1.75 +  CompileBroker::mark_on_stack();
    1.76 +}
    1.77 +
    1.78 +MetadataOnStackMark::~MetadataOnStackMark() {
    1.79 +  assert(SafepointSynchronize::is_at_safepoint(), "sanity check");
    1.80 +  // Unmark everything that was marked.   Can't do the same walk because
    1.81 +  // redefine classes messes up the code cache so the set of methods
    1.82 +  // might not be the same.
    1.83 +  for (int i = 0; i< _marked_objects->length(); i++) {
    1.84 +    _marked_objects->at(i)->set_on_stack(false);
    1.85 +  }
    1.86 +  _marked_objects->clear();   // reuse growable array for next time.
    1.87 +  NOT_PRODUCT(_is_active = false;)
    1.88 +}
    1.89 +
    1.90 +// Record which objects are marked so we can unmark the same objects.
    1.91 +void MetadataOnStackMark::record(Metadata* m) {
    1.92 +  assert(_is_active, "metadata on stack marking is active");
    1.93 +  _marked_objects->push(m);
    1.94 +}
    1.95 +
    1.96 +
    1.97  void VM_RedefineClasses::doit() {
    1.98    Thread *thread = Thread::current();
    1.99  
   1.100 @@ -111,7 +160,7 @@
   1.101      // shared readwrite, private just in case we need to redefine
   1.102      // a shared class. We do the remap during the doit() phase of
   1.103      // the safepoint to be safer.
   1.104 -    if (!CompactingPermGenGen::remap_shared_readonly_as_readwrite()) {
   1.105 +    if (!MetaspaceShared::remap_shared_readonly_as_readwrite()) {
   1.106        RC_TRACE_WITH_THREAD(0x00000001, thread,
   1.107          ("failed to remap shared readonly space to readwrite, private"));
   1.108        _res = JVMTI_ERROR_INTERNAL;
   1.109 @@ -119,9 +168,21 @@
   1.110      }
   1.111    }
   1.112  
   1.113 +  // Mark methods seen on stack and everywhere else so old methods are not
   1.114 +  // cleaned up if they're on the stack.
   1.115 +  MetadataOnStackMark md_on_stack;
   1.116 +  HandleMark hm(thread);   // make sure any handles created are deleted
   1.117 +                           // before the stack walk again.
   1.118 +
   1.119    for (int i = 0; i < _class_count; i++) {
   1.120      redefine_single_class(_class_defs[i].klass, _scratch_classes[i], thread);
   1.121 +    ClassLoaderData* cld = _scratch_classes[i]->class_loader_data();
   1.122 +    // Free the memory for this class at class unloading time.  Not before
   1.123 +    // because CMS might think this is still live.
   1.124 +    cld->add_to_deallocate_list((InstanceKlass*)_scratch_classes[i]);
   1.125 +    _scratch_classes[i] = NULL;
   1.126    }
   1.127 +
   1.128    // Disable any dependent concurrent compilations
   1.129    SystemDictionary::notice_modification();
   1.130  
   1.131 @@ -136,7 +197,6 @@
   1.132  
   1.133  void VM_RedefineClasses::doit_epilogue() {
   1.134    // Free os::malloc allocated memory.
   1.135 -  // The memory allocated in redefine will be free'ed in next VM operation.
   1.136    os::free(_scratch_classes);
   1.137  
   1.138    if (RC_TRACE_ENABLED(0x00000004)) {
   1.139 @@ -160,7 +220,7 @@
   1.140    if (java_lang_Class::is_primitive(klass_mirror)) {
   1.141      return false;
   1.142    }
   1.143 -  klassOop the_class_oop = java_lang_Class::as_klassOop(klass_mirror);
   1.144 +  Klass* the_class_oop = java_lang_Class::as_Klass(klass_mirror);
   1.145    // classes for arrays cannot be redefined
   1.146    if (the_class_oop == NULL || !Klass::cast(the_class_oop)->oop_is_instance()) {
   1.147      return false;
   1.148 @@ -215,7 +275,7 @@
   1.149      case JVM_CONSTANT_Double:  // fall through
   1.150      case JVM_CONSTANT_Long:
   1.151      {
   1.152 -      constantPoolOopDesc::copy_entry_to(scratch_cp, scratch_i, *merge_cp_p, *merge_cp_length_p,
   1.153 +      ConstantPool::copy_entry_to(scratch_cp, scratch_i, *merge_cp_p, *merge_cp_length_p,
   1.154          THREAD);
   1.155  
   1.156        if (scratch_i != *merge_cp_length_p) {
   1.157 @@ -232,15 +292,14 @@
   1.158      case JVM_CONSTANT_Utf8:    // fall through
   1.159  
   1.160      // This was an indirect CP entry, but it has been changed into
   1.161 -    // an interned string so this entry can be directly appended.
   1.162 +    // Symbol*s so this entry can be directly appended.
   1.163      case JVM_CONSTANT_String:      // fall through
   1.164  
   1.165      // These were indirect CP entries, but they have been changed into
   1.166      // Symbol*s so these entries can be directly appended.
   1.167      case JVM_CONSTANT_UnresolvedClass:  // fall through
   1.168 -    case JVM_CONSTANT_UnresolvedString:
   1.169      {
   1.170 -      constantPoolOopDesc::copy_entry_to(scratch_cp, scratch_i, *merge_cp_p, *merge_cp_length_p,
   1.171 +      ConstantPool::copy_entry_to(scratch_cp, scratch_i, *merge_cp_p, *merge_cp_length_p,
   1.172          THREAD);
   1.173  
   1.174        if (scratch_i != *merge_cp_length_p) {
   1.175 @@ -467,8 +526,7 @@
   1.176      // not be seen by itself.
   1.177      case JVM_CONSTANT_Invalid: // fall through
   1.178  
   1.179 -    // At this stage, String or UnresolvedString could be here, but not
   1.180 -    // StringIndex
   1.181 +    // At this stage, String could be here, but not StringIndex
   1.182      case JVM_CONSTANT_StringIndex: // fall through
   1.183  
   1.184      // At this stage JVM_CONSTANT_UnresolvedClassInError should not be
   1.185 @@ -485,20 +543,23 @@
   1.186  } // end append_entry()
   1.187  
   1.188  
   1.189 -void VM_RedefineClasses::swap_all_method_annotations(int i, int j, instanceKlassHandle scratch_class) {
   1.190 -  typeArrayOop save;
   1.191 -
   1.192 -  save = scratch_class->get_method_annotations_of(i);
   1.193 -  scratch_class->set_method_annotations_of(i, scratch_class->get_method_annotations_of(j));
   1.194 -  scratch_class->set_method_annotations_of(j, save);
   1.195 -
   1.196 -  save = scratch_class->get_method_parameter_annotations_of(i);
   1.197 -  scratch_class->set_method_parameter_annotations_of(i, scratch_class->get_method_parameter_annotations_of(j));
   1.198 -  scratch_class->set_method_parameter_annotations_of(j, save);
   1.199 -
   1.200 -  save = scratch_class->get_method_default_annotations_of(i);
   1.201 -  scratch_class->set_method_default_annotations_of(i, scratch_class->get_method_default_annotations_of(j));
   1.202 -  scratch_class->set_method_default_annotations_of(j, save);
   1.203 +void VM_RedefineClasses::swap_all_method_annotations(int i, int j, instanceKlassHandle scratch_class, TRAPS) {
   1.204 +  AnnotationArray* save;
   1.205 +
   1.206 +  Annotations* sca = scratch_class->annotations();
   1.207 +  if (sca == NULL) return;
   1.208 +
   1.209 +  save = sca->get_method_annotations_of(i);
   1.210 +  sca->set_method_annotations_of(scratch_class, i, sca->get_method_annotations_of(j), CHECK);
   1.211 +  sca->set_method_annotations_of(scratch_class, j, save, CHECK);
   1.212 +
   1.213 +  save = sca->get_method_parameter_annotations_of(i);
   1.214 +  sca->set_method_parameter_annotations_of(scratch_class, i, sca->get_method_parameter_annotations_of(j), CHECK);
   1.215 +  sca->set_method_parameter_annotations_of(scratch_class, j, save, CHECK);
   1.216 +
   1.217 +  save = sca->get_method_default_annotations_of(i);
   1.218 +  sca->set_method_default_annotations_of(scratch_class, i, sca->get_method_default_annotations_of(j), CHECK);
   1.219 +  sca->set_method_default_annotations_of(scratch_class, j, save, CHECK);
   1.220  }
   1.221  
   1.222  
   1.223 @@ -524,15 +585,15 @@
   1.224    // technically a bit more difficult, and, more importantly, I am not sure at present that the
   1.225    // order of interfaces does not matter on the implementation level, i.e. that the VM does not
   1.226    // rely on it somewhere.
   1.227 -  objArrayOop k_interfaces = the_class->local_interfaces();
   1.228 -  objArrayOop k_new_interfaces = scratch_class->local_interfaces();
   1.229 +  Array<Klass*>* k_interfaces = the_class->local_interfaces();
   1.230 +  Array<Klass*>* k_new_interfaces = scratch_class->local_interfaces();
   1.231    int n_intfs = k_interfaces->length();
   1.232    if (n_intfs != k_new_interfaces->length()) {
   1.233      return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
   1.234    }
   1.235    for (i = 0; i < n_intfs; i++) {
   1.236 -    if (Klass::cast((klassOop) k_interfaces->obj_at(i))->name() !=
   1.237 -        Klass::cast((klassOop) k_new_interfaces->obj_at(i))->name()) {
   1.238 +    if (Klass::cast(k_interfaces->at(i))->name() !=
   1.239 +        Klass::cast(k_new_interfaces->at(i))->name()) {
   1.240        return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
   1.241      }
   1.242    }
   1.243 @@ -591,23 +652,24 @@
   1.244    // old methods in the same order as the old methods and places
   1.245    // new overloaded methods at the end of overloaded methods of
   1.246    // that name. The code for this order normalization is adapted
   1.247 -  // from the algorithm used in instanceKlass::find_method().
   1.248 +  // from the algorithm used in InstanceKlass::find_method().
   1.249    // Since we are swapping out of order entries as we find them,
   1.250    // we only have to search forward through the overloaded methods.
   1.251    // Methods which are added and have the same name as an existing
   1.252    // method (but different signature) will be put at the end of
   1.253    // the methods with that name, and the name mismatch code will
   1.254    // handle them.
   1.255 -  objArrayHandle k_old_methods(the_class->methods());
   1.256 -  objArrayHandle k_new_methods(scratch_class->methods());
   1.257 +  Array<Method*>* k_old_methods(the_class->methods());
   1.258 +  Array<Method*>* k_new_methods(scratch_class->methods());
   1.259    int n_old_methods = k_old_methods->length();
   1.260    int n_new_methods = k_new_methods->length();
   1.261 +  Thread* thread = Thread::current();
   1.262  
   1.263    int ni = 0;
   1.264    int oi = 0;
   1.265    while (true) {
   1.266 -    methodOop k_old_method;
   1.267 -    methodOop k_new_method;
   1.268 +    Method* k_old_method;
   1.269 +    Method* k_new_method;
   1.270      enum { matched, added, deleted, undetermined } method_was = undetermined;
   1.271  
   1.272      if (oi >= n_old_methods) {
   1.273 @@ -615,16 +677,16 @@
   1.274          break; // we've looked at everything, done
   1.275        }
   1.276        // New method at the end
   1.277 -      k_new_method = (methodOop) k_new_methods->obj_at(ni);
   1.278 +      k_new_method = k_new_methods->at(ni);
   1.279        method_was = added;
   1.280      } else if (ni >= n_new_methods) {
   1.281        // Old method, at the end, is deleted
   1.282 -      k_old_method = (methodOop) k_old_methods->obj_at(oi);
   1.283 +      k_old_method = k_old_methods->at(oi);
   1.284        method_was = deleted;
   1.285      } else {
   1.286        // There are more methods in both the old and new lists
   1.287 -      k_old_method = (methodOop) k_old_methods->obj_at(oi);
   1.288 -      k_new_method = (methodOop) k_new_methods->obj_at(ni);
   1.289 +      k_old_method = k_old_methods->at(oi);
   1.290 +      k_new_method = k_new_methods->at(ni);
   1.291        if (k_old_method->name() != k_new_method->name()) {
   1.292          // Methods are sorted by method name, so a mismatch means added
   1.293          // or deleted
   1.294 @@ -641,7 +703,7 @@
   1.295          // search forward through the new overloaded methods.
   1.296          int nj;  // outside the loop for post-loop check
   1.297          for (nj = ni + 1; nj < n_new_methods; nj++) {
   1.298 -          methodOop m = (methodOop)k_new_methods->obj_at(nj);
   1.299 +          Method* m = k_new_methods->at(nj);
   1.300            if (k_old_method->name() != m->name()) {
   1.301              // reached another method name so no more overloaded methods
   1.302              method_was = deleted;
   1.303 @@ -649,8 +711,8 @@
   1.304            }
   1.305            if (k_old_method->signature() == m->signature()) {
   1.306              // found a match so swap the methods
   1.307 -            k_new_methods->obj_at_put(ni, m);
   1.308 -            k_new_methods->obj_at_put(nj, k_new_method);
   1.309 +            k_new_methods->at_put(ni, m);
   1.310 +            k_new_methods->at_put(nj, k_new_method);
   1.311              k_new_method = m;
   1.312              method_was = matched;
   1.313              break;
   1.314 @@ -676,13 +738,16 @@
   1.315          u2 new_num = k_new_method->method_idnum();
   1.316          u2 old_num = k_old_method->method_idnum();
   1.317          if (new_num != old_num) {
   1.318 -          methodOop idnum_owner = scratch_class->method_with_idnum(old_num);
   1.319 +          Method* idnum_owner = scratch_class->method_with_idnum(old_num);
   1.320            if (idnum_owner != NULL) {
   1.321              // There is already a method assigned this idnum -- switch them
   1.322              idnum_owner->set_method_idnum(new_num);
   1.323            }
   1.324            k_new_method->set_method_idnum(old_num);
   1.325 -          swap_all_method_annotations(old_num, new_num, scratch_class);
   1.326 +          swap_all_method_annotations(old_num, new_num, scratch_class, thread);
   1.327 +           if (thread->has_pending_exception()) {
   1.328 +             return JVMTI_ERROR_OUT_OF_MEMORY;
   1.329 +           }
   1.330          }
   1.331        }
   1.332        RC_TRACE(0x00008000, ("Method matched: new: %s [%d] == old: %s [%d]",
   1.333 @@ -704,18 +769,21 @@
   1.334        }
   1.335        {
   1.336          u2 num = the_class->next_method_idnum();
   1.337 -        if (num == constMethodOopDesc::UNSET_IDNUM) {
   1.338 +        if (num == ConstMethod::UNSET_IDNUM) {
   1.339            // cannot add any more methods
   1.340            return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED;
   1.341          }
   1.342          u2 new_num = k_new_method->method_idnum();
   1.343 -        methodOop idnum_owner = scratch_class->method_with_idnum(num);
   1.344 +        Method* idnum_owner = scratch_class->method_with_idnum(num);
   1.345          if (idnum_owner != NULL) {
   1.346            // There is already a method assigned this idnum -- switch them
   1.347            idnum_owner->set_method_idnum(new_num);
   1.348          }
   1.349          k_new_method->set_method_idnum(num);
   1.350 -        swap_all_method_annotations(new_num, num, scratch_class);
   1.351 +        swap_all_method_annotations(new_num, num, scratch_class, thread);
   1.352 +        if (thread->has_pending_exception()) {
   1.353 +          return JVMTI_ERROR_OUT_OF_MEMORY;
   1.354 +        }
   1.355        }
   1.356        RC_TRACE(0x00008000, ("Method added: new: %s [%d]",
   1.357                              k_new_method->name_and_sig_as_C_string(), ni));
   1.358 @@ -799,42 +867,18 @@
   1.359  } // end is_unresolved_class_mismatch()
   1.360  
   1.361  
   1.362 -// Returns true if the current mismatch is due to a resolved/unresolved
   1.363 -// string pair. Otherwise, returns false.
   1.364 -bool VM_RedefineClasses::is_unresolved_string_mismatch(constantPoolHandle cp1,
   1.365 -       int index1, constantPoolHandle cp2, int index2) {
   1.366 -
   1.367 -  jbyte t1 = cp1->tag_at(index1).value();
   1.368 -  if (t1 != JVM_CONSTANT_String && t1 != JVM_CONSTANT_UnresolvedString) {
   1.369 -    return false;  // wrong entry type; not our special case
   1.370 -  }
   1.371 -
   1.372 -  jbyte t2 = cp2->tag_at(index2).value();
   1.373 -  if (t2 != JVM_CONSTANT_String && t2 != JVM_CONSTANT_UnresolvedString) {
   1.374 -    return false;  // wrong entry type; not our special case
   1.375 -  }
   1.376 -
   1.377 -  if (t1 == t2) {
   1.378 -    return false;  // not a mismatch; not our special case
   1.379 -  }
   1.380 -
   1.381 -  char *s1 = cp1->string_at_noresolve(index1);
   1.382 -  char *s2 = cp2->string_at_noresolve(index2);
   1.383 -  if (strcmp(s1, s2) != 0) {
   1.384 -    return false;  // strings don't match; not our special case
   1.385 -  }
   1.386 -
   1.387 -  return true;  // made it through the gauntlet; this is our special case
   1.388 -} // end is_unresolved_string_mismatch()
   1.389 -
   1.390 -
   1.391  jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) {
   1.392 +
   1.393    // For consistency allocate memory using os::malloc wrapper.
   1.394 -  _scratch_classes = (instanceKlassHandle *)
   1.395 -    os::malloc(sizeof(instanceKlassHandle) * _class_count, mtInternal);
   1.396 +  _scratch_classes = (Klass**)
   1.397 +    os::malloc(sizeof(Klass*) * _class_count, mtClass);
   1.398    if (_scratch_classes == NULL) {
   1.399      return JVMTI_ERROR_OUT_OF_MEMORY;
   1.400    }
   1.401 +  // Zero initialize the _scratch_classes array.
   1.402 +  for (int i = 0; i < _class_count; i++) {
   1.403 +    _scratch_classes[i] = NULL;
   1.404 +  }
   1.405  
   1.406    ResourceMark rm(THREAD);
   1.407  
   1.408 @@ -843,12 +887,17 @@
   1.409    // should not happen since we're trying to do a RedefineClasses
   1.410    guarantee(state != NULL, "exiting thread calling load_new_class_versions");
   1.411    for (int i = 0; i < _class_count; i++) {
   1.412 +    // Create HandleMark so that any handles created while loading new class
   1.413 +    // versions are deleted. Constant pools are deallocated while merging
   1.414 +    // constant pools
   1.415 +    HandleMark hm(THREAD);
   1.416 +
   1.417      oop mirror = JNIHandles::resolve_non_null(_class_defs[i].klass);
   1.418      // classes for primitives cannot be redefined
   1.419      if (!is_modifiable_class(mirror)) {
   1.420        return JVMTI_ERROR_UNMODIFIABLE_CLASS;
   1.421      }
   1.422 -    klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
   1.423 +    Klass* the_class_oop = java_lang_Class::as_Klass(mirror);
   1.424      instanceKlassHandle the_class = instanceKlassHandle(THREAD, the_class_oop);
   1.425      Symbol*  the_class_sym = the_class->name();
   1.426  
   1.427 @@ -869,7 +918,7 @@
   1.428      // load hook event.
   1.429      state->set_class_being_redefined(&the_class, _class_load_kind);
   1.430  
   1.431 -    klassOop k = SystemDictionary::parse_stream(the_class_sym,
   1.432 +    Klass* k = SystemDictionary::parse_stream(the_class_sym,
   1.433                                                  the_class_loader,
   1.434                                                  protection_domain,
   1.435                                                  &st,
   1.436 @@ -881,8 +930,13 @@
   1.437  
   1.438      instanceKlassHandle scratch_class (THREAD, k);
   1.439  
   1.440 +    // Need to clean up allocated InstanceKlass if there's an error so assign
   1.441 +    // the result here. Caller deallocates all the scratch classes in case of
   1.442 +    // an error.
   1.443 +    _scratch_classes[i] = k;
   1.444 +
   1.445      if (HAS_PENDING_EXCEPTION) {
   1.446 -      Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
   1.447 +      Symbol* ex_name = PENDING_EXCEPTION->klass()->name();
   1.448        // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
   1.449        RC_TRACE_WITH_THREAD(0x00000002, THREAD, ("parse_stream exception: '%s'",
   1.450          ex_name->as_C_string()));
   1.451 @@ -908,7 +962,7 @@
   1.452      if (!the_class->is_linked()) {
   1.453        the_class->link_class(THREAD);
   1.454        if (HAS_PENDING_EXCEPTION) {
   1.455 -        Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
   1.456 +        Symbol* ex_name = PENDING_EXCEPTION->klass()->name();
   1.457          // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
   1.458          RC_TRACE_WITH_THREAD(0x00000002, THREAD, ("link_class exception: '%s'",
   1.459            ex_name->as_C_string()));
   1.460 @@ -946,7 +1000,7 @@
   1.461      }
   1.462  
   1.463      if (HAS_PENDING_EXCEPTION) {
   1.464 -      Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
   1.465 +      Symbol* ex_name = PENDING_EXCEPTION->klass()->name();
   1.466        // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
   1.467        RC_TRACE_WITH_THREAD(0x00000002, THREAD,
   1.468          ("verify_byte_codes exception: '%s'", ex_name->as_C_string()));
   1.469 @@ -972,7 +1026,7 @@
   1.470        }
   1.471  
   1.472        if (HAS_PENDING_EXCEPTION) {
   1.473 -        Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
   1.474 +        Symbol* ex_name = PENDING_EXCEPTION->klass()->name();
   1.475          // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
   1.476          RC_TRACE_WITH_THREAD(0x00000002, THREAD,
   1.477            ("verify_byte_codes post merge-CP exception: '%s'",
   1.478 @@ -992,7 +1046,7 @@
   1.479        Rewriter::relocate_and_link(scratch_class, THREAD);
   1.480      }
   1.481      if (HAS_PENDING_EXCEPTION) {
   1.482 -      Symbol* ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
   1.483 +      Symbol* ex_name = PENDING_EXCEPTION->klass()->name();
   1.484        CLEAR_PENDING_EXCEPTION;
   1.485        if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
   1.486          return JVMTI_ERROR_OUT_OF_MEMORY;
   1.487 @@ -1001,8 +1055,6 @@
   1.488        }
   1.489      }
   1.490  
   1.491 -    _scratch_classes[i] = scratch_class;
   1.492 -
   1.493      // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
   1.494      RC_TRACE_WITH_THREAD(0x00000001, THREAD,
   1.495        ("loaded name=%s (avail_mem=" UINT64_FORMAT "K)",
   1.496 @@ -1047,11 +1099,11 @@
   1.497         int *merge_cp_length_p, TRAPS) {
   1.498  
   1.499    if (merge_cp_p == NULL) {
   1.500 -    assert(false, "caller must provide scatch constantPool");
   1.501 +    assert(false, "caller must provide scratch constantPool");
   1.502      return false; // robustness
   1.503    }
   1.504    if (merge_cp_length_p == NULL) {
   1.505 -    assert(false, "caller must provide scatch CP length");
   1.506 +    assert(false, "caller must provide scratch CP length");
   1.507      return false; // robustness
   1.508    }
   1.509    // Worst case we need old_cp->length() + scratch_cp()->length(),
   1.510 @@ -1070,7 +1122,7 @@
   1.511      // Pass 0:
   1.512      // The old_cp is copied to *merge_cp_p; this means that any code
   1.513      // using old_cp does not have to change. This work looks like a
   1.514 -    // perfect fit for constantPoolOop::copy_cp_to(), but we need to
   1.515 +    // perfect fit for ConstantPool*::copy_cp_to(), but we need to
   1.516      // handle one special case:
   1.517      // - revert JVM_CONSTANT_Class to JVM_CONSTANT_UnresolvedClass
   1.518      // This will make verification happy.
   1.519 @@ -1095,13 +1147,13 @@
   1.520        case JVM_CONSTANT_Long:
   1.521          // just copy the entry to *merge_cp_p, but double and long take
   1.522          // two constant pool entries
   1.523 -        constantPoolOopDesc::copy_entry_to(old_cp, old_i, *merge_cp_p, old_i, CHECK_0);
   1.524 +        ConstantPool::copy_entry_to(old_cp, old_i, *merge_cp_p, old_i, CHECK_0);
   1.525          old_i++;
   1.526          break;
   1.527  
   1.528        default:
   1.529          // just copy the entry to *merge_cp_p
   1.530 -        constantPoolOopDesc::copy_entry_to(old_cp, old_i, *merge_cp_p, old_i, CHECK_0);
   1.531 +        ConstantPool::copy_entry_to(old_cp, old_i, *merge_cp_p, old_i, CHECK_0);
   1.532          break;
   1.533        }
   1.534      } // end for each old_cp entry
   1.535 @@ -1151,13 +1203,6 @@
   1.536          // class entries to unresolved class entries in *merge_cp_p,
   1.537          // we go with the unresolved class entry.
   1.538          continue;
   1.539 -      } else if (is_unresolved_string_mismatch(scratch_cp, scratch_i,
   1.540 -                                               *merge_cp_p, scratch_i)) {
   1.541 -        // The mismatch in compare_entry_to() above is because of a
   1.542 -        // resolved versus unresolved string entry at the same index
   1.543 -        // with the same string value. We can live with whichever
   1.544 -        // happens to be at scratch_i in *merge_cp_p.
   1.545 -        continue;
   1.546        }
   1.547  
   1.548        int found_i = scratch_cp->find_matching_entry(scratch_i, *merge_cp_p,
   1.549 @@ -1233,6 +1278,23 @@
   1.550  } // end merge_constant_pools()
   1.551  
   1.552  
   1.553 +// Scoped object to clean up the constant pool(s) created for merging
   1.554 +class MergeCPCleaner {
   1.555 +  ClassLoaderData*   _loader_data;
   1.556 +  ConstantPool*      _cp;
   1.557 +  ConstantPool*      _scratch_cp;
   1.558 + public:
   1.559 +  MergeCPCleaner(ClassLoaderData* loader_data, ConstantPool* merge_cp) :
   1.560 +                 _loader_data(loader_data), _cp(merge_cp), _scratch_cp(NULL) {}
   1.561 +  ~MergeCPCleaner() {
   1.562 +    _loader_data->add_to_deallocate_list(_cp);
   1.563 +    if (_scratch_cp != NULL) {
   1.564 +      _loader_data->add_to_deallocate_list(_scratch_cp);
   1.565 +    }
   1.566 +  }
   1.567 +  void add_scratch_cp(ConstantPool* scratch_cp) { _scratch_cp = scratch_cp; }
   1.568 +};
   1.569 +
   1.570  // Merge constant pools between the_class and scratch_class and
   1.571  // potentially rewrite bytecodes in scratch_class to use the merged
   1.572  // constant pool.
   1.573 @@ -1243,19 +1305,35 @@
   1.574    int merge_cp_length = the_class->constants()->length()
   1.575          + scratch_class->constants()->length();
   1.576  
   1.577 -  constantPoolHandle old_cp(THREAD, the_class->constants());
   1.578 -  constantPoolHandle scratch_cp(THREAD, scratch_class->constants());
   1.579 -
   1.580    // Constant pools are not easily reused so we allocate a new one
   1.581    // each time.
   1.582    // merge_cp is created unsafe for concurrent GC processing.  It
   1.583    // should be marked safe before discarding it. Even though
   1.584    // garbage,  if it crosses a card boundary, it may be scanned
   1.585    // in order to find the start of the first complete object on the card.
   1.586 -  constantPoolHandle merge_cp(THREAD,
   1.587 -    oopFactory::new_constantPool(merge_cp_length,
   1.588 -                                 oopDesc::IsUnsafeConc,
   1.589 -                                 THREAD));
   1.590 +  ClassLoaderData* loader_data = the_class->class_loader_data();
   1.591 +  ConstantPool* merge_cp_oop =
   1.592 +    ConstantPool::allocate(loader_data,
   1.593 +                                  merge_cp_length,
   1.594 +                                  THREAD);
   1.595 +  MergeCPCleaner cp_cleaner(loader_data, merge_cp_oop);
   1.596 +
   1.597 +  HandleMark hm(THREAD);  // make sure handles are cleared before
   1.598 +                          // MergeCPCleaner clears out merge_cp_oop
   1.599 +  constantPoolHandle merge_cp(THREAD, merge_cp_oop);
   1.600 +
   1.601 +  // Get constants() from the old class because it could have been rewritten
   1.602 +  // while we were at a safepoint allocating a new constant pool.
   1.603 +  constantPoolHandle old_cp(THREAD, the_class->constants());
   1.604 +  constantPoolHandle scratch_cp(THREAD, scratch_class->constants());
   1.605 +
   1.606 +  // If the length changed, the class was redefined out from under us. Return
   1.607 +  // an error.
   1.608 +  if (merge_cp_length != the_class->constants()->length()
   1.609 +         + scratch_class->constants()->length()) {
   1.610 +    return JVMTI_ERROR_INTERNAL;
   1.611 +  }
   1.612 +
   1.613    int orig_length = old_cp->orig_length();
   1.614    if (orig_length == 0) {
   1.615      // This old_cp is an actual original constant pool. We save
   1.616 @@ -1298,8 +1376,7 @@
   1.617        // rewriting so we can't use the old constant pool with the new
   1.618        // class.
   1.619  
   1.620 -      merge_cp()->set_is_conc_safe(true);
   1.621 -      merge_cp = constantPoolHandle();  // toss the merged constant pool
   1.622 +      // toss the merged constant pool at return
   1.623      } else if (old_cp->length() < scratch_cp->length()) {
   1.624        // The old constant pool has fewer entries than the new constant
   1.625        // pool and the index map is empty. This means the new constant
   1.626 @@ -1308,8 +1385,7 @@
   1.627        // rewriting so we can't use the new constant pool with the old
   1.628        // class.
   1.629  
   1.630 -      merge_cp()->set_is_conc_safe(true);
   1.631 -      merge_cp = constantPoolHandle();  // toss the merged constant pool
   1.632 +      // toss the merged constant pool at return
   1.633      } else {
   1.634        // The old constant pool has more entries than the new constant
   1.635        // pool and the index map is empty. This means that both the old
   1.636 @@ -1317,13 +1393,11 @@
   1.637        // pool.
   1.638  
   1.639        // Replace the new constant pool with a shrunken copy of the
   1.640 -      // merged constant pool; the previous new constant pool will
   1.641 -      // get GCed.
   1.642 -      set_new_constant_pool(scratch_class, merge_cp, merge_cp_length, true,
   1.643 -        THREAD);
   1.644 -      // drop local ref to the merged constant pool
   1.645 -      merge_cp()->set_is_conc_safe(true);
   1.646 -      merge_cp = constantPoolHandle();
   1.647 +      // merged constant pool
   1.648 +      set_new_constant_pool(loader_data, scratch_class, merge_cp, merge_cp_length, THREAD);
   1.649 +      // The new constant pool replaces scratch_cp so have cleaner clean it up.
   1.650 +      // It can't be cleaned up while there are handles to it.
   1.651 +      cp_cleaner.add_scratch_cp(scratch_cp());
   1.652      }
   1.653    } else {
   1.654      if (RC_TRACE_ENABLED(0x00040000)) {
   1.655 @@ -1350,12 +1424,11 @@
   1.656      // merged constant pool so now the rewritten bytecodes have
   1.657      // valid references; the previous new constant pool will get
   1.658      // GCed.
   1.659 -    set_new_constant_pool(scratch_class, merge_cp, merge_cp_length, true,
   1.660 -      THREAD);
   1.661 -    merge_cp()->set_is_conc_safe(true);
   1.662 +    set_new_constant_pool(loader_data, scratch_class, merge_cp, merge_cp_length, THREAD);
   1.663 +    // The new constant pool replaces scratch_cp so have cleaner clean it up.
   1.664 +    // It can't be cleaned up while there are handles to it.
   1.665 +    cp_cleaner.add_scratch_cp(scratch_cp());
   1.666    }
   1.667 -  assert(old_cp()->is_conc_safe(), "Just checking");
   1.668 -  assert(scratch_cp()->is_conc_safe(), "Just checking");
   1.669  
   1.670    return JVMTI_ERROR_NONE;
   1.671  } // end merge_cp_and_rewrite()
   1.672 @@ -1411,21 +1484,21 @@
   1.673  bool VM_RedefineClasses::rewrite_cp_refs_in_methods(
   1.674         instanceKlassHandle scratch_class, TRAPS) {
   1.675  
   1.676 -  objArrayHandle methods(THREAD, scratch_class->methods());
   1.677 -
   1.678 -  if (methods.is_null() || methods->length() == 0) {
   1.679 +  Array<Method*>* methods = scratch_class->methods();
   1.680 +
   1.681 +  if (methods == NULL || methods->length() == 0) {
   1.682      // no methods so nothing to do
   1.683      return true;
   1.684    }
   1.685  
   1.686    // rewrite constant pool references in the methods:
   1.687    for (int i = methods->length() - 1; i >= 0; i--) {
   1.688 -    methodHandle method(THREAD, (methodOop)methods->obj_at(i));
   1.689 +    methodHandle method(THREAD, methods->at(i));
   1.690      methodHandle new_method;
   1.691      rewrite_cp_refs_in_method(method, &new_method, CHECK_false);
   1.692      if (!new_method.is_null()) {
   1.693        // the method has been replaced so save the new method version
   1.694 -      methods->obj_at_put(i, new_method());
   1.695 +      methods->at_put(i, new_method());
   1.696      }
   1.697    }
   1.698  
   1.699 @@ -1441,7 +1514,7 @@
   1.700    *new_method_p = methodHandle();  // default is no new method
   1.701  
   1.702    // We cache a pointer to the bytecodes here in code_base. If GC
   1.703 -  // moves the methodOop, then the bytecodes will also move which
   1.704 +  // moves the Method*, then the bytecodes will also move which
   1.705    // will likely cause a crash. We create a No_Safepoint_Verifier
   1.706    // object to detect whether we pass a possible safepoint in this
   1.707    // code block.
   1.708 @@ -1570,9 +1643,8 @@
   1.709  bool VM_RedefineClasses::rewrite_cp_refs_in_class_annotations(
   1.710         instanceKlassHandle scratch_class, TRAPS) {
   1.711  
   1.712 -  typeArrayHandle class_annotations(THREAD,
   1.713 -    scratch_class->class_annotations());
   1.714 -  if (class_annotations.is_null() || class_annotations->length() == 0) {
   1.715 +  AnnotationArray* class_annotations = scratch_class->class_annotations();
   1.716 +  if (class_annotations == NULL || class_annotations->length() == 0) {
   1.717      // no class_annotations so nothing to do
   1.718      return true;
   1.719    }
   1.720 @@ -1596,7 +1668,7 @@
   1.721  // }
   1.722  //
   1.723  bool VM_RedefineClasses::rewrite_cp_refs_in_annotations_typeArray(
   1.724 -       typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
   1.725 +       AnnotationArray* annotations_typeArray, int &byte_i_ref, TRAPS) {
   1.726  
   1.727    if ((byte_i_ref + 2) > annotations_typeArray->length()) {
   1.728      // not enough room for num_annotations field
   1.729 @@ -1606,7 +1678,7 @@
   1.730    }
   1.731  
   1.732    u2 num_annotations = Bytes::get_Java_u2((address)
   1.733 -                         annotations_typeArray->byte_at_addr(byte_i_ref));
   1.734 +                         annotations_typeArray->adr_at(byte_i_ref));
   1.735    byte_i_ref += 2;
   1.736  
   1.737    RC_TRACE_WITH_THREAD(0x02000000, THREAD,
   1.738 @@ -1642,7 +1714,7 @@
   1.739  // }
   1.740  //
   1.741  bool VM_RedefineClasses::rewrite_cp_refs_in_annotation_struct(
   1.742 -       typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
   1.743 +       AnnotationArray* annotations_typeArray, int &byte_i_ref, TRAPS) {
   1.744    if ((byte_i_ref + 2 + 2) > annotations_typeArray->length()) {
   1.745      // not enough room for smallest annotation_struct
   1.746      RC_TRACE_WITH_THREAD(0x02000000, THREAD,
   1.747 @@ -1654,8 +1726,7 @@
   1.748                      byte_i_ref, "mapped old type_index=%d", THREAD);
   1.749  
   1.750    u2 num_element_value_pairs = Bytes::get_Java_u2((address)
   1.751 -                                 annotations_typeArray->byte_at_addr(
   1.752 -                                 byte_i_ref));
   1.753 +                                 annotations_typeArray->adr_at(byte_i_ref));
   1.754    byte_i_ref += 2;
   1.755  
   1.756    RC_TRACE_WITH_THREAD(0x02000000, THREAD,
   1.757 @@ -1700,11 +1771,11 @@
   1.758  // pool reference if a rewrite was not needed or the new constant
   1.759  // pool reference if a rewrite was needed.
   1.760  u2 VM_RedefineClasses::rewrite_cp_ref_in_annotation_data(
   1.761 -     typeArrayHandle annotations_typeArray, int &byte_i_ref,
   1.762 +     AnnotationArray* annotations_typeArray, int &byte_i_ref,
   1.763       const char * trace_mesg, TRAPS) {
   1.764  
   1.765    address cp_index_addr = (address)
   1.766 -    annotations_typeArray->byte_at_addr(byte_i_ref);
   1.767 +    annotations_typeArray->adr_at(byte_i_ref);
   1.768    u2 old_cp_index = Bytes::get_Java_u2(cp_index_addr);
   1.769    u2 new_cp_index = find_new_index(old_cp_index);
   1.770    if (new_cp_index != 0) {
   1.771 @@ -1739,7 +1810,7 @@
   1.772  // }
   1.773  //
   1.774  bool VM_RedefineClasses::rewrite_cp_refs_in_element_value(
   1.775 -       typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
   1.776 +       AnnotationArray* annotations_typeArray, int &byte_i_ref, TRAPS) {
   1.777  
   1.778    if ((byte_i_ref + 1) > annotations_typeArray->length()) {
   1.779      // not enough room for a tag let alone the rest of an element_value
   1.780 @@ -1748,7 +1819,7 @@
   1.781      return false;
   1.782    }
   1.783  
   1.784 -  u1 tag = annotations_typeArray->byte_at(byte_i_ref);
   1.785 +  u1 tag = annotations_typeArray->at(byte_i_ref);
   1.786    byte_i_ref++;
   1.787    RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("tag='%c'", tag));
   1.788  
   1.789 @@ -1850,7 +1921,7 @@
   1.790        // For the above tag value, value.array_value is the right union
   1.791        // field. This is an array of nested element_value.
   1.792        u2 num_values = Bytes::get_Java_u2((address)
   1.793 -                        annotations_typeArray->byte_at_addr(byte_i_ref));
   1.794 +                        annotations_typeArray->adr_at(byte_i_ref));
   1.795        byte_i_ref += 2;
   1.796        RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("num_values=%d", num_values));
   1.797  
   1.798 @@ -1880,10 +1951,12 @@
   1.799  bool VM_RedefineClasses::rewrite_cp_refs_in_fields_annotations(
   1.800         instanceKlassHandle scratch_class, TRAPS) {
   1.801  
   1.802 -  objArrayHandle fields_annotations(THREAD,
   1.803 -    scratch_class->fields_annotations());
   1.804 -
   1.805 -  if (fields_annotations.is_null() || fields_annotations->length() == 0) {
   1.806 +  Annotations* sca = scratch_class->annotations();
   1.807 +  if (sca == NULL) return true;
   1.808 +
   1.809 +  Array<AnnotationArray*>* fields_annotations = sca->fields_annotations();
   1.810 +
   1.811 +  if (fields_annotations == NULL || fields_annotations->length() == 0) {
   1.812      // no fields_annotations so nothing to do
   1.813      return true;
   1.814    }
   1.815 @@ -1892,9 +1965,8 @@
   1.816      ("fields_annotations length=%d", fields_annotations->length()));
   1.817  
   1.818    for (int i = 0; i < fields_annotations->length(); i++) {
   1.819 -    typeArrayHandle field_annotations(THREAD,
   1.820 -      (typeArrayOop)fields_annotations->obj_at(i));
   1.821 -    if (field_annotations.is_null() || field_annotations->length() == 0) {
   1.822 +    AnnotationArray* field_annotations = fields_annotations->at(i);
   1.823 +    if (field_annotations == NULL || field_annotations->length() == 0) {
   1.824        // this field does not have any annotations so skip it
   1.825        continue;
   1.826      }
   1.827 @@ -1917,10 +1989,12 @@
   1.828  bool VM_RedefineClasses::rewrite_cp_refs_in_methods_annotations(
   1.829         instanceKlassHandle scratch_class, TRAPS) {
   1.830  
   1.831 -  objArrayHandle methods_annotations(THREAD,
   1.832 -    scratch_class->methods_annotations());
   1.833 -
   1.834 -  if (methods_annotations.is_null() || methods_annotations->length() == 0) {
   1.835 +  Annotations* sca = scratch_class->annotations();
   1.836 +  if (sca == NULL) return true;
   1.837 +
   1.838 +  Array<AnnotationArray*>* methods_annotations = sca->methods_annotations();
   1.839 +
   1.840 +  if (methods_annotations == NULL || methods_annotations->length() == 0) {
   1.841      // no methods_annotations so nothing to do
   1.842      return true;
   1.843    }
   1.844 @@ -1929,9 +2003,8 @@
   1.845      ("methods_annotations length=%d", methods_annotations->length()));
   1.846  
   1.847    for (int i = 0; i < methods_annotations->length(); i++) {
   1.848 -    typeArrayHandle method_annotations(THREAD,
   1.849 -      (typeArrayOop)methods_annotations->obj_at(i));
   1.850 -    if (method_annotations.is_null() || method_annotations->length() == 0) {
   1.851 +    AnnotationArray* method_annotations = methods_annotations->at(i);
   1.852 +    if (method_annotations == NULL || method_annotations->length() == 0) {
   1.853        // this method does not have any annotations so skip it
   1.854        continue;
   1.855      }
   1.856 @@ -1966,10 +2039,13 @@
   1.857  bool VM_RedefineClasses::rewrite_cp_refs_in_methods_parameter_annotations(
   1.858         instanceKlassHandle scratch_class, TRAPS) {
   1.859  
   1.860 -  objArrayHandle methods_parameter_annotations(THREAD,
   1.861 -    scratch_class->methods_parameter_annotations());
   1.862 -
   1.863 -  if (methods_parameter_annotations.is_null()
   1.864 +  Annotations* sca = scratch_class->annotations();
   1.865 +  if (sca == NULL) return true;
   1.866 +
   1.867 +  Array<AnnotationArray*>* methods_parameter_annotations =
   1.868 +    sca->methods_parameter_annotations();
   1.869 +
   1.870 +  if (methods_parameter_annotations == NULL
   1.871        || methods_parameter_annotations->length() == 0) {
   1.872      // no methods_parameter_annotations so nothing to do
   1.873      return true;
   1.874 @@ -1980,9 +2056,8 @@
   1.875      methods_parameter_annotations->length()));
   1.876  
   1.877    for (int i = 0; i < methods_parameter_annotations->length(); i++) {
   1.878 -    typeArrayHandle method_parameter_annotations(THREAD,
   1.879 -      (typeArrayOop)methods_parameter_annotations->obj_at(i));
   1.880 -    if (method_parameter_annotations.is_null()
   1.881 +    AnnotationArray* method_parameter_annotations = methods_parameter_annotations->at(i);
   1.882 +    if (method_parameter_annotations == NULL
   1.883          || method_parameter_annotations->length() == 0) {
   1.884        // this method does not have any parameter annotations so skip it
   1.885        continue;
   1.886 @@ -1997,7 +2072,7 @@
   1.887  
   1.888      int byte_i = 0;  // byte index into method_parameter_annotations
   1.889  
   1.890 -    u1 num_parameters = method_parameter_annotations->byte_at(byte_i);
   1.891 +    u1 num_parameters = method_parameter_annotations->at(byte_i);
   1.892      byte_i++;
   1.893  
   1.894      RC_TRACE_WITH_THREAD(0x02000000, THREAD,
   1.895 @@ -2031,10 +2106,13 @@
   1.896  bool VM_RedefineClasses::rewrite_cp_refs_in_methods_default_annotations(
   1.897         instanceKlassHandle scratch_class, TRAPS) {
   1.898  
   1.899 -  objArrayHandle methods_default_annotations(THREAD,
   1.900 -    scratch_class->methods_default_annotations());
   1.901 -
   1.902 -  if (methods_default_annotations.is_null()
   1.903 +  Annotations* sca = scratch_class->annotations();
   1.904 +  if (sca == NULL) return true;
   1.905 +
   1.906 +  Array<AnnotationArray*>* methods_default_annotations =
   1.907 +    sca->methods_default_annotations();
   1.908 +
   1.909 +  if (methods_default_annotations == NULL
   1.910        || methods_default_annotations->length() == 0) {
   1.911      // no methods_default_annotations so nothing to do
   1.912      return true;
   1.913 @@ -2045,9 +2123,8 @@
   1.914      methods_default_annotations->length()));
   1.915  
   1.916    for (int i = 0; i < methods_default_annotations->length(); i++) {
   1.917 -    typeArrayHandle method_default_annotations(THREAD,
   1.918 -      (typeArrayOop)methods_default_annotations->obj_at(i));
   1.919 -    if (method_default_annotations.is_null()
   1.920 +    AnnotationArray* method_default_annotations = methods_default_annotations->at(i);
   1.921 +    if (method_default_annotations == NULL
   1.922          || method_default_annotations->length() == 0) {
   1.923        // this method does not have any default annotations so skip it
   1.924        continue;
   1.925 @@ -2086,8 +2163,8 @@
   1.926      return;
   1.927    }
   1.928  
   1.929 -  typeArrayOop stackmap_data = method->stackmap_data();
   1.930 -  address stackmap_p = (address)stackmap_data->byte_at_addr(0);
   1.931 +  AnnotationArray* stackmap_data = method->stackmap_data();
   1.932 +  address stackmap_p = (address)stackmap_data->adr_at(0);
   1.933    address stackmap_end = stackmap_p + stackmap_data->length();
   1.934  
   1.935    assert(stackmap_p + 2 <= stackmap_end, "no room for number_of_entries");
   1.936 @@ -2335,17 +2412,16 @@
   1.937  // are copied from scratch_cp to a smaller constant pool and the
   1.938  // smaller constant pool is associated with scratch_class.
   1.939  void VM_RedefineClasses::set_new_constant_pool(
   1.940 +       ClassLoaderData* loader_data,
   1.941         instanceKlassHandle scratch_class, constantPoolHandle scratch_cp,
   1.942 -       int scratch_cp_length, bool shrink, TRAPS) {
   1.943 -  assert(!shrink || scratch_cp->length() >= scratch_cp_length, "sanity check");
   1.944 -
   1.945 -  if (shrink) {
   1.946 +       int scratch_cp_length, TRAPS) {
   1.947 +  assert(scratch_cp->length() >= scratch_cp_length, "sanity check");
   1.948 +
   1.949      // scratch_cp is a merged constant pool and has enough space for a
   1.950      // worst case merge situation. We want to associate the minimum
   1.951      // sized constant pool with the klass to save space.
   1.952      constantPoolHandle smaller_cp(THREAD,
   1.953 -      oopFactory::new_constantPool(scratch_cp_length,
   1.954 -                                   oopDesc::IsUnsafeConc,
   1.955 +    ConstantPool::allocate(loader_data, scratch_cp_length,
   1.956                                     THREAD));
   1.957      // preserve orig_length() value in the smaller copy
   1.958      int orig_length = scratch_cp->orig_length();
   1.959 @@ -2353,8 +2429,6 @@
   1.960      smaller_cp->set_orig_length(orig_length);
   1.961      scratch_cp->copy_cp_to(1, scratch_cp_length - 1, smaller_cp, 1, THREAD);
   1.962      scratch_cp = smaller_cp;
   1.963 -    smaller_cp()->set_is_conc_safe(true);
   1.964 -  }
   1.965  
   1.966    // attach new constant pool to klass
   1.967    scratch_cp->set_pool_holder(scratch_class());
   1.968 @@ -2430,9 +2504,9 @@
   1.969  
   1.970    // Attach each method in klass to the new constant pool and update
   1.971    // to use new constant pool indices as needed:
   1.972 -  objArrayHandle methods(THREAD, scratch_class->methods());
   1.973 +  Array<Method*>* methods = scratch_class->methods();
   1.974    for (i = methods->length() - 1; i >= 0; i--) {
   1.975 -    methodHandle method(THREAD, (methodOop)methods->obj_at(i));
   1.976 +    methodHandle method(THREAD, methods->at(i));
   1.977      method->set_constants(scratch_cp());
   1.978  
   1.979      int new_index = find_new_index(method->name_index());
   1.980 @@ -2528,10 +2602,18 @@
   1.981  
   1.982      rewrite_cp_refs_in_stack_map_table(method, THREAD);
   1.983    } // end for each method
   1.984 -  assert(scratch_cp()->is_conc_safe(), "Just checking");
   1.985  } // end set_new_constant_pool()
   1.986  
   1.987  
   1.988 +void VM_RedefineClasses::adjust_array_vtable(Klass* k_oop) {
   1.989 +  arrayKlass* ak = arrayKlass::cast(k_oop);
   1.990 +  bool trace_name_printed = false;
   1.991 +  ak->vtable()->adjust_method_entries(_matching_old_methods,
   1.992 +                                      _matching_new_methods,
   1.993 +                                      _matching_methods_length,
   1.994 +                                      &trace_name_printed);
   1.995 +}
   1.996 +
   1.997  // Unevolving classes may point to methods of the_class directly
   1.998  // from their constant pool caches, itables, and/or vtables. We
   1.999  // use the SystemDictionary::classes_do() facility and this helper
  1.1000 @@ -2539,12 +2621,13 @@
  1.1001  //
  1.1002  // Note: We currently don't support updating the vtable in
  1.1003  // arrayKlassOops. See Open Issues in jvmtiRedefineClasses.hpp.
  1.1004 -void VM_RedefineClasses::adjust_cpool_cache_and_vtable(klassOop k_oop,
  1.1005 -       oop initiating_loader, TRAPS) {
  1.1006 -  Klass *k = k_oop->klass_part();
  1.1007 +void VM_RedefineClasses::adjust_cpool_cache_and_vtable(Klass* k_oop,
  1.1008 +       ClassLoaderData* initiating_loader,
  1.1009 +       TRAPS) {
  1.1010 +  Klass *k = k_oop;
  1.1011    if (k->oop_is_instance()) {
  1.1012      HandleMark hm(THREAD);
  1.1013 -    instanceKlass *ik = (instanceKlass *) k;
  1.1014 +    InstanceKlass *ik = (InstanceKlass *) k;
  1.1015  
  1.1016      // HotSpot specific optimization! HotSpot does not currently
  1.1017      // support delegation from the bootstrap class loader to a
  1.1018 @@ -2559,11 +2642,17 @@
  1.1019      // loader as its defining class loader, then we can skip all
  1.1020      // classes loaded by the bootstrap class loader.
  1.1021      bool is_user_defined =
  1.1022 -           instanceKlass::cast(_the_class_oop)->class_loader() != NULL;
  1.1023 +           InstanceKlass::cast(_the_class_oop)->class_loader() != NULL;
  1.1024      if (is_user_defined && ik->class_loader() == NULL) {
  1.1025        return;
  1.1026      }
  1.1027  
  1.1028 +    // If the class being redefined is java.lang.Object, we need to fix all
  1.1029 +    // array class vtables also
  1.1030 +    if (_the_class_oop == SystemDictionary::Object_klass()) {
  1.1031 +      ik->array_klasses_do(adjust_array_vtable);
  1.1032 +    }
  1.1033 +
  1.1034      // This is a very busy routine. We don't want too much tracing
  1.1035      // printed out.
  1.1036      bool trace_name_printed = false;
  1.1037 @@ -2577,9 +2666,9 @@
  1.1038  
  1.1039      // Fix the vtable embedded in the_class and subclasses of the_class,
  1.1040      // if one exists. We discard scratch_class and we don't keep an
  1.1041 -    // instanceKlass around to hold obsolete methods so we don't have
  1.1042 -    // any other instanceKlass embedded vtables to update. The vtable
  1.1043 -    // holds the methodOops for virtual (but not final) methods.
  1.1044 +    // InstanceKlass around to hold obsolete methods so we don't have
  1.1045 +    // any other InstanceKlass embedded vtables to update. The vtable
  1.1046 +    // holds the Method*s for virtual (but not final) methods.
  1.1047      if (ik->vtable_length() > 0 && ik->is_subtype_of(_the_class_oop)) {
  1.1048        // ik->vtable() creates a wrapper object; rm cleans it up
  1.1049        ResourceMark rm(THREAD);
  1.1050 @@ -2593,8 +2682,8 @@
  1.1051      // interface or if the current class is a subclass of the_class, then
  1.1052      // we potentially have to fix the itable. If we are redefining an
  1.1053      // interface, then we have to call adjust_method_entries() for
  1.1054 -    // every instanceKlass that has an itable since there isn't a
  1.1055 -    // subclass relationship between an interface and an instanceKlass.
  1.1056 +    // every InstanceKlass that has an itable since there isn't a
  1.1057 +    // subclass relationship between an interface and an InstanceKlass.
  1.1058      if (ik->itable_length() > 0 && (Klass::cast(_the_class_oop)->is_interface()
  1.1059          || ik->is_subclass_of(_the_class_oop))) {
  1.1060        // ik->itable() creates a wrapper object; rm cleans it up
  1.1061 @@ -2609,7 +2698,7 @@
  1.1062      // methods in the_class. We have to update method information in
  1.1063      // other_cp's cache. If other_cp has a previous version, then we
  1.1064      // have to repeat the process for each previous version. The
  1.1065 -    // constant pool cache holds the methodOops for non-virtual
  1.1066 +    // constant pool cache holds the Method*s for non-virtual
  1.1067      // methods and for virtual, final methods.
  1.1068      //
  1.1069      // Special case: if the current class is the_class, then new_cp
  1.1070 @@ -2619,7 +2708,7 @@
  1.1071      // updated. We can simply start with the previous version(s) in
  1.1072      // that case.
  1.1073      constantPoolHandle other_cp;
  1.1074 -    constantPoolCacheOop cp_cache;
  1.1075 +    ConstantPoolCache* cp_cache;
  1.1076  
  1.1077      if (k_oop != _the_class_oop) {
  1.1078        // this klass' constant pool cache may need adjustment
  1.1079 @@ -2659,13 +2748,13 @@
  1.1080  
  1.1081  void VM_RedefineClasses::update_jmethod_ids() {
  1.1082    for (int j = 0; j < _matching_methods_length; ++j) {
  1.1083 -    methodOop old_method = _matching_old_methods[j];
  1.1084 +    Method* old_method = _matching_old_methods[j];
  1.1085      jmethodID jmid = old_method->find_jmethod_id_or_null();
  1.1086      if (jmid != NULL) {
  1.1087        // There is a jmethodID, change it to point to the new method
  1.1088        methodHandle new_method_h(_matching_new_methods[j]);
  1.1089 -      JNIHandles::change_method_associated_with_jmethod_id(jmid, new_method_h);
  1.1090 -      assert(JNIHandles::resolve_jmethod_id(jmid) == _matching_new_methods[j],
  1.1091 +      Method::change_method_associated_with_jmethod_id(jmid, new_method_h());
  1.1092 +      assert(Method::resolve_jmethod_id(jmid) == _matching_new_methods[j],
  1.1093               "should be replaced");
  1.1094      }
  1.1095    }
  1.1096 @@ -2677,14 +2766,13 @@
  1.1097    int obsolete_count = 0;
  1.1098    int old_index = 0;
  1.1099    for (int j = 0; j < _matching_methods_length; ++j, ++old_index) {
  1.1100 -    methodOop old_method = _matching_old_methods[j];
  1.1101 -    methodOop new_method = _matching_new_methods[j];
  1.1102 -    methodOop old_array_method;
  1.1103 +    Method* old_method = _matching_old_methods[j];
  1.1104 +    Method* new_method = _matching_new_methods[j];
  1.1105 +    Method* old_array_method;
  1.1106  
  1.1107      // Maintain an old_index into the _old_methods array by skipping
  1.1108      // deleted methods
  1.1109 -    while ((old_array_method = (methodOop) _old_methods->obj_at(old_index))
  1.1110 -                                                            != old_method) {
  1.1111 +    while ((old_array_method = _old_methods->at(old_index)) != old_method) {
  1.1112        ++old_index;
  1.1113      }
  1.1114  
  1.1115 @@ -2718,29 +2806,29 @@
  1.1116        // methods by new methods will save us space except for those
  1.1117        // (hopefully few) old methods that are still executing.
  1.1118        //
  1.1119 -      // A method refers to a constMethodOop and this presents another
  1.1120 -      // possible avenue to space savings. The constMethodOop in the
  1.1121 +      // A method refers to a ConstMethod* and this presents another
  1.1122 +      // possible avenue to space savings. The ConstMethod* in the
  1.1123        // new method contains possibly new attributes (LNT, LVT, etc).
  1.1124        // At first glance, it seems possible to save space by replacing
  1.1125 -      // the constMethodOop in the old method with the constMethodOop
  1.1126 +      // the ConstMethod* in the old method with the ConstMethod*
  1.1127        // from the new method. The old and new methods would share the
  1.1128 -      // same constMethodOop and we would save the space occupied by
  1.1129 -      // the old constMethodOop. However, the constMethodOop contains
  1.1130 +      // same ConstMethod* and we would save the space occupied by
  1.1131 +      // the old ConstMethod*. However, the ConstMethod* contains
  1.1132        // a back reference to the containing method. Sharing the
  1.1133 -      // constMethodOop between two methods could lead to confusion in
  1.1134 +      // ConstMethod* between two methods could lead to confusion in
  1.1135        // the code that uses the back reference. This would lead to
  1.1136        // brittle code that could be broken in non-obvious ways now or
  1.1137        // in the future.
  1.1138        //
  1.1139 -      // Another possibility is to copy the constMethodOop from the new
  1.1140 +      // Another possibility is to copy the ConstMethod* from the new
  1.1141        // method to the old method and then overwrite the new method with
  1.1142 -      // the old method. Since the constMethodOop contains the bytecodes
  1.1143 +      // the old method. Since the ConstMethod* contains the bytecodes
  1.1144        // for the method embedded in the oop, this option would change
  1.1145        // the bytecodes out from under any threads executing the old
  1.1146        // method and make the thread's bcp invalid. Since EMCP requires
  1.1147        // that the bytecodes be the same modulo constant pool indices, it
  1.1148        // is straight forward to compute the correct new bcp in the new
  1.1149 -      // constMethodOop from the old bcp in the old constMethodOop. The
  1.1150 +      // ConstMethod* from the old bcp in the old ConstMethod*. The
  1.1151        // time consuming part would be searching all the frames in all
  1.1152        // of the threads to find all of the calls to the old method.
  1.1153        //
  1.1154 @@ -2766,8 +2854,8 @@
  1.1155        obsolete_count++;
  1.1156  
  1.1157        // obsolete methods need a unique idnum
  1.1158 -      u2 num = instanceKlass::cast(_the_class_oop)->next_method_idnum();
  1.1159 -      if (num != constMethodOopDesc::UNSET_IDNUM) {
  1.1160 +      u2 num = InstanceKlass::cast(_the_class_oop)->next_method_idnum();
  1.1161 +      if (num != ConstMethod::UNSET_IDNUM) {
  1.1162  //      u2 old_num = old_method->method_idnum();
  1.1163          old_method->set_method_idnum(num);
  1.1164  // TO DO: attach obsolete annotations to obsolete method's new idnum
  1.1165 @@ -2782,7 +2870,7 @@
  1.1166      old_method->set_is_old();
  1.1167    }
  1.1168    for (int i = 0; i < _deleted_methods_length; ++i) {
  1.1169 -    methodOop old_method = _deleted_methods[i];
  1.1170 +    Method* old_method = _deleted_methods[i];
  1.1171  
  1.1172      assert(old_method->vtable_index() < 0,
  1.1173             "cannot delete methods with vtable entries");;
  1.1174 @@ -2837,11 +2925,11 @@
  1.1175    //    (1) without the prefix.
  1.1176    //    (2) with the prefix.
  1.1177    // where 'prefix' is the prefix at that 'depth' (first prefix, second prefix,...)
  1.1178 -  methodOop search_prefix_name_space(int depth, char* name_str, size_t name_len,
  1.1179 +  Method* search_prefix_name_space(int depth, char* name_str, size_t name_len,
  1.1180                                       Symbol* signature) {
  1.1181      TempNewSymbol name_symbol = SymbolTable::probe(name_str, (int)name_len);
  1.1182      if (name_symbol != NULL) {
  1.1183 -      methodOop method = Klass::cast(the_class())->lookup_method(name_symbol, signature);
  1.1184 +      Method* method = Klass::cast(the_class())->lookup_method(name_symbol, signature);
  1.1185        if (method != NULL) {
  1.1186          // Even if prefixed, intermediate methods must exist.
  1.1187          if (method->is_native()) {
  1.1188 @@ -2877,7 +2965,7 @@
  1.1189    }
  1.1190  
  1.1191    // Return the method name with old prefixes stripped away.
  1.1192 -  char* method_name_without_prefixes(methodOop method) {
  1.1193 +  char* method_name_without_prefixes(Method* method) {
  1.1194      Symbol* name = method->name();
  1.1195      char* name_str = name->as_utf8();
  1.1196  
  1.1197 @@ -2894,7 +2982,7 @@
  1.1198  
  1.1199    // Strip any prefixes off the old native method, then try to find a
  1.1200    // (possibly prefixed) new native that matches it.
  1.1201 -  methodOop strip_and_search_for_new_native(methodOop method) {
  1.1202 +  Method* strip_and_search_for_new_native(Method* method) {
  1.1203      ResourceMark rm;
  1.1204      char* name_str = method_name_without_prefixes(method);
  1.1205      return search_prefix_name_space(0, name_str, strlen(name_str),
  1.1206 @@ -2912,18 +3000,18 @@
  1.1207    }
  1.1208  
  1.1209    // Attempt to transfer any of the old or deleted methods that are native
  1.1210 -  void transfer_registrations(methodOop* old_methods, int methods_length) {
  1.1211 +  void transfer_registrations(Method** old_methods, int methods_length) {
  1.1212      for (int j = 0; j < methods_length; j++) {
  1.1213 -      methodOop old_method = old_methods[j];
  1.1214 +      Method* old_method = old_methods[j];
  1.1215  
  1.1216        if (old_method->is_native() && old_method->has_native_function()) {
  1.1217 -        methodOop new_method = strip_and_search_for_new_native(old_method);
  1.1218 +        Method* new_method = strip_and_search_for_new_native(old_method);
  1.1219          if (new_method != NULL) {
  1.1220            // Actually set the native function in the new method.
  1.1221            // Redefine does not send events (except CFLH), certainly not this
  1.1222            // behind the scenes re-registration.
  1.1223            new_method->set_native_function(old_method->native_function(),
  1.1224 -                              !methodOopDesc::native_bind_event_is_interesting);
  1.1225 +                              !Method::native_bind_event_is_interesting);
  1.1226          }
  1.1227        }
  1.1228      }
  1.1229 @@ -2977,13 +3065,13 @@
  1.1230  }
  1.1231  
  1.1232  void VM_RedefineClasses::compute_added_deleted_matching_methods() {
  1.1233 -  methodOop old_method;
  1.1234 -  methodOop new_method;
  1.1235 -
  1.1236 -  _matching_old_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  1.1237 -  _matching_new_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  1.1238 -  _added_methods        = NEW_RESOURCE_ARRAY(methodOop, _new_methods->length());
  1.1239 -  _deleted_methods      = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  1.1240 +  Method* old_method;
  1.1241 +  Method* new_method;
  1.1242 +
  1.1243 +  _matching_old_methods = NEW_RESOURCE_ARRAY(Method*, _old_methods->length());
  1.1244 +  _matching_new_methods = NEW_RESOURCE_ARRAY(Method*, _old_methods->length());
  1.1245 +  _added_methods        = NEW_RESOURCE_ARRAY(Method*, _new_methods->length());
  1.1246 +  _deleted_methods      = NEW_RESOURCE_ARRAY(Method*, _old_methods->length());
  1.1247  
  1.1248    _matching_methods_length = 0;
  1.1249    _deleted_methods_length  = 0;
  1.1250 @@ -2997,17 +3085,17 @@
  1.1251          break; // we've looked at everything, done
  1.1252        }
  1.1253        // New method at the end
  1.1254 -      new_method = (methodOop) _new_methods->obj_at(nj);
  1.1255 +      new_method = _new_methods->at(nj);
  1.1256        _added_methods[_added_methods_length++] = new_method;
  1.1257        ++nj;
  1.1258      } else if (nj >= _new_methods->length()) {
  1.1259        // Old method, at the end, is deleted
  1.1260 -      old_method = (methodOop) _old_methods->obj_at(oj);
  1.1261 +      old_method = _old_methods->at(oj);
  1.1262        _deleted_methods[_deleted_methods_length++] = old_method;
  1.1263        ++oj;
  1.1264      } else {
  1.1265 -      old_method = (methodOop) _old_methods->obj_at(oj);
  1.1266 -      new_method = (methodOop) _new_methods->obj_at(nj);
  1.1267 +      old_method = _old_methods->at(oj);
  1.1268 +      new_method = _new_methods->at(nj);
  1.1269        if (old_method->name() == new_method->name()) {
  1.1270          if (old_method->signature() == new_method->signature()) {
  1.1271            _matching_old_methods[_matching_methods_length  ] = old_method;
  1.1272 @@ -3052,12 +3140,15 @@
  1.1273  //      that we would like to pass to the helper method are saved in
  1.1274  //      static global fields in the VM operation.
  1.1275  void VM_RedefineClasses::redefine_single_class(jclass the_jclass,
  1.1276 -       instanceKlassHandle scratch_class, TRAPS) {
  1.1277 -
  1.1278 +       Klass* scratch_class_oop, TRAPS) {
  1.1279 +
  1.1280 +  HandleMark hm(THREAD);   // make sure handles from this call are freed
  1.1281    RC_TIMER_START(_timer_rsc_phase1);
  1.1282  
  1.1283 +  instanceKlassHandle scratch_class(scratch_class_oop);
  1.1284 +
  1.1285    oop the_class_mirror = JNIHandles::resolve_non_null(the_jclass);
  1.1286 -  klassOop the_class_oop = java_lang_Class::as_klassOop(the_class_mirror);
  1.1287 +  Klass* the_class_oop = java_lang_Class::as_Klass(the_class_mirror);
  1.1288    instanceKlassHandle the_class = instanceKlassHandle(THREAD, the_class_oop);
  1.1289  
  1.1290  #ifndef JVMTI_KERNEL
  1.1291 @@ -3105,13 +3196,13 @@
  1.1292    // done here since we are past the bytecode verification and
  1.1293    // constant pool optimization phases.
  1.1294    for (int i = _old_methods->length() - 1; i >= 0; i--) {
  1.1295 -    methodOop method = (methodOop)_old_methods->obj_at(i);
  1.1296 +    Method* method = _old_methods->at(i);
  1.1297      method->set_constants(scratch_class->constants());
  1.1298    }
  1.1299  
  1.1300    {
  1.1301      // walk all previous versions of the klass
  1.1302 -    instanceKlass *ik = (instanceKlass *)the_class()->klass_part();
  1.1303 +    InstanceKlass *ik = (InstanceKlass *)the_class();
  1.1304      PreviousVersionWalker pvw(ik);
  1.1305      instanceKlassHandle ikh;
  1.1306      do {
  1.1307 @@ -3124,9 +3215,9 @@
  1.1308  
  1.1309          // Attach each method in the previous version of klass to the
  1.1310          // new constant pool
  1.1311 -        objArrayOop prev_methods = ik->methods();
  1.1312 +        Array<Method*>* prev_methods = ik->methods();
  1.1313          for (int i = prev_methods->length() - 1; i >= 0; i--) {
  1.1314 -          methodOop method = (methodOop)prev_methods->obj_at(i);
  1.1315 +          Method* method = prev_methods->at(i);
  1.1316            method->set_constants(scratch_class->constants());
  1.1317          }
  1.1318        }
  1.1319 @@ -3139,7 +3230,7 @@
  1.1320    scratch_class->set_methods(_old_methods);     // To prevent potential GCing of the old methods,
  1.1321                                            // and to be able to undo operation easily.
  1.1322  
  1.1323 -  constantPoolOop old_constants = the_class->constants();
  1.1324 +  ConstantPool* old_constants = the_class->constants();
  1.1325    the_class->set_constants(scratch_class->constants());
  1.1326    scratch_class->set_constants(old_constants);  // See the previous comment.
  1.1327  #if 0
  1.1328 @@ -3166,7 +3257,7 @@
  1.1329    // Miranda methods are a little more complicated. A miranda method is
  1.1330    // provided by an interface when the class implementing the interface
  1.1331    // does not provide its own method.  These interfaces are implemented
  1.1332 -  // internally as an instanceKlass. These special instanceKlasses
  1.1333 +  // internally as an InstanceKlass. These special instanceKlasses
  1.1334    // share the constant pool of the class that "implements" the
  1.1335    // interface. By sharing the constant pool, the method holder of a
  1.1336    // miranda method is the class that "implements" the interface. In a
  1.1337 @@ -3205,7 +3296,7 @@
  1.1338  #endif
  1.1339  
  1.1340    // Replace inner_classes
  1.1341 -  typeArrayOop old_inner_classes = the_class->inner_classes();
  1.1342 +  Array<u2>* old_inner_classes = the_class->inner_classes();
  1.1343    the_class->set_inner_classes(scratch_class->inner_classes());
  1.1344    scratch_class->set_inner_classes(old_inner_classes);
  1.1345  
  1.1346 @@ -3247,34 +3338,10 @@
  1.1347      the_class->set_access_flags(flags);
  1.1348    }
  1.1349  
  1.1350 -  // Replace class annotation fields values
  1.1351 -  typeArrayOop old_class_annotations = the_class->class_annotations();
  1.1352 -  the_class->set_class_annotations(scratch_class->class_annotations());
  1.1353 -  scratch_class->set_class_annotations(old_class_annotations);
  1.1354 -
  1.1355 -  // Replace fields annotation fields values
  1.1356 -  objArrayOop old_fields_annotations = the_class->fields_annotations();
  1.1357 -  the_class->set_fields_annotations(scratch_class->fields_annotations());
  1.1358 -  scratch_class->set_fields_annotations(old_fields_annotations);
  1.1359 -
  1.1360 -  // Replace methods annotation fields values
  1.1361 -  objArrayOop old_methods_annotations = the_class->methods_annotations();
  1.1362 -  the_class->set_methods_annotations(scratch_class->methods_annotations());
  1.1363 -  scratch_class->set_methods_annotations(old_methods_annotations);
  1.1364 -
  1.1365 -  // Replace methods parameter annotation fields values
  1.1366 -  objArrayOop old_methods_parameter_annotations =
  1.1367 -    the_class->methods_parameter_annotations();
  1.1368 -  the_class->set_methods_parameter_annotations(
  1.1369 -    scratch_class->methods_parameter_annotations());
  1.1370 -  scratch_class->set_methods_parameter_annotations(old_methods_parameter_annotations);
  1.1371 -
  1.1372 -  // Replace methods default annotation fields values
  1.1373 -  objArrayOop old_methods_default_annotations =
  1.1374 -    the_class->methods_default_annotations();
  1.1375 -  the_class->set_methods_default_annotations(
  1.1376 -    scratch_class->methods_default_annotations());
  1.1377 -  scratch_class->set_methods_default_annotations(old_methods_default_annotations);
  1.1378 +  // Replace annotation fields value
  1.1379 +  Annotations* old_annotations = the_class->annotations();
  1.1380 +  the_class->set_annotations(scratch_class->annotations());
  1.1381 +  scratch_class->set_annotations(old_annotations);
  1.1382  
  1.1383    // Replace minor version number of class file
  1.1384    u2 old_minor_version = the_class->minor_version();
  1.1385 @@ -3305,6 +3372,9 @@
  1.1386    // that reference methods of the evolved class.
  1.1387    SystemDictionary::classes_do(adjust_cpool_cache_and_vtable, THREAD);
  1.1388  
  1.1389 +  // Fix Resolution Error table also to remove old constant pools
  1.1390 +  SystemDictionary::delete_resolution_error(old_constants);
  1.1391 +
  1.1392    if (the_class->oop_map_cache() != NULL) {
  1.1393      // Flush references to any obsolete methods from the oop map cache
  1.1394      // so that obsolete methods are not pinned.
  1.1395 @@ -3313,7 +3383,7 @@
  1.1396  
  1.1397    // increment the classRedefinedCount field in the_class and in any
  1.1398    // direct and indirect subclasses of the_class
  1.1399 -  increment_class_counter((instanceKlass *)the_class()->klass_part(), THREAD);
  1.1400 +  increment_class_counter((InstanceKlass *)the_class(), THREAD);
  1.1401  
  1.1402    // RC_TRACE macro has an embedded ResourceMark
  1.1403    RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  1.1404 @@ -3326,11 +3396,11 @@
  1.1405  } // end redefine_single_class()
  1.1406  
  1.1407  
  1.1408 -// Increment the classRedefinedCount field in the specific instanceKlass
  1.1409 +// Increment the classRedefinedCount field in the specific InstanceKlass
  1.1410  // and in all direct and indirect subclasses.
  1.1411 -void VM_RedefineClasses::increment_class_counter(instanceKlass *ik, TRAPS) {
  1.1412 +void VM_RedefineClasses::increment_class_counter(InstanceKlass *ik, TRAPS) {
  1.1413    oop class_mirror = ik->java_mirror();
  1.1414 -  klassOop class_oop = java_lang_Class::as_klassOop(class_mirror);
  1.1415 +  Klass* class_oop = java_lang_Class::as_Klass(class_mirror);
  1.1416    int new_count = java_lang_Class::classRedefinedCount(class_mirror) + 1;
  1.1417    java_lang_Class::set_classRedefinedCount(class_mirror, new_count);
  1.1418  
  1.1419 @@ -3344,7 +3414,7 @@
  1.1420         subk = subk->next_sibling()) {
  1.1421      if (subk->oop_is_instance()) {
  1.1422        // Only update instanceKlasses
  1.1423 -      instanceKlass *subik = (instanceKlass*)subk;
  1.1424 +      InstanceKlass *subik = (InstanceKlass*)subk;
  1.1425        // recursively do subclasses of the current subclass
  1.1426        increment_class_counter(subik, THREAD);
  1.1427      }
  1.1428 @@ -3352,22 +3422,36 @@
  1.1429  }
  1.1430  
  1.1431  #ifndef PRODUCT
  1.1432 -void VM_RedefineClasses::check_class(klassOop k_oop,
  1.1433 -       oop initiating_loader, TRAPS) {
  1.1434 -  Klass *k = k_oop->klass_part();
  1.1435 +void VM_RedefineClasses::check_class(Klass* k_oop,
  1.1436 +                                     ClassLoaderData* initiating_loader,
  1.1437 +                                     TRAPS) {
  1.1438 +  Klass *k = k_oop;
  1.1439    if (k->oop_is_instance()) {
  1.1440      HandleMark hm(THREAD);
  1.1441 -    instanceKlass *ik = (instanceKlass *) k;
  1.1442 +    InstanceKlass *ik = (InstanceKlass *) k;
  1.1443  
  1.1444      if (ik->vtable_length() > 0) {
  1.1445        ResourceMark rm(THREAD);
  1.1446        if (!ik->vtable()->check_no_old_entries()) {
  1.1447          tty->print_cr("klassVtable::check_no_old_entries failure -- OLD method found -- class: %s", ik->signature_name());
  1.1448          ik->vtable()->dump_vtable();
  1.1449 -        dump_methods();
  1.1450          assert(false, "OLD method found");
  1.1451        }
  1.1452      }
  1.1453 +    if (ik->itable_length() > 0) {
  1.1454 +      ResourceMark rm(THREAD);
  1.1455 +      if (!ik->itable()->check_no_old_entries()) {
  1.1456 +        tty->print_cr("klassItable::check_no_old_entries failure -- OLD method found -- class: %s", ik->signature_name());
  1.1457 +        assert(false, "OLD method found");
  1.1458 +      }
  1.1459 +    }
  1.1460 +    // Check that the constant pool cache has no deleted entries.
  1.1461 +    if (ik->constants() != NULL &&
  1.1462 +        ik->constants()->cache() != NULL &&
  1.1463 +       !ik->constants()->cache()->check_no_old_entries()) {
  1.1464 +      tty->print_cr("klassVtable::check_no_old_entries failure -- OLD method found -- class: %s", ik->signature_name());
  1.1465 +      assert(false, "OLD method found");
  1.1466 +    }
  1.1467    }
  1.1468  }
  1.1469  
  1.1470 @@ -3375,7 +3459,7 @@
  1.1471          int j;
  1.1472          tty->print_cr("_old_methods --");
  1.1473          for (j = 0; j < _old_methods->length(); ++j) {
  1.1474 -          methodOop m = (methodOop) _old_methods->obj_at(j);
  1.1475 +          Method* m = _old_methods->at(j);
  1.1476            tty->print("%4d  (%5d)  ", j, m->vtable_index());
  1.1477            m->access_flags().print_on(tty);
  1.1478            tty->print(" --  ");
  1.1479 @@ -3384,7 +3468,7 @@
  1.1480          }
  1.1481          tty->print_cr("_new_methods --");
  1.1482          for (j = 0; j < _new_methods->length(); ++j) {
  1.1483 -          methodOop m = (methodOop) _new_methods->obj_at(j);
  1.1484 +          Method* m = _new_methods->at(j);
  1.1485            tty->print("%4d  (%5d)  ", j, m->vtable_index());
  1.1486            m->access_flags().print_on(tty);
  1.1487            tty->print(" --  ");
  1.1488 @@ -3393,7 +3477,7 @@
  1.1489          }
  1.1490          tty->print_cr("_matching_(old/new)_methods --");
  1.1491          for (j = 0; j < _matching_methods_length; ++j) {
  1.1492 -          methodOop m = _matching_old_methods[j];
  1.1493 +          Method* m = _matching_old_methods[j];
  1.1494            tty->print("%4d  (%5d)  ", j, m->vtable_index());
  1.1495            m->access_flags().print_on(tty);
  1.1496            tty->print(" --  ");
  1.1497 @@ -3406,7 +3490,7 @@
  1.1498          }
  1.1499          tty->print_cr("_deleted_methods --");
  1.1500          for (j = 0; j < _deleted_methods_length; ++j) {
  1.1501 -          methodOop m = _deleted_methods[j];
  1.1502 +          Method* m = _deleted_methods[j];
  1.1503            tty->print("%4d  (%5d)  ", j, m->vtable_index());
  1.1504            m->access_flags().print_on(tty);
  1.1505            tty->print(" --  ");
  1.1506 @@ -3415,7 +3499,7 @@
  1.1507          }
  1.1508          tty->print_cr("_added_methods --");
  1.1509          for (j = 0; j < _added_methods_length; ++j) {
  1.1510 -          methodOop m = _added_methods[j];
  1.1511 +          Method* m = _added_methods[j];
  1.1512            tty->print("%4d  (%5d)  ", j, m->vtable_index());
  1.1513            m->access_flags().print_on(tty);
  1.1514            tty->print(" --  ");

mercurial