23 */ |
23 */ |
24 |
24 |
25 #ifndef SHARE_VM_GC_INTERFACE_COLLECTEDHEAP_INLINE_HPP |
25 #ifndef SHARE_VM_GC_INTERFACE_COLLECTEDHEAP_INLINE_HPP |
26 #define SHARE_VM_GC_INTERFACE_COLLECTEDHEAP_INLINE_HPP |
26 #define SHARE_VM_GC_INTERFACE_COLLECTEDHEAP_INLINE_HPP |
27 |
27 |
|
28 #include "gc_interface/allocTracer.hpp" |
28 #include "gc_interface/collectedHeap.hpp" |
29 #include "gc_interface/collectedHeap.hpp" |
29 #include "memory/threadLocalAllocBuffer.inline.hpp" |
30 #include "memory/threadLocalAllocBuffer.inline.hpp" |
30 #include "memory/universe.hpp" |
31 #include "memory/universe.hpp" |
31 #include "oops/arrayOop.hpp" |
32 #include "oops/arrayOop.hpp" |
32 #include "prims/jvmtiExport.hpp" |
33 #include "prims/jvmtiExport.hpp" |
105 assert(((oop)obj)->is_array(), "must be an array"); |
106 assert(((oop)obj)->is_array(), "must be an array"); |
106 // notify jvmti and dtrace (must be after length is set for dtrace) |
107 // notify jvmti and dtrace (must be after length is set for dtrace) |
107 post_allocation_notify(klass, (oop)obj); |
108 post_allocation_notify(klass, (oop)obj); |
108 } |
109 } |
109 |
110 |
110 HeapWord* CollectedHeap::common_mem_allocate_noinit(size_t size, TRAPS) { |
111 HeapWord* CollectedHeap::common_mem_allocate_noinit(KlassHandle klass, size_t size, TRAPS) { |
111 |
112 |
112 // Clear unhandled oops for memory allocation. Memory allocation might |
113 // Clear unhandled oops for memory allocation. Memory allocation might |
113 // not take out a lock if from tlab, so clear here. |
114 // not take out a lock if from tlab, so clear here. |
114 CHECK_UNHANDLED_OOPS_ONLY(THREAD->clear_unhandled_oops();) |
115 CHECK_UNHANDLED_OOPS_ONLY(THREAD->clear_unhandled_oops();) |
115 |
116 |
118 return NULL; // caller does a CHECK_0 too |
119 return NULL; // caller does a CHECK_0 too |
119 } |
120 } |
120 |
121 |
121 HeapWord* result = NULL; |
122 HeapWord* result = NULL; |
122 if (UseTLAB) { |
123 if (UseTLAB) { |
123 result = CollectedHeap::allocate_from_tlab(THREAD, size); |
124 result = allocate_from_tlab(klass, THREAD, size); |
124 if (result != NULL) { |
125 if (result != NULL) { |
125 assert(!HAS_PENDING_EXCEPTION, |
126 assert(!HAS_PENDING_EXCEPTION, |
126 "Unexpected exception, will result in uninitialized storage"); |
127 "Unexpected exception, will result in uninitialized storage"); |
127 return result; |
128 return result; |
128 } |
129 } |
134 NOT_PRODUCT(Universe::heap()-> |
135 NOT_PRODUCT(Universe::heap()-> |
135 check_for_non_bad_heap_word_value(result, size)); |
136 check_for_non_bad_heap_word_value(result, size)); |
136 assert(!HAS_PENDING_EXCEPTION, |
137 assert(!HAS_PENDING_EXCEPTION, |
137 "Unexpected exception, will result in uninitialized storage"); |
138 "Unexpected exception, will result in uninitialized storage"); |
138 THREAD->incr_allocated_bytes(size * HeapWordSize); |
139 THREAD->incr_allocated_bytes(size * HeapWordSize); |
|
140 |
|
141 AllocTracer::send_allocation_outside_tlab_event(klass, size * HeapWordSize); |
|
142 |
139 return result; |
143 return result; |
140 } |
144 } |
141 |
145 |
142 |
146 |
143 if (!gc_overhead_limit_was_exceeded) { |
147 if (!gc_overhead_limit_was_exceeded) { |
163 |
167 |
164 THROW_OOP_0(Universe::out_of_memory_error_gc_overhead_limit()); |
168 THROW_OOP_0(Universe::out_of_memory_error_gc_overhead_limit()); |
165 } |
169 } |
166 } |
170 } |
167 |
171 |
168 HeapWord* CollectedHeap::common_mem_allocate_init(size_t size, TRAPS) { |
172 HeapWord* CollectedHeap::common_mem_allocate_init(KlassHandle klass, size_t size, TRAPS) { |
169 HeapWord* obj = common_mem_allocate_noinit(size, CHECK_NULL); |
173 HeapWord* obj = common_mem_allocate_noinit(klass, size, CHECK_NULL); |
170 init_obj(obj, size); |
174 init_obj(obj, size); |
171 return obj; |
175 return obj; |
172 } |
176 } |
173 |
177 |
174 HeapWord* CollectedHeap::allocate_from_tlab(Thread* thread, size_t size) { |
178 HeapWord* CollectedHeap::allocate_from_tlab(KlassHandle klass, Thread* thread, size_t size) { |
175 assert(UseTLAB, "should use UseTLAB"); |
179 assert(UseTLAB, "should use UseTLAB"); |
176 |
180 |
177 HeapWord* obj = thread->tlab().allocate(size); |
181 HeapWord* obj = thread->tlab().allocate(size); |
178 if (obj != NULL) { |
182 if (obj != NULL) { |
179 return obj; |
183 return obj; |
180 } |
184 } |
181 // Otherwise... |
185 // Otherwise... |
182 return allocate_from_tlab_slow(thread, size); |
186 return allocate_from_tlab_slow(klass, thread, size); |
183 } |
187 } |
184 |
188 |
185 void CollectedHeap::init_obj(HeapWord* obj, size_t size) { |
189 void CollectedHeap::init_obj(HeapWord* obj, size_t size) { |
186 assert(obj != NULL, "cannot initialize NULL object"); |
190 assert(obj != NULL, "cannot initialize NULL object"); |
187 const size_t hs = oopDesc::header_size(); |
191 const size_t hs = oopDesc::header_size(); |
192 |
196 |
193 oop CollectedHeap::obj_allocate(KlassHandle klass, int size, TRAPS) { |
197 oop CollectedHeap::obj_allocate(KlassHandle klass, int size, TRAPS) { |
194 debug_only(check_for_valid_allocation_state()); |
198 debug_only(check_for_valid_allocation_state()); |
195 assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed"); |
199 assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed"); |
196 assert(size >= 0, "int won't convert to size_t"); |
200 assert(size >= 0, "int won't convert to size_t"); |
197 HeapWord* obj = common_mem_allocate_init(size, CHECK_NULL); |
201 HeapWord* obj = common_mem_allocate_init(klass, size, CHECK_NULL); |
198 post_allocation_setup_obj(klass, obj); |
202 post_allocation_setup_obj(klass, obj); |
199 NOT_PRODUCT(Universe::heap()->check_for_bad_heap_word_value(obj, size)); |
203 NOT_PRODUCT(Universe::heap()->check_for_bad_heap_word_value(obj, size)); |
200 return (oop)obj; |
204 return (oop)obj; |
201 } |
205 } |
202 |
206 |
205 int length, |
209 int length, |
206 TRAPS) { |
210 TRAPS) { |
207 debug_only(check_for_valid_allocation_state()); |
211 debug_only(check_for_valid_allocation_state()); |
208 assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed"); |
212 assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed"); |
209 assert(size >= 0, "int won't convert to size_t"); |
213 assert(size >= 0, "int won't convert to size_t"); |
210 HeapWord* obj = common_mem_allocate_init(size, CHECK_NULL); |
214 HeapWord* obj = common_mem_allocate_init(klass, size, CHECK_NULL); |
211 post_allocation_setup_array(klass, obj, length); |
215 post_allocation_setup_array(klass, obj, length); |
212 NOT_PRODUCT(Universe::heap()->check_for_bad_heap_word_value(obj, size)); |
216 NOT_PRODUCT(Universe::heap()->check_for_bad_heap_word_value(obj, size)); |
213 return (oop)obj; |
217 return (oop)obj; |
214 } |
218 } |
215 |
219 |
218 int length, |
222 int length, |
219 TRAPS) { |
223 TRAPS) { |
220 debug_only(check_for_valid_allocation_state()); |
224 debug_only(check_for_valid_allocation_state()); |
221 assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed"); |
225 assert(!Universe::heap()->is_gc_active(), "Allocation during gc not allowed"); |
222 assert(size >= 0, "int won't convert to size_t"); |
226 assert(size >= 0, "int won't convert to size_t"); |
223 HeapWord* obj = common_mem_allocate_noinit(size, CHECK_NULL); |
227 HeapWord* obj = common_mem_allocate_noinit(klass, size, CHECK_NULL); |
224 ((oop)obj)->set_klass_gap(0); |
228 ((oop)obj)->set_klass_gap(0); |
225 post_allocation_setup_array(klass, obj, length); |
229 post_allocation_setup_array(klass, obj, length); |
226 #ifndef PRODUCT |
230 #ifndef PRODUCT |
227 const size_t hs = oopDesc::header_size()+1; |
231 const size_t hs = oopDesc::header_size()+1; |
228 Universe::heap()->check_for_non_bad_heap_word_value(obj+hs, size-hs); |
232 Universe::heap()->check_for_non_bad_heap_word_value(obj+hs, size-hs); |