src/share/vm/prims/jvm.cpp

changeset 9099
08326a76b148
parent 9073
55990d3e4c5e
child 9122
024be04bb151
child 9478
f3108e56b502
child 9530
9fce84e6f51a
equal deleted inserted replaced
9096:425504a45630 9099:08326a76b148
1 /* 1 /*
2 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
36 #endif 36 #endif
37 #include "classfile/vmSymbols.hpp" 37 #include "classfile/vmSymbols.hpp"
38 #include "gc_interface/collectedHeap.inline.hpp" 38 #include "gc_interface/collectedHeap.inline.hpp"
39 #include "interpreter/bytecode.hpp" 39 #include "interpreter/bytecode.hpp"
40 #include "memory/oopFactory.hpp" 40 #include "memory/oopFactory.hpp"
41 #include "memory/referenceType.hpp"
41 #include "memory/universe.inline.hpp" 42 #include "memory/universe.inline.hpp"
42 #include "oops/fieldStreams.hpp" 43 #include "oops/fieldStreams.hpp"
43 #include "oops/instanceKlass.hpp" 44 #include "oops/instanceKlass.hpp"
44 #include "oops/objArrayKlass.hpp" 45 #include "oops/objArrayKlass.hpp"
45 #include "oops/method.hpp" 46 #include "oops/method.hpp"
88 #endif 89 #endif
89 #ifdef TARGET_OS_FAMILY_bsd 90 #ifdef TARGET_OS_FAMILY_bsd
90 # include "jvm_bsd.h" 91 # include "jvm_bsd.h"
91 #endif 92 #endif
92 93
94 #if INCLUDE_ALL_GCS
95 #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp"
96 #endif // INCLUDE_ALL_GCS
97
93 #include <errno.h> 98 #include <errno.h>
94 99
95 #ifndef USDT2 100 #ifndef USDT2
96 HS_DTRACE_PROBE_DECL1(hotspot, thread__sleep__begin, long long); 101 HS_DTRACE_PROBE_DECL1(hotspot, thread__sleep__begin, long long);
97 HS_DTRACE_PROBE_DECL1(hotspot, thread__sleep__end, int); 102 HS_DTRACE_PROBE_DECL1(hotspot, thread__sleep__end, int);
576 Handle obj(THREAD, JNIHandles::resolve_non_null(handle)); 581 Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
577 ObjectSynchronizer::notifyall(obj, CHECK); 582 ObjectSynchronizer::notifyall(obj, CHECK);
578 JVM_END 583 JVM_END
579 584
580 585
586 static void fixup_cloned_reference(ReferenceType ref_type, oop src, oop clone) {
587 // If G1 is enabled then we need to register a non-null referent
588 // with the SATB barrier.
589 #if INCLUDE_ALL_GCS
590 if (UseG1GC) {
591 oop referent = java_lang_ref_Reference::referent(clone);
592 if (referent != NULL) {
593 G1SATBCardTableModRefBS::enqueue(referent);
594 }
595 }
596 #endif // INCLUDE_ALL_GCS
597 if ((java_lang_ref_Reference::next(clone) != NULL) ||
598 (java_lang_ref_Reference::queue(clone) == java_lang_ref_ReferenceQueue::ENQUEUED_queue())) {
599 // If the source has been enqueued or is being enqueued, don't
600 // register the clone with a queue.
601 java_lang_ref_Reference::set_queue(clone, java_lang_ref_ReferenceQueue::NULL_queue());
602 }
603 // discovered and next are list links; the clone is not in those lists.
604 java_lang_ref_Reference::set_discovered(clone, NULL);
605 java_lang_ref_Reference::set_next(clone, NULL);
606 }
607
581 JVM_ENTRY(jobject, JVM_Clone(JNIEnv* env, jobject handle)) 608 JVM_ENTRY(jobject, JVM_Clone(JNIEnv* env, jobject handle))
582 JVMWrapper("JVM_Clone"); 609 JVMWrapper("JVM_Clone");
583 Handle obj(THREAD, JNIHandles::resolve_non_null(handle)); 610 Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
584 const KlassHandle klass (THREAD, obj->klass()); 611 const KlassHandle klass (THREAD, obj->klass());
585 JvmtiVMObjectAllocEventCollector oam; 612 JvmtiVMObjectAllocEventCollector oam;
601 ResourceMark rm(THREAD); 628 ResourceMark rm(THREAD);
602 THROW_MSG_0(vmSymbols::java_lang_CloneNotSupportedException(), klass->external_name()); 629 THROW_MSG_0(vmSymbols::java_lang_CloneNotSupportedException(), klass->external_name());
603 } 630 }
604 631
605 // Make shallow object copy 632 // Make shallow object copy
633 ReferenceType ref_type = REF_NONE;
606 const int size = obj->size(); 634 const int size = obj->size();
607 oop new_obj_oop = NULL; 635 oop new_obj_oop = NULL;
608 if (obj->is_array()) { 636 if (obj->is_array()) {
609 const int length = ((arrayOop)obj())->length(); 637 const int length = ((arrayOop)obj())->length();
610 new_obj_oop = CollectedHeap::array_allocate(klass, size, length, CHECK_NULL); 638 new_obj_oop = CollectedHeap::array_allocate(klass, size, length, CHECK_NULL);
611 } else { 639 } else {
640 ref_type = InstanceKlass::cast(klass())->reference_type();
641 assert((ref_type == REF_NONE) ==
642 !klass->is_subclass_of(SystemDictionary::Reference_klass()),
643 "invariant");
612 new_obj_oop = CollectedHeap::obj_allocate(klass, size, CHECK_NULL); 644 new_obj_oop = CollectedHeap::obj_allocate(klass, size, CHECK_NULL);
613 } 645 }
614 646
615 // 4839641 (4840070): We must do an oop-atomic copy, because if another thread 647 // 4839641 (4840070): We must do an oop-atomic copy, because if another thread
616 // is modifying a reference field in the clonee, a non-oop-atomic copy might 648 // is modifying a reference field in the clonee, a non-oop-atomic copy might
629 661
630 // Store check (mark entire object and let gc sort it out) 662 // Store check (mark entire object and let gc sort it out)
631 BarrierSet* bs = Universe::heap()->barrier_set(); 663 BarrierSet* bs = Universe::heap()->barrier_set();
632 assert(bs->has_write_region_opt(), "Barrier set does not have write_region"); 664 assert(bs->has_write_region_opt(), "Barrier set does not have write_region");
633 bs->write_region(MemRegion((HeapWord*)new_obj_oop, size)); 665 bs->write_region(MemRegion((HeapWord*)new_obj_oop, size));
666
667 // If cloning a Reference, set Reference fields to a safe state.
668 // Fixup must be completed before any safepoint.
669 if (ref_type != REF_NONE) {
670 fixup_cloned_reference(ref_type, obj(), new_obj_oop);
671 }
634 672
635 Handle new_obj(THREAD, new_obj_oop); 673 Handle new_obj(THREAD, new_obj_oop);
636 // Special handling for MemberNames. Since they contain Method* metadata, they 674 // Special handling for MemberNames. Since they contain Method* metadata, they
637 // must be registered so that RedefineClasses can fix metadata contained in them. 675 // must be registered so that RedefineClasses can fix metadata contained in them.
638 if (java_lang_invoke_MemberName::is_instance(new_obj()) && 676 if (java_lang_invoke_MemberName::is_instance(new_obj()) &&

mercurial