< prev index next >

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

Print this page

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 
31 ZObjArrayAllocator::ZObjArrayAllocator(Klass* klass, size_t word_size, int length, Thread* thread) :
32     ObjArrayAllocator(klass, word_size, length, false /* do_zero */, thread) {}
33 
34 oop ZObjArrayAllocator::finish(HeapWord* mem) const {
35   // Initialize object header and length field
36   ObjArrayAllocator::finish(mem);
37 
38   // Keep the array alive across safepoints through an invisible
39   // root. Invisible roots are not visited by the heap itarator
40   // and the marking logic will not attempt to follow its elements.
41   ZThreadLocalData::set_invisible_root(_thread, (oop*)&mem);
42 
43   // A max segment size of 64K was chosen because microbenchmarking
44   // suggested that it offered a good trade-off between allocation
45   // time and time-to-safepoint
46   const size_t segment_max = ZUtils::bytes_to_words(64 * K);
47   const size_t skip = arrayOopDesc::header_size(ArrayKlass::cast(_klass)->element_type());
48   size_t remaining = _word_size - skip;

49 

50   while (remaining > 0) {
51     // Clear segment
52     const size_t segment = MIN2(remaining, segment_max);
53     Copy::zero_to_words(mem + (_word_size - remaining), segment);
54     remaining -= segment;
55 
56     if (remaining > 0) {
57       // Safepoint
58       ThreadBlockInVM tbivm(_thread->as_Java_thread());
59     }
60   }
61 
62   ZThreadLocalData::clear_invisible_root(_thread);
63 
64   return cast_to_oop(mem);
65 }

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 
31 ZObjArrayAllocator::ZObjArrayAllocator(Klass* klass, size_t word_size, int length, Thread* thread) :
32     ObjArrayAllocator(klass, word_size, length, false /* do_zero */, thread) {}
33 
34 oop ZObjArrayAllocator::finish(HeapWord* mem) const {
35   // Initialize object header and length field
36   ObjArrayAllocator::finish(mem);
37 
38   // Keep the array alive across safepoints through an invisible
39   // root. Invisible roots are not visited by the heap itarator
40   // and the marking logic will not attempt to follow its elements.
41   ZThreadLocalData::set_invisible_root(_thread, (oop*)&mem);
42 
43   // A max segment size of 64K was chosen because microbenchmarking
44   // suggested that it offered a good trade-off between allocation
45   // time and time-to-safepoint
46   const size_t segment_max = 64 * K;
47   const size_t skip = arrayOopDesc::base_offset_in_bytes(ArrayKlass::cast(_klass)->element_type());
48   size_t byte_size = _word_size * BytesPerWord;
49   size_t remaining = byte_size - skip;
50 
51   char* const start = reinterpret_cast<char*>(mem);
52   while (remaining > 0) {
53     // Clear segment
54     const size_t segment = MIN2(remaining, segment_max);
55     Copy::zero_to_bytes(start + (byte_size - remaining), segment);
56     remaining -= segment;
57 
58     if (remaining > 0) {
59       // Safepoint
60       ThreadBlockInVM tbivm(_thread->as_Java_thread());
61     }
62   }
63 
64   ZThreadLocalData::clear_invisible_root(_thread);
65 
66   return cast_to_oop(mem);
67 }
< prev index next >