< prev index next >

src/hotspot/share/opto/runtime.cpp

RFE_8195103_reduce_initial_card_marks

0 /*                                                                                                                         
1  * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.                                            
2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.                                                           
3  *                                                                                                                         
4  * This code is free software; you can redistribute it and/or modify it                                                    
5  * under the terms of the GNU General Public License version 2 only, as                                                    
6  * published by the Free Software Foundation.                                                                              
7  *                                                                                                                         
8  * This code is distributed in the hope that it will be useful, but WITHOUT                                                
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or                                                   
10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License                                                   
11  * version 2 for more details (a copy is included in the LICENSE file that                                                 
12  * accompanied this code).                                                                                                 
13  *                                                                                                                         
14  * You should have received a copy of the GNU General Public License version                                               
15  * 2 along with this work; if not, write to the Free Software Foundation,                                                  
16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.                                                           
17  *                                                                                                                         
18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA                                                 
19  * or visit www.oracle.com if you need additional information or have any                                                  
20  * questions.                                                                                                              

0 /*
1  * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3  *
4  * This code is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 2 only, as
6  * published by the Free Software Foundation.
7  *
8  * This code is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
11  * version 2 for more details (a copy is included in the LICENSE file that
12  * accompanied this code).
13  *
14  * You should have received a copy of the GNU General Public License version
15  * 2 along with this work; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17  *
18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19  * or visit www.oracle.com if you need additional information or have any
20  * questions.

176   CodeBlob* cb = CodeCache::find_blob(entry);                                                                              
177   RuntimeStub* rs =(RuntimeStub *)cb;                                                                                      
178   assert(rs != NULL && rs->is_runtime_stub(), "not a runtime stub");                                                       
179   return rs->name();                                                                                                       
180 #else                                                                                                                      
181   // Fast implementation for product mode (maybe it should be inlined too)                                                 
182   return "runtime stub";                                                                                                   
183 #endif                                                                                                                     
184 }                                                                                                                          
185 
186 
187 //=============================================================================                                            
188 // Opto compiler runtime routines                                                                                          
189 //=============================================================================                                            
190 
191 
192 //=============================allocation======================================                                            
193 // We failed the fast-path allocation.  Now we need to do a scavenge or GC                                                 
194 // and try allocation again.                                                                                               
195 
196 void OptoRuntime::new_store_pre_barrier(JavaThread* thread) {                                                              
197   // After any safepoint, just before going back to compiled code,                                                         
198   // we inform the GC that we will be doing initializing writes to                                                         
199   // this object in the future without emitting card-marks, so                                                             
200   // GC may take any compensating steps.                                                                                   
201   // NOTE: Keep this code consistent with GraphKit::store_barrier.                                                         
202                                                                                                                            
203   oop new_obj = thread->vm_result();                                                                                       
204   if (new_obj == NULL)  return;                                                                                            
205                                                                                                                            
206   assert(Universe::heap()->can_elide_tlab_store_barriers(),                                                                
207          "compiler must check this first");                                                                                
208   // GC may decide to give back a safer copy of new_obj.                                                                   
209   new_obj = Universe::heap()->new_store_pre_barrier(thread, new_obj);                                                      
210   thread->set_vm_result(new_obj);                                                                                          
211 }                                                                                                                          
212                                                                                                                            
213 // object allocation                                                                                                       
214 JRT_BLOCK_ENTRY(void, OptoRuntime::new_instance_C(Klass* klass, JavaThread* thread))                                       
215   JRT_BLOCK;                                                                                                               
216 #ifndef PRODUCT                                                                                                            
217   SharedRuntime::_new_instance_ctr++;         // new instance requires GC                                                  
218 #endif                                                                                                                     
219   assert(check_compiled_frame(thread), "incorrect caller");                                                                
220 
221   // These checks are cheap to make and support reflective allocation.                                                     
222   int lh = klass->layout_helper();                                                                                         
223   if (Klass::layout_helper_needs_slow_path(lh) || !InstanceKlass::cast(klass)->is_initialized()) {                         
224     Handle holder(THREAD, klass->klass_holder()); // keep the klass alive                                                  
225     klass->check_valid_for_instantiation(false, THREAD);                                                                   
226     if (!HAS_PENDING_EXCEPTION) {                                                                                          
227       InstanceKlass::cast(klass)->initialize(THREAD);                                                                      
228     }                                                                                                                      
229   }                                                                                                                        
230 
231   if (!HAS_PENDING_EXCEPTION) {                                                                                            
232     // Scavenge and allocate an instance.                                                                                  
233     Handle holder(THREAD, klass->klass_holder()); // keep the klass alive                                                  
234     oop result = InstanceKlass::cast(klass)->allocate_instance(THREAD);                                                    
235     thread->set_vm_result(result);                                                                                         
236 
237     // Pass oops back through thread local storage.  Our apparent type to Java                                             
238     // is that we return an oop, but we can block on exit from this routine and                                            
239     // a GC can trash the oop in C's return register.  The generated stub will                                             
240     // fetch the oop from TLS after any possible GC.                                                                       
241   }                                                                                                                        
242 
243   deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);                                                                  
244   JRT_BLOCK_END;                                                                                                           
245 
246   if (GraphKit::use_ReduceInitialCardMarks()) {                                                                            
247     // inform GC that we won't do card marks for initializing writes.                                                      
248     new_store_pre_barrier(thread);                                                                                         
249   }                                                                                                                        
250 JRT_END                                                                                                                    
251 
252 
253 // array allocation                                                                                                        
254 JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_C(Klass* array_type, int len, JavaThread *thread))                            
255   JRT_BLOCK;                                                                                                               
256 #ifndef PRODUCT                                                                                                            
257   SharedRuntime::_new_array_ctr++;            // new array requires GC                                                     
258 #endif                                                                                                                     
259   assert(check_compiled_frame(thread), "incorrect caller");                                                                
260 
261   // Scavenge and allocate an instance.                                                                                    
262   oop result;                                                                                                              
263 
264   if (array_type->is_typeArray_klass()) {                                                                                  
265     // The oopFactory likes to work with the element type.                                                                 
266     // (We could bypass the oopFactory, since it doesn't add much value.)                                                  
267     BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();                                                
268     result = oopFactory::new_typeArray(elem_type, len, THREAD);                                                            
269   } else {                                                                                                                 
270     // Although the oopFactory likes to work with the elem_type,                                                           
271     // the compiler prefers the array_type, since it must already have                                                     
272     // that latter value in hand for the fast path.                                                                        
273     Handle holder(THREAD, array_type->klass_holder()); // keep the array klass alive                                       
274     Klass* elem_type = ObjArrayKlass::cast(array_type)->element_klass();                                                   
275     result = oopFactory::new_objArray(elem_type, len, THREAD);                                                             
276   }                                                                                                                        
277 
278   // Pass oops back through thread local storage.  Our apparent type to Java                                               
279   // is that we return an oop, but we can block on exit from this routine and                                              
280   // a GC can trash the oop in C's return register.  The generated stub will                                               
281   // fetch the oop from TLS after any possible GC.                                                                         
282   deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);                                                                  
283   thread->set_vm_result(result);                                                                                           
284   JRT_BLOCK_END;                                                                                                           
285 
286   if (GraphKit::use_ReduceInitialCardMarks()) {                                                                            
287     // inform GC that we won't do card marks for initializing writes.                                                      
288     new_store_pre_barrier(thread);                                                                                         
289   }                                                                                                                        
290 JRT_END                                                                                                                    
291 
292 // array allocation without zeroing                                                                                        
293 JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_nozero_C(Klass* array_type, int len, JavaThread *thread))                     
294   JRT_BLOCK;                                                                                                               
295 #ifndef PRODUCT                                                                                                            
296   SharedRuntime::_new_array_ctr++;            // new array requires GC                                                     
297 #endif                                                                                                                     
298   assert(check_compiled_frame(thread), "incorrect caller");                                                                
299 
300   // Scavenge and allocate an instance.                                                                                    
301   oop result;                                                                                                              
302 
303   assert(array_type->is_typeArray_klass(), "should be called only for type array");                                        
304   // The oopFactory likes to work with the element type.                                                                   
305   BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();                                                  
306   result = oopFactory::new_typeArray_nozero(elem_type, len, THREAD);                                                       
307 
308   // Pass oops back through thread local storage.  Our apparent type to Java                                               
309   // is that we return an oop, but we can block on exit from this routine and                                              
310   // a GC can trash the oop in C's return register.  The generated stub will                                               
311   // fetch the oop from TLS after any possible GC.                                                                         
312   deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);                                                                  
313   thread->set_vm_result(result);                                                                                           
314   JRT_BLOCK_END;                                                                                                           
315 
316   if (GraphKit::use_ReduceInitialCardMarks()) {                                                                            
317     // inform GC that we won't do card marks for initializing writes.                                                      
318     new_store_pre_barrier(thread);                                                                                         
319   }                                                                                                                        
320 
321   oop result = thread->vm_result();                                                                                        
322   if ((len > 0) && (result != NULL) &&                                                                                     
323       is_deoptimized_caller_frame(thread)) {                                                                               
324     // Zero array here if the caller is deoptimized.                                                                       
325     int size = ((typeArrayOop)result)->object_size();                                                                      
326     BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();                                                
327     const size_t hs = arrayOopDesc::header_size(elem_type);                                                                
328     // Align to next 8 bytes to avoid trashing arrays's length.                                                            
329     const size_t aligned_hs = align_object_offset(hs);                                                                     
330     HeapWord* obj = (HeapWord*)result;                                                                                     
331     if (aligned_hs > hs) {                                                                                                 
332       Copy::zero_to_words(obj+hs, aligned_hs-hs);                                                                          
333     }                                                                                                                      
334     // Optimized zeroing.                                                                                                  
335     Copy::fill_to_aligned_words(obj+aligned_hs, size-aligned_hs);                                                          
336   }                                                                                                                        
337 
338 JRT_END                                                                                                                    

176   CodeBlob* cb = CodeCache::find_blob(entry);
177   RuntimeStub* rs =(RuntimeStub *)cb;
178   assert(rs != NULL && rs->is_runtime_stub(), "not a runtime stub");
179   return rs->name();
180 #else
181   // Fast implementation for product mode (maybe it should be inlined too)
182   return "runtime stub";
183 #endif
184 }
185 
186 
187 //=============================================================================
188 // Opto compiler runtime routines
189 //=============================================================================
190 
191 
192 //=============================allocation======================================
193 // We failed the fast-path allocation.  Now we need to do a scavenge or GC
194 // and try allocation again.
195 

















196 // object allocation
197 JRT_BLOCK_ENTRY(void, OptoRuntime::new_instance_C(Klass* klass, JavaThread* thread))
198   JRT_BLOCK;
199 #ifndef PRODUCT
200   SharedRuntime::_new_instance_ctr++;         // new instance requires GC
201 #endif
202   assert(check_compiled_frame(thread), "incorrect caller");
203 
204   // These checks are cheap to make and support reflective allocation.
205   int lh = klass->layout_helper();
206   if (Klass::layout_helper_needs_slow_path(lh) || !InstanceKlass::cast(klass)->is_initialized()) {
207     Handle holder(THREAD, klass->klass_holder()); // keep the klass alive
208     klass->check_valid_for_instantiation(false, THREAD);
209     if (!HAS_PENDING_EXCEPTION) {
210       InstanceKlass::cast(klass)->initialize(THREAD);
211     }
212   }
213 
214   if (!HAS_PENDING_EXCEPTION) {
215     // Scavenge and allocate an instance.
216     Handle holder(THREAD, klass->klass_holder()); // keep the klass alive
217     oop result = InstanceKlass::cast(klass)->allocate_instance(THREAD);
218     thread->set_vm_result(result);
219 
220     // Pass oops back through thread local storage.  Our apparent type to Java
221     // is that we return an oop, but we can block on exit from this routine and
222     // a GC can trash the oop in C's return register.  The generated stub will
223     // fetch the oop from TLS after any possible GC.
224   }
225 
226   deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
227   JRT_BLOCK_END;
228 
229   // inform GC that we won't do card marks for initializing writes.
230   SharedRuntime::on_slowpath_allocation_exit(thread);


231 JRT_END
232 
233 
234 // array allocation
235 JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_C(Klass* array_type, int len, JavaThread *thread))
236   JRT_BLOCK;
237 #ifndef PRODUCT
238   SharedRuntime::_new_array_ctr++;            // new array requires GC
239 #endif
240   assert(check_compiled_frame(thread), "incorrect caller");
241 
242   // Scavenge and allocate an instance.
243   oop result;
244 
245   if (array_type->is_typeArray_klass()) {
246     // The oopFactory likes to work with the element type.
247     // (We could bypass the oopFactory, since it doesn't add much value.)
248     BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
249     result = oopFactory::new_typeArray(elem_type, len, THREAD);
250   } else {
251     // Although the oopFactory likes to work with the elem_type,
252     // the compiler prefers the array_type, since it must already have
253     // that latter value in hand for the fast path.
254     Handle holder(THREAD, array_type->klass_holder()); // keep the array klass alive
255     Klass* elem_type = ObjArrayKlass::cast(array_type)->element_klass();
256     result = oopFactory::new_objArray(elem_type, len, THREAD);
257   }
258 
259   // Pass oops back through thread local storage.  Our apparent type to Java
260   // is that we return an oop, but we can block on exit from this routine and
261   // a GC can trash the oop in C's return register.  The generated stub will
262   // fetch the oop from TLS after any possible GC.
263   deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
264   thread->set_vm_result(result);
265   JRT_BLOCK_END;
266 
267   // inform GC that we won't do card marks for initializing writes.
268   SharedRuntime::on_slowpath_allocation_exit(thread);


269 JRT_END
270 
271 // array allocation without zeroing
272 JRT_BLOCK_ENTRY(void, OptoRuntime::new_array_nozero_C(Klass* array_type, int len, JavaThread *thread))
273   JRT_BLOCK;
274 #ifndef PRODUCT
275   SharedRuntime::_new_array_ctr++;            // new array requires GC
276 #endif
277   assert(check_compiled_frame(thread), "incorrect caller");
278 
279   // Scavenge and allocate an instance.
280   oop result;
281 
282   assert(array_type->is_typeArray_klass(), "should be called only for type array");
283   // The oopFactory likes to work with the element type.
284   BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
285   result = oopFactory::new_typeArray_nozero(elem_type, len, THREAD);
286 
287   // Pass oops back through thread local storage.  Our apparent type to Java
288   // is that we return an oop, but we can block on exit from this routine and
289   // a GC can trash the oop in C's return register.  The generated stub will
290   // fetch the oop from TLS after any possible GC.
291   deoptimize_caller_frame(thread, HAS_PENDING_EXCEPTION);
292   thread->set_vm_result(result);
293   JRT_BLOCK_END;
294 
295 
296   // inform GC that we won't do card marks for initializing writes.
297   SharedRuntime::on_slowpath_allocation_exit(thread);

298 
299   oop result = thread->vm_result();
300   if ((len > 0) && (result != NULL) &&
301       is_deoptimized_caller_frame(thread)) {
302     // Zero array here if the caller is deoptimized.
303     int size = ((typeArrayOop)result)->object_size();
304     BasicType elem_type = TypeArrayKlass::cast(array_type)->element_type();
305     const size_t hs = arrayOopDesc::header_size(elem_type);
306     // Align to next 8 bytes to avoid trashing arrays's length.
307     const size_t aligned_hs = align_object_offset(hs);
308     HeapWord* obj = (HeapWord*)result;
309     if (aligned_hs > hs) {
310       Copy::zero_to_words(obj+hs, aligned_hs-hs);
311     }
312     // Optimized zeroing.
313     Copy::fill_to_aligned_words(obj+aligned_hs, size-aligned_hs);
314   }
315 
316 JRT_END
< prev index next >