src/share/vm/prims/jvm.cpp

changeset 7391
fe34c5ab0b35
parent 7322
4cb90023bf2b
child 7404
d4caf9c96afd
     1.1 --- a/src/share/vm/prims/jvm.cpp	Thu Nov 20 11:06:26 2014 +0100
     1.2 +++ b/src/share/vm/prims/jvm.cpp	Wed Nov 19 13:02:11 2014 -0500
     1.3 @@ -603,13 +603,14 @@
     1.4  
     1.5    // Make shallow object copy
     1.6    const int size = obj->size();
     1.7 -  oop new_obj = NULL;
     1.8 +  oop new_obj_oop = NULL;
     1.9    if (obj->is_array()) {
    1.10      const int length = ((arrayOop)obj())->length();
    1.11 -    new_obj = CollectedHeap::array_allocate(klass, size, length, CHECK_NULL);
    1.12 +    new_obj_oop = CollectedHeap::array_allocate(klass, size, length, CHECK_NULL);
    1.13    } else {
    1.14 -    new_obj = CollectedHeap::obj_allocate(klass, size, CHECK_NULL);
    1.15 +    new_obj_oop = CollectedHeap::obj_allocate(klass, size, CHECK_NULL);
    1.16    }
    1.17 +
    1.18    // 4839641 (4840070): We must do an oop-atomic copy, because if another thread
    1.19    // is modifying a reference field in the clonee, a non-oop-atomic copy might
    1.20    // be suspended in the middle of copying the pointer and end up with parts
    1.21 @@ -620,24 +621,41 @@
    1.22    // The same is true of StubRoutines::object_copy and the various oop_copy
    1.23    // variants, and of the code generated by the inline_native_clone intrinsic.
    1.24    assert(MinObjAlignmentInBytes >= BytesPerLong, "objects misaligned");
    1.25 -  Copy::conjoint_jlongs_atomic((jlong*)obj(), (jlong*)new_obj,
    1.26 +  Copy::conjoint_jlongs_atomic((jlong*)obj(), (jlong*)new_obj_oop,
    1.27                                 (size_t)align_object_size(size) / HeapWordsPerLong);
    1.28    // Clear the header
    1.29 -  new_obj->init_mark();
    1.30 +  new_obj_oop->init_mark();
    1.31  
    1.32    // Store check (mark entire object and let gc sort it out)
    1.33    BarrierSet* bs = Universe::heap()->barrier_set();
    1.34    assert(bs->has_write_region_opt(), "Barrier set does not have write_region");
    1.35 -  bs->write_region(MemRegion((HeapWord*)new_obj, size));
    1.36 +  bs->write_region(MemRegion((HeapWord*)new_obj_oop, size));
    1.37 +
    1.38 +  Handle new_obj(THREAD, new_obj_oop);
    1.39 +  // Special handling for MemberNames.  Since they contain Method* metadata, they
    1.40 +  // must be registered so that RedefineClasses can fix metadata contained in them.
    1.41 +  if (java_lang_invoke_MemberName::is_instance(new_obj()) &&
    1.42 +      java_lang_invoke_MemberName::is_method(new_obj())) {
    1.43 +    Method* method = (Method*)java_lang_invoke_MemberName::vmtarget(new_obj());
    1.44 +    // MemberName may be unresolved, so doesn't need registration until resolved.
    1.45 +    if (method != NULL) {
    1.46 +      methodHandle m(THREAD, method);
    1.47 +      // This can safepoint and redefine method, so need both new_obj and method
    1.48 +      // in a handle, for two different reasons.  new_obj can move, method can be
    1.49 +      // deleted if nothing is using it on the stack.
    1.50 +      m->method_holder()->add_member_name(new_obj());
    1.51 +    }
    1.52 +  }
    1.53  
    1.54    // Caution: this involves a java upcall, so the clone should be
    1.55    // "gc-robust" by this stage.
    1.56    if (klass->has_finalizer()) {
    1.57      assert(obj->is_instance(), "should be instanceOop");
    1.58 -    new_obj = InstanceKlass::register_finalizer(instanceOop(new_obj), CHECK_NULL);
    1.59 +    new_obj_oop = InstanceKlass::register_finalizer(instanceOop(new_obj()), CHECK_NULL);
    1.60 +    new_obj = Handle(THREAD, new_obj_oop);
    1.61    }
    1.62  
    1.63 -  return JNIHandles::make_local(env, oop(new_obj));
    1.64 +  return JNIHandles::make_local(env, new_obj());
    1.65  JVM_END
    1.66  
    1.67  // java.lang.Compiler ////////////////////////////////////////////////////

mercurial