src/share/vm/prims/jvm.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File 8042235_8u40 Sdiff src/share/vm/prims

src/share/vm/prims/jvm.cpp

Print this page
rev 6917 : 8042235: redefining method used by multiple MethodHandles crashes VM
Summary: note all MemberNames created on internal list for adjusting method entries.
Reviewed-by: sspitsyn, dcubed, lfoltan


 586 #ifdef ASSERT
 587   // Just checking that the cloneable flag is set correct
 588   if (obj->is_array()) {
 589     guarantee(klass->is_cloneable(), "all arrays are cloneable");
 590   } else {
 591     guarantee(obj->is_instance(), "should be instanceOop");
 592     bool cloneable = klass->is_subtype_of(SystemDictionary::Cloneable_klass());
 593     guarantee(cloneable == klass->is_cloneable(), "incorrect cloneable flag");
 594   }
 595 #endif
 596 
 597   // Check if class of obj supports the Cloneable interface.
 598   // All arrays are considered to be cloneable (See JLS 20.1.5)
 599   if (!klass->is_cloneable()) {
 600     ResourceMark rm(THREAD);
 601     THROW_MSG_0(vmSymbols::java_lang_CloneNotSupportedException(), klass->external_name());
 602   }
 603 
 604   // Make shallow object copy
 605   const int size = obj->size();
 606   oop new_obj = NULL;
 607   if (obj->is_array()) {
 608     const int length = ((arrayOop)obj())->length();
 609     new_obj = CollectedHeap::array_allocate(klass, size, length, CHECK_NULL);
 610   } else {
 611     new_obj = CollectedHeap::obj_allocate(klass, size, CHECK_NULL);
 612   }

 613   // 4839641 (4840070): We must do an oop-atomic copy, because if another thread
 614   // is modifying a reference field in the clonee, a non-oop-atomic copy might
 615   // be suspended in the middle of copying the pointer and end up with parts
 616   // of two different pointers in the field.  Subsequent dereferences will crash.
 617   // 4846409: an oop-copy of objects with long or double fields or arrays of same
 618   // won't copy the longs/doubles atomically in 32-bit vm's, so we copy jlongs instead
 619   // of oops.  We know objects are aligned on a minimum of an jlong boundary.
 620   // The same is true of StubRoutines::object_copy and the various oop_copy
 621   // variants, and of the code generated by the inline_native_clone intrinsic.
 622   assert(MinObjAlignmentInBytes >= BytesPerLong, "objects misaligned");
 623   Copy::conjoint_jlongs_atomic((jlong*)obj(), (jlong*)new_obj,
 624                                (size_t)align_object_size(size) / HeapWordsPerLong);
 625   // Clear the header
 626   new_obj->init_mark();
 627 
 628   // Store check (mark entire object and let gc sort it out)
 629   BarrierSet* bs = Universe::heap()->barrier_set();
 630   assert(bs->has_write_region_opt(), "Barrier set does not have write_region");
 631   bs->write_region(MemRegion((HeapWord*)new_obj, size));
















 632 
 633   // Caution: this involves a java upcall, so the clone should be
 634   // "gc-robust" by this stage.
 635   if (klass->has_finalizer()) {
 636     assert(obj->is_instance(), "should be instanceOop");
 637     new_obj = InstanceKlass::register_finalizer(instanceOop(new_obj), CHECK_NULL);

 638   }
 639 
 640   return JNIHandles::make_local(env, oop(new_obj));
 641 JVM_END
 642 
 643 // java.lang.Compiler ////////////////////////////////////////////////////
 644 
 645 // The initial cuts of the HotSpot VM will not support JITs, and all existing
 646 // JITs would need extensive changes to work with HotSpot.  The JIT-related JVM
 647 // functions are all silently ignored unless JVM warnings are printed.
 648 
 649 JVM_LEAF(void, JVM_InitializeCompiler (JNIEnv *env, jclass compCls))
 650   if (PrintJVMWarnings) warning("JVM_InitializeCompiler not supported");
 651 JVM_END
 652 
 653 
 654 JVM_LEAF(jboolean, JVM_IsSilentCompiler(JNIEnv *env, jclass compCls))
 655   if (PrintJVMWarnings) warning("JVM_IsSilentCompiler not supported");
 656   return JNI_FALSE;
 657 JVM_END
 658 
 659 
 660 JVM_LEAF(jboolean, JVM_CompileClass(JNIEnv *env, jclass compCls, jclass cls))




 586 #ifdef ASSERT
 587   // Just checking that the cloneable flag is set correct
 588   if (obj->is_array()) {
 589     guarantee(klass->is_cloneable(), "all arrays are cloneable");
 590   } else {
 591     guarantee(obj->is_instance(), "should be instanceOop");
 592     bool cloneable = klass->is_subtype_of(SystemDictionary::Cloneable_klass());
 593     guarantee(cloneable == klass->is_cloneable(), "incorrect cloneable flag");
 594   }
 595 #endif
 596 
 597   // Check if class of obj supports the Cloneable interface.
 598   // All arrays are considered to be cloneable (See JLS 20.1.5)
 599   if (!klass->is_cloneable()) {
 600     ResourceMark rm(THREAD);
 601     THROW_MSG_0(vmSymbols::java_lang_CloneNotSupportedException(), klass->external_name());
 602   }
 603 
 604   // Make shallow object copy
 605   const int size = obj->size();
 606   oop new_obj_oop = NULL;
 607   if (obj->is_array()) {
 608     const int length = ((arrayOop)obj())->length();
 609     new_obj_oop = CollectedHeap::array_allocate(klass, size, length, CHECK_NULL);
 610   } else {
 611     new_obj_oop = CollectedHeap::obj_allocate(klass, size, CHECK_NULL);
 612   }
 613 
 614   // 4839641 (4840070): We must do an oop-atomic copy, because if another thread
 615   // is modifying a reference field in the clonee, a non-oop-atomic copy might
 616   // be suspended in the middle of copying the pointer and end up with parts
 617   // of two different pointers in the field.  Subsequent dereferences will crash.
 618   // 4846409: an oop-copy of objects with long or double fields or arrays of same
 619   // won't copy the longs/doubles atomically in 32-bit vm's, so we copy jlongs instead
 620   // of oops.  We know objects are aligned on a minimum of an jlong boundary.
 621   // The same is true of StubRoutines::object_copy and the various oop_copy
 622   // variants, and of the code generated by the inline_native_clone intrinsic.
 623   assert(MinObjAlignmentInBytes >= BytesPerLong, "objects misaligned");
 624   Copy::conjoint_jlongs_atomic((jlong*)obj(), (jlong*)new_obj_oop,
 625                                (size_t)align_object_size(size) / HeapWordsPerLong);
 626   // Clear the header
 627   new_obj_oop->init_mark();
 628 
 629   // Store check (mark entire object and let gc sort it out)
 630   BarrierSet* bs = Universe::heap()->barrier_set();
 631   assert(bs->has_write_region_opt(), "Barrier set does not have write_region");
 632   bs->write_region(MemRegion((HeapWord*)new_obj_oop, size));
 633 
 634   Handle new_obj(THREAD, new_obj_oop);
 635   // Special handling for MemberNames.  Since they contain Method* metadata, they
 636   // must be registered so that RedefineClasses can fix metadata contained in them.
 637   if (java_lang_invoke_MemberName::is_instance(new_obj()) &&
 638       java_lang_invoke_MemberName::is_method(new_obj())) {
 639     Method* method = (Method*)java_lang_invoke_MemberName::vmtarget(new_obj());
 640     // MemberName may be unresolved, so doesn't need registration until resolved.
 641     if (method != NULL) {
 642       methodHandle m(THREAD, method);
 643       // This can safepoint and redefine method, so need both new_obj and method
 644       // in a handle, for two different reasons.  new_obj can move, method can be
 645       // deleted if nothing is using it on the stack.
 646       m->method_holder()->add_member_name(new_obj());
 647     }
 648   }
 649 
 650   // Caution: this involves a java upcall, so the clone should be
 651   // "gc-robust" by this stage.
 652   if (klass->has_finalizer()) {
 653     assert(obj->is_instance(), "should be instanceOop");
 654     new_obj_oop = InstanceKlass::register_finalizer(instanceOop(new_obj()), CHECK_NULL);
 655     new_obj = Handle(THREAD, new_obj_oop);
 656   }
 657 
 658   return JNIHandles::make_local(env, new_obj());
 659 JVM_END
 660 
 661 // java.lang.Compiler ////////////////////////////////////////////////////
 662 
 663 // The initial cuts of the HotSpot VM will not support JITs, and all existing
 664 // JITs would need extensive changes to work with HotSpot.  The JIT-related JVM
 665 // functions are all silently ignored unless JVM warnings are printed.
 666 
 667 JVM_LEAF(void, JVM_InitializeCompiler (JNIEnv *env, jclass compCls))
 668   if (PrintJVMWarnings) warning("JVM_InitializeCompiler not supported");
 669 JVM_END
 670 
 671 
 672 JVM_LEAF(jboolean, JVM_IsSilentCompiler(JNIEnv *env, jclass compCls))
 673   if (PrintJVMWarnings) warning("JVM_IsSilentCompiler not supported");
 674   return JNI_FALSE;
 675 JVM_END
 676 
 677 
 678 JVM_LEAF(jboolean, JVM_CompileClass(JNIEnv *env, jclass compCls, jclass cls))


src/share/vm/prims/jvm.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File