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