< 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 
 53   if (_word_size <= segment_max) {
 54     // To small to use segmented clearing
 55     return ObjArrayAllocator::initialize(mem);
 56   }
 57 
 58   // Segmented clearing
 59 
 60   // The array is going to be exposed before it has been completely
 61   // cleared, therefore we can't expose the header at the end of this
 62   // function. Instead explicitly initialize it according to our needs.
 63 
 64   // Signal to the ZIterator that this is an invisible root, by setting
 65   // the mark word to "marked". Reset to prototype() after the clearing.
 66   arrayOopDesc::set_mark(mem, markWord::prototype().set_marked());
 67   arrayOopDesc::release_set_klass(mem, _klass);
 68   assert(_length >= 0, "length should be non-negative");
 69   arrayOopDesc::set_length(mem, _length);
 70 
 71   // Keep the array alive across safepoints through an invisible
 72   // root. Invisible roots are not visited by the heap iterator
 73   // and the marking logic will not attempt to follow its elements.
 74   // Relocation and remembered set code know how to dodge iterating
 75   // over such objects.
 76   ZThreadLocalData::set_invisible_root(_thread, (zaddress_unsafe*)&mem);
 77 
 78   const BasicType element_type = ArrayKlass::cast(_klass)->element_type();
 79   const size_t base_offset_in_bytes = (size_t)arrayOopDesc::base_offset_in_bytes(element_type);
 80   const size_t process_start_offset_in_bytes = align_up(base_offset_in_bytes, (size_t)BytesPerWord);
 81 
 82   if (process_start_offset_in_bytes != base_offset_in_bytes) {
 83     // initialize_memory can only fill word aligned memory,
 84     // fill the first 4 bytes here.
 85     assert(process_start_offset_in_bytes - base_offset_in_bytes == 4, "Must be 4-byte aligned");
 86     assert(!is_reference_type(element_type), "Only TypeArrays can be 4-byte aligned");

135         seen_gc_safepoint = true;
136         return false;
137       }
138     }
139     return true;
140   };
141 
142   mem_zap_start_padding(mem);
143 
144   if (!initialize_memory()) {
145     // Re-color with 11 remset bits if we got intercepted by a GC safepoint
146     const bool result = initialize_memory();
147     assert(result, "Array initialization should always succeed the second time");
148   }
149 
150   mem_zap_end_padding(mem);
151 
152   ZThreadLocalData::clear_invisible_root(_thread);
153 
154   // Signal to the ZIterator that this is no longer an invisible root
155   oopDesc::release_set_mark(mem, markWord::prototype());
156 
157   return cast_to_oop(mem);
158 }

 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 
 54   if (_word_size <= segment_max || ArrayKlass::cast(_klass)->is_flatArray_klass()) {
 55     // To small to use segmented clearing
 56     return ObjArrayAllocator::initialize(mem);
 57   }
 58 
 59   // Segmented clearing
 60 
 61   // The array is going to be exposed before it has been completely
 62   // cleared, therefore we can't expose the header at the end of this
 63   // function. Instead explicitly initialize it according to our needs.
 64 
 65   // Signal to the ZIterator that this is an invisible root, by setting
 66   // the mark word to "marked". Reset to prototype() after the clearing.
 67   arrayOopDesc::set_mark(mem, Klass::default_prototype_header(_klass).set_marked());
 68   arrayOopDesc::release_set_klass(mem, _klass);
 69   assert(_length >= 0, "length should be non-negative");
 70   arrayOopDesc::set_length(mem, _length);
 71 
 72   // Keep the array alive across safepoints through an invisible
 73   // root. Invisible roots are not visited by the heap iterator
 74   // and the marking logic will not attempt to follow its elements.
 75   // Relocation and remembered set code know how to dodge iterating
 76   // over such objects.
 77   ZThreadLocalData::set_invisible_root(_thread, (zaddress_unsafe*)&mem);
 78 
 79   const BasicType element_type = ArrayKlass::cast(_klass)->element_type();
 80   const size_t base_offset_in_bytes = (size_t)arrayOopDesc::base_offset_in_bytes(element_type);
 81   const size_t process_start_offset_in_bytes = align_up(base_offset_in_bytes, (size_t)BytesPerWord);
 82 
 83   if (process_start_offset_in_bytes != base_offset_in_bytes) {
 84     // initialize_memory can only fill word aligned memory,
 85     // fill the first 4 bytes here.
 86     assert(process_start_offset_in_bytes - base_offset_in_bytes == 4, "Must be 4-byte aligned");
 87     assert(!is_reference_type(element_type), "Only TypeArrays can be 4-byte aligned");

136         seen_gc_safepoint = true;
137         return false;
138       }
139     }
140     return true;
141   };
142 
143   mem_zap_start_padding(mem);
144 
145   if (!initialize_memory()) {
146     // Re-color with 11 remset bits if we got intercepted by a GC safepoint
147     const bool result = initialize_memory();
148     assert(result, "Array initialization should always succeed the second time");
149   }
150 
151   mem_zap_end_padding(mem);
152 
153   ZThreadLocalData::clear_invisible_root(_thread);
154 
155   // Signal to the ZIterator that this is no longer an invisible root
156   oopDesc::release_set_mark(mem, Klass::default_prototype_header(_klass));
157 
158   return cast_to_oop(mem);
159 }
< prev index next >