Mercurial > hg > openjdk > jdk7u > hotspot
changeset 5828:82e6757505da jdk7u181-b00
8192025: Less referential references
Reviewed-by: coleenp, eosterlund, mchung, ahgross, rhalade
author | kbarrett |
---|---|
date | Wed, 18 Apr 2018 02:18:40 +0100 |
parents | 0dc659da232e |
children | 2e805376030c |
files | src/share/vm/classfile/javaClasses.cpp src/share/vm/classfile/javaClasses.hpp src/share/vm/classfile/systemDictionary.cpp src/share/vm/classfile/systemDictionary.hpp src/share/vm/classfile/vmSymbols.hpp src/share/vm/oops/klass.cpp src/share/vm/oops/klass.hpp src/share/vm/prims/jvm.cpp |
diffstat | 8 files changed, 118 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/share/vm/classfile/javaClasses.cpp Wed May 23 17:39:33 2018 +0100 +++ b/src/share/vm/classfile/javaClasses.cpp Wed Apr 18 02:18:40 2018 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -2413,6 +2413,32 @@ *offset = value; } +// Support for java_lang_ref_ReferenceQueue + +oop java_lang_ref_ReferenceQueue::NULL_queue() { + instanceKlass* ik = instanceKlass::cast(SystemDictionary::ReferenceQueue_klass()); + oop mirror = ik->java_mirror(); + return mirror->obj_field(static_NULL_queue_offset); +} + +oop java_lang_ref_ReferenceQueue::ENQUEUED_queue() { + instanceKlass* ik = instanceKlass::cast(SystemDictionary::ReferenceQueue_klass()); + oop mirror = ik->java_mirror(); + return mirror->obj_field(static_ENQUEUED_queue_offset); +} + +void java_lang_ref_ReferenceQueue::compute_offsets() { + klassOop k = SystemDictionary::ReferenceQueue_klass(); + compute_offset(static_NULL_queue_offset, + k, + vmSymbols::referencequeue_null_name(), + vmSymbols::referencequeue_signature()); + compute_offset(static_ENQUEUED_queue_offset, + k, + vmSymbols::referencequeue_enqueued_name(), + vmSymbols::referencequeue_signature()); +} + // Support for java_lang_invoke_DirectMethodHandle int java_lang_invoke_DirectMethodHandle::_member_offset; @@ -2921,6 +2947,8 @@ int java_lang_ref_Reference::static_lock_offset; int java_lang_ref_Reference::static_pending_offset; int java_lang_ref_Reference::number_of_fake_oop_fields; +int java_lang_ref_ReferenceQueue::static_NULL_queue_offset; +int java_lang_ref_ReferenceQueue::static_ENQUEUED_queue_offset; int java_lang_ref_SoftReference::timestamp_offset; int java_lang_ref_SoftReference::static_clock_offset; int java_lang_ClassLoader::parent_offset; @@ -3100,6 +3128,8 @@ sun_reflect_UnsafeStaticFieldAccessorImpl::compute_offsets(); } + java_lang_ref_ReferenceQueue::compute_offsets(); + // generated interpreter code wants to know about the offsets we just computed: AbstractAssembler::update_delayed_values(); }
--- a/src/share/vm/classfile/javaClasses.hpp Wed May 23 17:39:33 2018 +0100 +++ b/src/share/vm/classfile/javaClasses.hpp Wed Apr 18 02:18:40 2018 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -859,6 +859,12 @@ static HeapWord* discovered_addr(oop ref) { return ref->obj_field_addr<HeapWord>(discovered_offset); } + static inline oop queue(oop ref) { + return ref->obj_field(queue_offset); + } + static inline void set_queue(oop ref, oop value) { + return ref->obj_field_put(queue_offset, value); + } // Accessors for statics static oop pending_list_lock(); static oop pending_list(); @@ -891,6 +897,20 @@ }; +// Interface to java.lang.ref.ReferenceQueue objects + +class java_lang_ref_ReferenceQueue: public AllStatic { +public: + static int static_NULL_queue_offset; + static int static_ENQUEUED_queue_offset; + + // Accessors + static oop NULL_queue(); + static oop ENQUEUED_queue(); + + static void compute_offsets(); +}; + // Interface to java.lang.invoke.MethodHandle objects class MethodHandleEntry;
--- a/src/share/vm/classfile/systemDictionary.cpp Wed May 23 17:39:33 2018 +0100 +++ b/src/share/vm/classfile/systemDictionary.cpp Wed Apr 18 02:18:40 2018 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -1903,6 +1903,8 @@ instanceKlass::cast(WK_KLASS(PhantomReference_klass))->set_reference_type(REF_PHANTOM); instanceKlass::cast(WK_KLASS(Cleaner_klass))->set_reference_type(REF_CLEANER); + initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(ReferenceQueue_klass), scan, CHECK); + // JSR 292 classes WKID jsr292_group_start = WK_KLASS_ENUM_NAME(MethodHandle_klass); WKID jsr292_group_end = WK_KLASS_ENUM_NAME(VolatileCallSite_klass);
--- a/src/share/vm/classfile/systemDictionary.hpp Wed May 23 17:39:33 2018 +0100 +++ b/src/share/vm/classfile/systemDictionary.hpp Wed Apr 18 02:18:40 2018 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -128,6 +128,7 @@ do_klass(PhantomReference_klass, java_lang_ref_PhantomReference, Pre ) \ do_klass(Cleaner_klass, sun_misc_Cleaner, Pre ) \ do_klass(Finalizer_klass, java_lang_ref_Finalizer, Pre ) \ + do_klass(ReferenceQueue_klass, java_lang_ref_ReferenceQueue, Pre ) \ \ do_klass(Thread_klass, java_lang_Thread, Pre ) \ do_klass(ThreadGroup_klass, java_lang_ThreadGroup, Pre ) \
--- a/src/share/vm/classfile/vmSymbols.hpp Wed May 23 17:39:33 2018 +0100 +++ b/src/share/vm/classfile/vmSymbols.hpp Wed Apr 18 02:18:40 2018 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -83,6 +83,7 @@ template(java_lang_ref_PhantomReference, "java/lang/ref/PhantomReference") \ template(sun_misc_Cleaner, "sun/misc/Cleaner") \ template(java_lang_ref_Finalizer, "java/lang/ref/Finalizer") \ + template(java_lang_ref_ReferenceQueue, "java/lang/ref/ReferenceQueue") \ template(java_lang_reflect_AccessibleObject, "java/lang/reflect/AccessibleObject") \ template(java_lang_reflect_Method, "java/lang/reflect/Method") \ template(java_lang_reflect_Constructor, "java/lang/reflect/Constructor") \ @@ -379,6 +380,8 @@ template(array_klass_name, "array_klass") \ template(oop_size_name, "oop_size") \ template(static_oop_field_count_name, "static_oop_field_count") \ + template(referencequeue_null_name, "NULL") \ + template(referencequeue_enqueued_name, "ENQUEUED") \ \ /* non-intrinsic name/signature pairs: */ \ template(register_method_name, "register") \ @@ -469,6 +472,7 @@ template(class_signature, "Ljava/lang/Class;") \ template(string_signature, "Ljava/lang/String;") \ template(reference_signature, "Ljava/lang/ref/Reference;") \ + template(referencequeue_signature, "Ljava/lang/ref/ReferenceQueue;") \ template(concurrenthashmap_signature, "Ljava/util/concurrent/ConcurrentHashMap;") \ template(String_StringBuilder_signature, "(Ljava/lang/String;)Ljava/lang/StringBuilder;") \ template(int_StringBuilder_signature, "(I)Ljava/lang/StringBuilder;") \
--- a/src/share/vm/oops/klass.cpp Wed May 23 17:39:33 2018 +0100 +++ b/src/share/vm/oops/klass.cpp Wed Apr 18 02:18:40 2018 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -36,6 +36,19 @@ #include "runtime/atomic.hpp" #include "trace/traceMacros.hpp" +bool Klass::is_cloneable() const { + return _access_flags.is_cloneable() || + is_subtype_of(SystemDictionary::Cloneable_klass()); +} + +void Klass::set_is_cloneable() { + if (oop_is_instance() && instanceKlass::cast(this->as_klassOop())->reference_type() != REF_NONE) { + // Reference cloning should not be intrinsified and always happen in JVM_Clone. + } else { + _access_flags.set_is_cloneable(); + } +} + void Klass::set_name(Symbol* n) { _name = n; if (_name != NULL) _name->increment_refcount();
--- a/src/share/vm/oops/klass.hpp Wed May 23 17:39:33 2018 +0100 +++ b/src/share/vm/oops/klass.hpp Wed Apr 18 02:18:40 2018 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -673,8 +673,8 @@ bool has_final_method() const { return _access_flags.has_final_method(); } void set_has_finalizer() { _access_flags.set_has_finalizer(); } void set_has_final_method() { _access_flags.set_has_final_method(); } - bool is_cloneable() const { return _access_flags.is_cloneable(); } - void set_is_cloneable() { _access_flags.set_is_cloneable(); } + bool is_cloneable() const; + void set_is_cloneable(); bool has_vanilla_constructor() const { return _access_flags.has_vanilla_constructor(); } void set_has_vanilla_constructor() { _access_flags.set_has_vanilla_constructor(); } bool has_miranda_methods () const { return access_flags().has_miranda_methods(); }
--- a/src/share/vm/prims/jvm.cpp Wed May 23 17:39:33 2018 +0100 +++ b/src/share/vm/prims/jvm.cpp Wed Apr 18 02:18:40 2018 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -31,6 +31,7 @@ #include "classfile/vmSymbols.hpp" #include "gc_interface/collectedHeap.inline.hpp" #include "memory/oopFactory.hpp" +#include "memory/referenceType.hpp" #include "memory/universe.inline.hpp" #include "oops/fieldStreams.hpp" #include "oops/instanceKlass.hpp" @@ -82,6 +83,10 @@ # include "jvm_bsd.h" #endif +#ifndef SERIALGC +#include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp" +#endif // !SERIALGC + #include <errno.h> #ifndef USDT2 @@ -574,6 +579,28 @@ JVM_END +static void fixup_cloned_reference(ReferenceType ref_type, oop src, oop clone) { + // If G1 is enabled then we need to register a non-null referent + // with the SATB barrier. +#ifndef SERIALGC + if (UseG1GC) { + oop referent = java_lang_ref_Reference::referent(clone); + if (referent != NULL) { + G1SATBCardTableModRefBS::enqueue(referent); + } + } +#endif // !SERIALGC + if ((java_lang_ref_Reference::next(clone) != NULL) || + (java_lang_ref_Reference::queue(clone) == java_lang_ref_ReferenceQueue::ENQUEUED_queue())) { + // If the source has been enqueued or is being enqueued, don't + // register the clone with a queue. + java_lang_ref_Reference::set_queue(clone, java_lang_ref_ReferenceQueue::NULL_queue()); + } + // discovered and next are list links; the clone is not in those lists. + java_lang_ref_Reference::set_discovered(clone, NULL); + java_lang_ref_Reference::set_next(clone, NULL); +} + JVM_ENTRY(jobject, JVM_Clone(JNIEnv* env, jobject handle)) JVMWrapper("JVM_Clone"); Handle obj(THREAD, JNIHandles::resolve_non_null(handle)); @@ -599,12 +626,17 @@ } // Make shallow object copy + ReferenceType ref_type = REF_NONE; const int size = obj->size(); oop new_obj_oop = NULL; if (obj->is_javaArray()) { const int length = ((arrayOop)obj())->length(); new_obj_oop = CollectedHeap::array_allocate(klass, size, length, CHECK_NULL); } else { + ref_type = instanceKlass::cast(klass())->reference_type(); + assert((ref_type == REF_NONE) == + !klass->is_subclass_of(SystemDictionary::Reference_klass()), + "invariant"); new_obj_oop = CollectedHeap::obj_allocate(klass, size, CHECK_NULL); } // 4839641 (4840070): We must do an oop-atomic copy, because if another thread @@ -627,6 +659,12 @@ assert(bs->has_write_region_opt(), "Barrier set does not have write_region"); bs->write_region(MemRegion((HeapWord*)new_obj_oop, size)); + // If cloning a Reference, set Reference fields to a safe state. + // Fixup must be completed before any safepoint. + if (ref_type != REF_NONE) { + fixup_cloned_reference(ref_type, obj(), new_obj_oop); + } + Handle new_obj(THREAD, new_obj_oop); // Special handling for MemberNames. Since they contain Method* metadata, they // must be registered so that RedefineClasses can fix metadata contained in them.