< prev index next >

src/hotspot/share/gc/z/zObjArrayAllocator.cpp

Print this page

 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 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 #include "precompiled.hpp"
 25 #include "gc/z/zThreadLocalData.hpp"
 26 #include "gc/z/zObjArrayAllocator.hpp"
 27 #include "gc/z/zUtils.inline.hpp"
 28 #include "oops/arrayKlass.hpp"
 29 #include "runtime/interfaceSupport.inline.hpp"
 30 #include "utilities/debug.hpp"

 31 
 32 ZObjArrayAllocator::ZObjArrayAllocator(Klass* klass, size_t word_size, int length, bool do_zero, Thread* thread)
 33   : ObjArrayAllocator(klass, word_size, length, do_zero, thread) {}
 34 
 35 void ZObjArrayAllocator::yield_for_safepoint() const {
 36   ThreadBlockInVM tbivm(JavaThread::cast(_thread));
 37 }
 38 
 39 oop ZObjArrayAllocator::initialize(HeapWord* mem) const {
 40   // ZGC specializes the initialization by performing segmented clearing
 41   // to allow shorter time-to-safepoints.
 42 
 43   if (!_do_zero) {
 44     // No need for ZGC specialization
 45     return ObjArrayAllocator::initialize(mem);
 46   }
 47 
 48   // A max segment size of 64K was chosen because microbenchmarking
 49   // suggested that it offered a good trade-off between allocation
 50   // time and time-to-safepoint
 51   const size_t segment_max = ZUtils::bytes_to_words(64 * K);
 52   const BasicType element_type = ArrayKlass::cast(_klass)->element_type();
 53   const size_t header = arrayOopDesc::header_size(element_type);
 54   const size_t payload_size = _word_size - header;
 55 
 56   if (payload_size <= segment_max) {
 57     // To small to use segmented clearing
 58     return ObjArrayAllocator::initialize(mem);
 59   }
 60 
 61   // Segmented clearing
 62 
 63   // The array is going to be exposed before it has been completely
 64   // cleared, therefore we can't expose the header at the end of this
 65   // function. Instead explicitly initialize it according to our needs.
 66 
 67   // Signal to the ZIterator that this is an invisible root, by setting
 68   // the mark word to "marked". Reset to prototype() after the clearing.
 69   arrayOopDesc::set_mark(mem, markWord::prototype().set_marked());
 70   arrayOopDesc::release_set_klass(mem, _klass);
 71   assert(_length >= 0, "length should be non-negative");
 72   arrayOopDesc::set_length(mem, _length);
 73 
 74   // Keep the array alive across safepoints through an invisible
 75   // root. Invisible roots are not visited by the heap iterator
 76   // and the marking logic will not attempt to follow its elements.
 77   // Relocation and remembered set code know how to dodge iterating
 78   // over such objects.
 79   ZThreadLocalData::set_invisible_root(_thread, (zaddress_unsafe*)&mem);
 80 
 81   uint32_t old_seqnum_before = ZGeneration::old()->seqnum();
 82   uint32_t young_seqnum_before = ZGeneration::young()->seqnum();
 83   uintptr_t color_before = ZPointerStoreGoodMask;
 84   auto gc_safepoint_happened = [&]() {
 85     return old_seqnum_before != ZGeneration::old()->seqnum() ||
 86            young_seqnum_before != ZGeneration::young()->seqnum() ||
 87            color_before != ZPointerStoreGoodMask;
 88   };
 89 

118       // Deal with safepoints
119       if (!seen_gc_safepoint && gc_safepoint_happened()) {
120         // The first time we observe a GC safepoint in the yield point,
121         // we have to restart processing with 11 remembered bits.
122         seen_gc_safepoint = true;
123         return false;
124       }
125     }
126     return true;
127   };
128 
129   if (!initialize_memory()) {
130     // Re-color with 11 remset bits if we got intercepted by a GC safepoint
131     const bool result = initialize_memory();
132     assert(result, "Array initialization should always succeed the second time");
133   }
134 
135   ZThreadLocalData::clear_invisible_root(_thread);
136 
137   // Signal to the ZIterator that this is no longer an invisible root
138   oopDesc::release_set_mark(mem, markWord::prototype());
139 
140   return cast_to_oop(mem);
141 }

 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 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 #include "precompiled.hpp"
 25 #include "gc/z/zThreadLocalData.hpp"
 26 #include "gc/z/zObjArrayAllocator.hpp"
 27 #include "gc/z/zUtils.inline.hpp"
 28 #include "oops/arrayKlass.hpp"
 29 #include "runtime/interfaceSupport.inline.hpp"
 30 #include "utilities/debug.hpp"
 31 #include "utilities/globalDefinitions.hpp"
 32 
 33 ZObjArrayAllocator::ZObjArrayAllocator(Klass* klass, size_t word_size, int length, bool do_zero, Thread* thread)
 34   : ObjArrayAllocator(klass, word_size, length, do_zero, thread) {}
 35 
 36 void ZObjArrayAllocator::yield_for_safepoint() const {
 37   ThreadBlockInVM tbivm(JavaThread::cast(_thread));
 38 }
 39 
 40 oop ZObjArrayAllocator::initialize(HeapWord* mem) const {
 41   // ZGC specializes the initialization by performing segmented clearing
 42   // to allow shorter time-to-safepoints.
 43 
 44   if (!_do_zero) {
 45     // No need for ZGC specialization
 46     return ObjArrayAllocator::initialize(mem);
 47   }
 48 
 49   // A max segment size of 64K was chosen because microbenchmarking
 50   // suggested that it offered a good trade-off between allocation
 51   // time and time-to-safepoint
 52   const size_t segment_max = ZUtils::bytes_to_words(64 * K);
 53   const BasicType element_type = ArrayKlass::cast(_klass)->element_type();
 54   const size_t header = arrayOopDesc::header_size(element_type);
 55   const size_t payload_size = _word_size - header;
 56 
 57   if (payload_size <= segment_max || ArrayKlass::cast(_klass)->is_flatArray_klass()) {
 58     // To small to use segmented clearing
 59     return ObjArrayAllocator::initialize(mem);
 60   }
 61 
 62   // Segmented clearing
 63 
 64   // The array is going to be exposed before it has been completely
 65   // cleared, therefore we can't expose the header at the end of this
 66   // function. Instead explicitly initialize it according to our needs.
 67 
 68   // Signal to the ZIterator that this is an invisible root, by setting
 69   // the mark word to "marked". Reset to prototype() after the clearing.
 70   arrayOopDesc::set_mark(mem, Klass::default_prototype_header(_klass).set_marked());
 71   arrayOopDesc::release_set_klass(mem, _klass);
 72   assert(_length >= 0, "length should be non-negative");
 73   arrayOopDesc::set_length(mem, _length);
 74 
 75   // Keep the array alive across safepoints through an invisible
 76   // root. Invisible roots are not visited by the heap iterator
 77   // and the marking logic will not attempt to follow its elements.
 78   // Relocation and remembered set code know how to dodge iterating
 79   // over such objects.
 80   ZThreadLocalData::set_invisible_root(_thread, (zaddress_unsafe*)&mem);
 81 
 82   uint32_t old_seqnum_before = ZGeneration::old()->seqnum();
 83   uint32_t young_seqnum_before = ZGeneration::young()->seqnum();
 84   uintptr_t color_before = ZPointerStoreGoodMask;
 85   auto gc_safepoint_happened = [&]() {
 86     return old_seqnum_before != ZGeneration::old()->seqnum() ||
 87            young_seqnum_before != ZGeneration::young()->seqnum() ||
 88            color_before != ZPointerStoreGoodMask;
 89   };
 90 

119       // Deal with safepoints
120       if (!seen_gc_safepoint && gc_safepoint_happened()) {
121         // The first time we observe a GC safepoint in the yield point,
122         // we have to restart processing with 11 remembered bits.
123         seen_gc_safepoint = true;
124         return false;
125       }
126     }
127     return true;
128   };
129 
130   if (!initialize_memory()) {
131     // Re-color with 11 remset bits if we got intercepted by a GC safepoint
132     const bool result = initialize_memory();
133     assert(result, "Array initialization should always succeed the second time");
134   }
135 
136   ZThreadLocalData::clear_invisible_root(_thread);
137 
138   // Signal to the ZIterator that this is no longer an invisible root
139   oopDesc::release_set_mark(mem, Klass::default_prototype_header(_klass));
140 
141   return cast_to_oop(mem);
142 }
< prev index next >