17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/classFileStream.hpp"
27 #include "classfile/classLoader.hpp"
28 #include "classfile/classLoaderData.inline.hpp"
29 #include "classfile/javaAssertions.hpp"
30 #include "classfile/javaClasses.inline.hpp"
31 #include "classfile/moduleEntry.hpp"
32 #include "classfile/modules.hpp"
33 #include "classfile/packageEntry.hpp"
34 #include "classfile/stringTable.hpp"
35 #include "classfile/systemDictionary.hpp"
36 #include "classfile/vmSymbols.hpp"
37 #include "gc/shared/barrierSet.inline.hpp"
38 #include "gc/shared/collectedHeap.inline.hpp"
39 #include "interpreter/bytecode.hpp"
40 #include "memory/oopFactory.hpp"
41 #include "memory/resourceArea.hpp"
42 #include "memory/universe.inline.hpp"
43 #include "oops/fieldStreams.hpp"
44 #include "oops/instanceKlass.hpp"
45 #include "oops/method.hpp"
46 #include "oops/objArrayKlass.hpp"
47 #include "oops/objArrayOop.inline.hpp"
48 #include "oops/oop.inline.hpp"
49 #include "prims/jvm.h"
50 #include "prims/jvm_misc.hpp"
51 #include "prims/jvmtiExport.hpp"
52 #include "prims/jvmtiThreadState.hpp"
53 #include "prims/nativeLookup.hpp"
54 #include "prims/privilegedStack.hpp"
55 #include "prims/stackwalk.hpp"
56 #include "runtime/arguments.hpp"
57 #include "runtime/atomic.hpp"
58 #include "runtime/handles.inline.hpp"
59 #include "runtime/init.hpp"
60 #include "runtime/interfaceSupport.hpp"
61 #include "runtime/java.hpp"
62 #include "runtime/javaCalls.hpp"
63 #include "runtime/jfieldIDWorkaround.hpp"
64 #include "runtime/orderAccess.inline.hpp"
65 #include "runtime/os.inline.hpp"
66 #include "runtime/perfData.hpp"
67 #include "runtime/reflection.hpp"
68 #include "runtime/thread.inline.hpp"
69 #include "runtime/vframe.hpp"
70 #include "runtime/vm_operations.hpp"
71 #include "runtime/vm_version.hpp"
72 #include "services/attachListener.hpp"
73 #include "services/management.hpp"
74 #include "services/threadService.hpp"
75 #include "trace/tracing.hpp"
635 }
636 #endif
637
638 // Check if class of obj supports the Cloneable interface.
639 // All arrays are considered to be cloneable (See JLS 20.1.5)
640 if (!klass->is_cloneable()) {
641 ResourceMark rm(THREAD);
642 THROW_MSG_0(vmSymbols::java_lang_CloneNotSupportedException(), klass->external_name());
643 }
644
645 // Make shallow object copy
646 const int size = obj->size();
647 oop new_obj_oop = NULL;
648 if (obj->is_array()) {
649 const int length = ((arrayOop)obj())->length();
650 new_obj_oop = CollectedHeap::array_allocate(klass, size, length, CHECK_NULL);
651 } else {
652 new_obj_oop = CollectedHeap::obj_allocate(klass, size, CHECK_NULL);
653 }
654
655 // 4839641 (4840070): We must do an oop-atomic copy, because if another thread
656 // is modifying a reference field in the clonee, a non-oop-atomic copy might
657 // be suspended in the middle of copying the pointer and end up with parts
658 // of two different pointers in the field. Subsequent dereferences will crash.
659 // 4846409: an oop-copy of objects with long or double fields or arrays of same
660 // won't copy the longs/doubles atomically in 32-bit vm's, so we copy jlongs instead
661 // of oops. We know objects are aligned on a minimum of an jlong boundary.
662 // The same is true of StubRoutines::object_copy and the various oop_copy
663 // variants, and of the code generated by the inline_native_clone intrinsic.
664 assert(MinObjAlignmentInBytes >= BytesPerLong, "objects misaligned");
665 Copy::conjoint_jlongs_atomic((jlong*)obj(), (jlong*)new_obj_oop,
666 (size_t)align_object_size(size) / HeapWordsPerLong);
667 // Clear the header
668 new_obj_oop->init_mark();
669
670 // Store check (mark entire object and let gc sort it out)
671 BarrierSet* bs = Universe::heap()->barrier_set();
672 assert(bs->has_write_region_opt(), "Barrier set does not have write_region");
673 bs->write_region(MemRegion((HeapWord*)new_obj_oop, size));
674
675 Handle new_obj(THREAD, new_obj_oop);
676 // Special handling for MemberNames. Since they contain Method* metadata, they
677 // must be registered so that RedefineClasses can fix metadata contained in them.
678 if (java_lang_invoke_MemberName::is_instance(new_obj()) &&
679 java_lang_invoke_MemberName::is_method(new_obj())) {
680 Method* method = (Method*)java_lang_invoke_MemberName::vmtarget(new_obj());
681 // MemberName may be unresolved, so doesn't need registration until resolved.
682 if (method != NULL) {
683 methodHandle m(THREAD, method);
684 // This can safepoint and redefine method, so need both new_obj and method
685 // in a handle, for two different reasons. new_obj can move, method can be
686 // deleted if nothing is using it on the stack.
687 m->method_holder()->add_member_name(new_obj, false);
688 }
689 }
690
691 // Caution: this involves a java upcall, so the clone should be
692 // "gc-robust" by this stage.
693 if (klass->has_finalizer()) {
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/classFileStream.hpp"
27 #include "classfile/classLoader.hpp"
28 #include "classfile/classLoaderData.inline.hpp"
29 #include "classfile/javaAssertions.hpp"
30 #include "classfile/javaClasses.inline.hpp"
31 #include "classfile/moduleEntry.hpp"
32 #include "classfile/modules.hpp"
33 #include "classfile/packageEntry.hpp"
34 #include "classfile/stringTable.hpp"
35 #include "classfile/systemDictionary.hpp"
36 #include "classfile/vmSymbols.hpp"
37 #include "gc/shared/collectedHeap.inline.hpp"
38 #include "interpreter/bytecode.hpp"
39 #include "memory/oopFactory.hpp"
40 #include "memory/resourceArea.hpp"
41 #include "memory/universe.inline.hpp"
42 #include "oops/fieldStreams.hpp"
43 #include "oops/instanceKlass.hpp"
44 #include "oops/method.hpp"
45 #include "oops/objArrayKlass.hpp"
46 #include "oops/objArrayOop.inline.hpp"
47 #include "oops/oop.inline.hpp"
48 #include "prims/jvm.h"
49 #include "prims/jvm_misc.hpp"
50 #include "prims/jvmtiExport.hpp"
51 #include "prims/jvmtiThreadState.hpp"
52 #include "prims/nativeLookup.hpp"
53 #include "prims/privilegedStack.hpp"
54 #include "prims/stackwalk.hpp"
55 #include "runtime/access.inline.hpp"
56 #include "runtime/arguments.hpp"
57 #include "runtime/atomic.hpp"
58 #include "runtime/handles.inline.hpp"
59 #include "runtime/init.hpp"
60 #include "runtime/interfaceSupport.hpp"
61 #include "runtime/java.hpp"
62 #include "runtime/javaCalls.hpp"
63 #include "runtime/jfieldIDWorkaround.hpp"
64 #include "runtime/orderAccess.inline.hpp"
65 #include "runtime/os.inline.hpp"
66 #include "runtime/perfData.hpp"
67 #include "runtime/reflection.hpp"
68 #include "runtime/thread.inline.hpp"
69 #include "runtime/vframe.hpp"
70 #include "runtime/vm_operations.hpp"
71 #include "runtime/vm_version.hpp"
72 #include "services/attachListener.hpp"
73 #include "services/management.hpp"
74 #include "services/threadService.hpp"
75 #include "trace/tracing.hpp"
635 }
636 #endif
637
638 // Check if class of obj supports the Cloneable interface.
639 // All arrays are considered to be cloneable (See JLS 20.1.5)
640 if (!klass->is_cloneable()) {
641 ResourceMark rm(THREAD);
642 THROW_MSG_0(vmSymbols::java_lang_CloneNotSupportedException(), klass->external_name());
643 }
644
645 // Make shallow object copy
646 const int size = obj->size();
647 oop new_obj_oop = NULL;
648 if (obj->is_array()) {
649 const int length = ((arrayOop)obj())->length();
650 new_obj_oop = CollectedHeap::array_allocate(klass, size, length, CHECK_NULL);
651 } else {
652 new_obj_oop = CollectedHeap::obj_allocate(klass, size, CHECK_NULL);
653 }
654
655 HeapAccess<>::clone(obj(), new_obj_oop, size);
656
657 Handle new_obj(THREAD, new_obj_oop);
658 // Special handling for MemberNames. Since they contain Method* metadata, they
659 // must be registered so that RedefineClasses can fix metadata contained in them.
660 if (java_lang_invoke_MemberName::is_instance(new_obj()) &&
661 java_lang_invoke_MemberName::is_method(new_obj())) {
662 Method* method = (Method*)java_lang_invoke_MemberName::vmtarget(new_obj());
663 // MemberName may be unresolved, so doesn't need registration until resolved.
664 if (method != NULL) {
665 methodHandle m(THREAD, method);
666 // This can safepoint and redefine method, so need both new_obj and method
667 // in a handle, for two different reasons. new_obj can move, method can be
668 // deleted if nothing is using it on the stack.
669 m->method_holder()->add_member_name(new_obj, false);
670 }
671 }
672
673 // Caution: this involves a java upcall, so the clone should be
674 // "gc-robust" by this stage.
675 if (klass->has_finalizer()) {
|