src/share/vm/gc_implementation/parallelScavenge/psPromotionManager.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File nmethods-gc-ps Sdiff src/share/vm/gc_implementation/parallelScavenge

src/share/vm/gc_implementation/parallelScavenge/psPromotionManager.cpp

Print this page


   1 /*
   2  * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  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  *


 230 
 231 void PSPromotionManager::flush_labs() {
 232   assert(stacks_empty(), "Attempt to flush lab with live stack");
 233 
 234   // If either promotion lab fills up, we can flush the
 235   // lab but not refill it, so check first.
 236   assert(!_young_lab.is_flushed() || _young_gen_is_full, "Sanity");
 237   if (!_young_lab.is_flushed())
 238     _young_lab.flush();
 239 
 240   assert(!_old_lab.is_flushed() || _old_gen_is_full, "Sanity");
 241   if (!_old_lab.is_flushed())
 242     _old_lab.flush();
 243 
 244   // Let PSScavenge know if we overflowed
 245   if (_young_gen_is_full) {
 246     PSScavenge::set_survivor_overflow(true);
 247   }
 248 }
 249 
 250 //
 251 // This method is pretty bulky. It would be nice to split it up
 252 // into smaller submethods, but we need to be careful not to hurt
 253 // performance.
 254 //
 255 
 256 oop PSPromotionManager::copy_to_survivor_space(oop o) {
 257   assert(PSScavenge::should_scavenge(&o), "Sanity");
 258 
 259   oop new_obj = NULL;
 260 
 261   // NOTE! We must be very careful with any methods that access the mark
 262   // in o. There may be multiple threads racing on it, and it may be forwarded
 263   // at any time. Do not use oop methods for accessing the mark!
 264   markOop test_mark = o->mark();
 265 
 266   // The same test as "o->is_forwarded()"
 267   if (!test_mark->is_marked()) {
 268     bool new_obj_is_tenured = false;
 269     size_t new_obj_size = o->size();
 270 
 271     // Find the objects age, MT safe.
 272     int age = (test_mark->has_displaced_mark_helper() /* o->has_displaced_mark() */) ?
 273       test_mark->displaced_mark_helper()->age() : test_mark->age();
 274 
 275     // Try allocating obj in to-space (unless too old)
 276     if (age < PSScavenge::tenuring_threshold()) {
 277       new_obj = (oop) _young_lab.allocate(new_obj_size);
 278       if (new_obj == NULL && !_young_gen_is_full) {
 279         // Do we allocate directly, or flush and refill?
 280         if (new_obj_size > (YoungPLABSize / 2)) {
 281           // Allocate this object directly
 282           new_obj = (oop)young_space()->cas_allocate(new_obj_size);
 283         } else {
 284           // Flush and fill
 285           _young_lab.flush();
 286 
 287           HeapWord* lab_base = young_space()->cas_allocate(YoungPLABSize);
 288           if (lab_base != NULL) {
 289             _young_lab.initialize(MemRegion(lab_base, YoungPLABSize));
 290             // Try the young lab allocation again.
 291             new_obj = (oop) _young_lab.allocate(new_obj_size);
 292           } else {
 293             _young_gen_is_full = true;
 294           }
 295         }
 296       }
 297     }
 298 
 299     // Otherwise try allocating obj tenured
 300     if (new_obj == NULL) {
 301 #ifndef PRODUCT
 302       if (Universe::heap()->promotion_should_fail()) {
 303         return oop_promotion_failed(o, test_mark);
 304       }
 305 #endif  // #ifndef PRODUCT
 306 
 307       new_obj = (oop) _old_lab.allocate(new_obj_size);
 308       new_obj_is_tenured = true;
 309 
 310       if (new_obj == NULL) {
 311         if (!_old_gen_is_full) {
 312           // Do we allocate directly, or flush and refill?
 313           if (new_obj_size > (OldPLABSize / 2)) {
 314             // Allocate this object directly
 315             new_obj = (oop)old_gen()->cas_allocate(new_obj_size);
 316           } else {
 317             // Flush and fill
 318             _old_lab.flush();
 319 
 320             HeapWord* lab_base = old_gen()->cas_allocate(OldPLABSize);
 321             if(lab_base != NULL) {
 322               _old_lab.initialize(MemRegion(lab_base, OldPLABSize));
 323               // Try the old lab allocation again.
 324               new_obj = (oop) _old_lab.allocate(new_obj_size);
 325             }
 326           }
 327         }
 328 
 329         // This is the promotion failed test, and code handling.
 330         // The code belongs here for two reasons. It is slightly
 331         // different thatn the code below, and cannot share the
 332         // CAS testing code. Keeping the code here also minimizes
 333         // the impact on the common case fast path code.
 334 
 335         if (new_obj == NULL) {
 336           _old_gen_is_full = true;
 337           return oop_promotion_failed(o, test_mark);
 338         }
 339       }
 340     }
 341 
 342     assert(new_obj != NULL, "allocation should have succeeded");
 343 
 344     // Copy obj
 345     Copy::aligned_disjoint_words((HeapWord*)o, (HeapWord*)new_obj, new_obj_size);
 346 
 347     // Now we have to CAS in the header.
 348     if (o->cas_forward_to(new_obj, test_mark)) {
 349       // We won any races, we "own" this object.
 350       assert(new_obj == o->forwardee(), "Sanity");
 351 
 352       // Increment age if obj still in new generation. Now that
 353       // we're dealing with a markOop that cannot change, it is
 354       // okay to use the non mt safe oop methods.
 355       if (!new_obj_is_tenured) {
 356         new_obj->incr_age();
 357         assert(young_space()->contains(new_obj), "Attempt to push non-promoted obj");
 358       }
 359 
 360       // Do the size comparison first with new_obj_size, which we
 361       // already have. Hopefully, only a few objects are larger than
 362       // _min_array_size_for_chunking, and most of them will be arrays.
 363       // So, the is->objArray() test would be very infrequent.
 364       if (new_obj_size > _min_array_size_for_chunking &&
 365           new_obj->is_objArray() &&
 366           PSChunkLargeArrays) {
 367         // we'll chunk it
 368         oop* const masked_o = mask_chunked_array_oop(o);
 369         push_depth(masked_o);
 370         TASKQUEUE_STATS_ONLY(++_arrays_chunked; ++_masked_pushes);
 371       } else {
 372         // we'll just push its contents
 373         new_obj->push_contents(this);
 374       }
 375     }  else {
 376       // We lost, someone else "owns" this object
 377       guarantee(o->is_forwarded(), "Object must be forwarded if the cas failed.");
 378 
 379       // Try to deallocate the space.  If it was directly allocated we cannot
 380       // deallocate it, so we have to test.  If the deallocation fails,
 381       // overwrite with a filler object.
 382       if (new_obj_is_tenured) {
 383         if (!_old_lab.unallocate_object((HeapWord*) new_obj, new_obj_size)) {
 384           CollectedHeap::fill_with_object((HeapWord*) new_obj, new_obj_size);
 385         }
 386       } else if (!_young_lab.unallocate_object((HeapWord*) new_obj, new_obj_size)) {
 387         CollectedHeap::fill_with_object((HeapWord*) new_obj, new_obj_size);
 388       }
 389 
 390       // don't update this before the unallocation!
 391       new_obj = o->forwardee();
 392     }
 393   } else {
 394     assert(o->is_forwarded(), "Sanity");
 395     new_obj = o->forwardee();
 396   }
 397 
 398 #ifdef DEBUG
 399   // This code must come after the CAS test, or it will print incorrect
 400   // information.
 401   if (TraceScavenge) {
 402     gclog_or_tty->print_cr("{%s %s " PTR_FORMAT " -> " PTR_FORMAT " (" SIZE_FORMAT ")}",
 403        PSScavenge::should_scavenge(&new_obj) ? "copying" : "tenuring",
 404        new_obj->blueprint()->internal_name(), o, new_obj, new_obj->size());
 405   }
 406 #endif
 407 
 408   return new_obj;
 409 }
 410 
 411 template <class T> void PSPromotionManager::process_array_chunk_work(
 412                                                  oop obj,
 413                                                  int start, int end) {
 414   assert(start <= end, "invariant");
 415   T* const base      = (T*)objArrayOop(obj)->base();
 416   T* p               = base + start;
 417   T* const chunk_end = base + end;
 418   while (p < chunk_end) {
 419     if (PSScavenge::should_scavenge(p)) {
 420       claim_or_forward_depth(p);
 421     }
 422     ++p;
 423   }
 424 }
 425 
 426 void PSPromotionManager::process_array_chunk(oop old) {
 427   assert(PSChunkLargeArrays, "invariant");
 428   assert(old->is_objArray(), "invariant");
 429   assert(old->is_forwarded(), "invariant");
 430 


   1 /*
   2  * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  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  *


 230 
 231 void PSPromotionManager::flush_labs() {
 232   assert(stacks_empty(), "Attempt to flush lab with live stack");
 233 
 234   // If either promotion lab fills up, we can flush the
 235   // lab but not refill it, so check first.
 236   assert(!_young_lab.is_flushed() || _young_gen_is_full, "Sanity");
 237   if (!_young_lab.is_flushed())
 238     _young_lab.flush();
 239 
 240   assert(!_old_lab.is_flushed() || _old_gen_is_full, "Sanity");
 241   if (!_old_lab.is_flushed())
 242     _old_lab.flush();
 243 
 244   // Let PSScavenge know if we overflowed
 245   if (_young_gen_is_full) {
 246     PSScavenge::set_survivor_overflow(true);
 247   }
 248 }
 249 

































































































































































 250 template <class T> void PSPromotionManager::process_array_chunk_work(
 251                                                  oop obj,
 252                                                  int start, int end) {
 253   assert(start <= end, "invariant");
 254   T* const base      = (T*)objArrayOop(obj)->base();
 255   T* p               = base + start;
 256   T* const chunk_end = base + end;
 257   while (p < chunk_end) {
 258     if (PSScavenge::should_scavenge(p)) {
 259       claim_or_forward_depth(p);
 260     }
 261     ++p;
 262   }
 263 }
 264 
 265 void PSPromotionManager::process_array_chunk(oop old) {
 266   assert(PSChunkLargeArrays, "invariant");
 267   assert(old->is_objArray(), "invariant");
 268   assert(old->is_forwarded(), "invariant");
 269 


src/share/vm/gc_implementation/parallelScavenge/psPromotionManager.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File