< prev index next >

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

Print this page

 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 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 "gc/z/zThreadLocalData.hpp"
 25 #include "gc/z/zObjArrayAllocator.hpp"
 26 #include "gc/z/zUtils.inline.hpp"
 27 #include "oops/arrayKlass.hpp"
 28 #include "runtime/interfaceSupport.inline.hpp"
 29 #include "utilities/debug.hpp"

 30 
 31 ZObjArrayAllocator::ZObjArrayAllocator(Klass* klass, size_t word_size, int length, bool do_zero, Thread* thread)
 32   : ObjArrayAllocator(klass, word_size, length, do_zero, thread) {}
 33 
 34 void ZObjArrayAllocator::yield_for_safepoint() const {
 35   ThreadBlockInVM tbivm(JavaThread::cast(_thread));
 36 }
 37 
 38 oop ZObjArrayAllocator::initialize(HeapWord* mem) const {
 39   // ZGC specializes the initialization by performing segmented clearing
 40   // to allow shorter time-to-safepoints.
 41 
 42   if (!_do_zero) {
 43     // No need for ZGC specialization
 44     return ObjArrayAllocator::initialize(mem);
 45   }
 46 
 47   // A max segment size of 64K was chosen because microbenchmarking
 48   // suggested that it offered a good trade-off between allocation
 49   // time and time-to-safepoint
 50   const size_t segment_max = ZUtils::bytes_to_words(64 * K);
 51 
 52   if (_word_size <= segment_max) {
 53     // To small to use segmented clearing
 54     return ObjArrayAllocator::initialize(mem);
 55   }
 56 
 57   // Segmented clearing
 58 
 59   // The array is going to be exposed before it has been completely
 60   // cleared, therefore we can't expose the header at the end of this
 61   // function. Instead explicitly initialize it according to our needs.
 62 
 63   // Signal to the ZIterator that this is an invisible root, by setting
 64   // the mark word to "marked". Reset to prototype() after the clearing.
 65   if (UseCompactObjectHeaders) {
 66     oopDesc::release_set_mark(mem, _klass->prototype_header().set_marked());
 67   } else {
 68     arrayOopDesc::set_mark(mem, markWord::prototype().set_marked());




 69     arrayOopDesc::release_set_klass(mem, _klass);
 70   }
 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   const BasicType element_type = ArrayKlass::cast(_klass)->element_type();
 82   const size_t base_offset_in_bytes = (size_t)arrayOopDesc::base_offset_in_bytes(element_type);
 83   const size_t process_start_offset_in_bytes = align_up(base_offset_in_bytes, (size_t)BytesPerWord);
 84 
 85   if (process_start_offset_in_bytes != base_offset_in_bytes) {
 86     // initialize_memory can only fill word aligned memory,
 87     // fill the first 4 bytes here.
 88     assert(process_start_offset_in_bytes - base_offset_in_bytes == 4, "Must be 4-byte aligned");

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

 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 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 "gc/z/zThreadLocalData.hpp"
 25 #include "gc/z/zObjArrayAllocator.hpp"
 26 #include "gc/z/zUtils.inline.hpp"
 27 #include "oops/arrayKlass.hpp"
 28 #include "runtime/interfaceSupport.inline.hpp"
 29 #include "utilities/debug.hpp"
 30 #include "utilities/globalDefinitions.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 || ArrayKlass::cast(_klass)->is_flatArray_klass()) {
 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   if (UseCompactObjectHeaders) {
 67     oopDesc::release_set_mark(mem, _klass->prototype_header().set_marked());
 68   } else {
 69     if (EnableValhalla) {
 70       arrayOopDesc::set_mark(mem, _klass->prototype_header().set_marked());
 71     } else {
 72       arrayOopDesc::set_mark(mem, markWord::prototype().set_marked());
 73     }
 74     arrayOopDesc::release_set_klass(mem, _klass);
 75   }
 76   assert(_length >= 0, "length should be non-negative");
 77   arrayOopDesc::set_length(mem, _length);
 78 
 79   // Keep the array alive across safepoints through an invisible
 80   // root. Invisible roots are not visited by the heap iterator
 81   // and the marking logic will not attempt to follow its elements.
 82   // Relocation and remembered set code know how to dodge iterating
 83   // over such objects.
 84   ZThreadLocalData::set_invisible_root(_thread, (zaddress_unsafe*)&mem);
 85 
 86   const BasicType element_type = ArrayKlass::cast(_klass)->element_type();
 87   const size_t base_offset_in_bytes = (size_t)arrayOopDesc::base_offset_in_bytes(element_type);
 88   const size_t process_start_offset_in_bytes = align_up(base_offset_in_bytes, (size_t)BytesPerWord);
 89 
 90   if (process_start_offset_in_bytes != base_offset_in_bytes) {
 91     // initialize_memory can only fill word aligned memory,
 92     // fill the first 4 bytes here.
 93     assert(process_start_offset_in_bytes - base_offset_in_bytes == 4, "Must be 4-byte aligned");

143         seen_gc_safepoint = true;
144         return false;
145       }
146     }
147     return true;
148   };
149 
150   mem_zap_start_padding(mem);
151 
152   if (!initialize_memory()) {
153     // Re-color with 11 remset bits if we got intercepted by a GC safepoint
154     const bool result = initialize_memory();
155     assert(result, "Array initialization should always succeed the second time");
156   }
157 
158   mem_zap_end_padding(mem);
159 
160   ZThreadLocalData::clear_invisible_root(_thread);
161 
162   // Signal to the ZIterator that this is no longer an invisible root
163   if (UseCompactObjectHeaders || EnableValhalla) {
164     oopDesc::release_set_mark(mem, _klass->prototype_header());
165   } else {
166     oopDesc::release_set_mark(mem, markWord::prototype());
167   }
168 
169   return cast_to_oop(mem);
170 }
< prev index next >