352 // The functions below are helper functions that a subclass of
353 // "CollectedHeap" can use in the implementation of its virtual
354 // functions.
355
356 class GenClosure : public StackObj {
357 public:
358 virtual void do_generation(Generation* gen) = 0;
359 };
360
361 // Apply "cl.do_generation" to all generations in the heap
362 // If "old_to_young" determines the order.
363 void generation_iterate(GenClosure* cl, bool old_to_young);
364
365 void space_iterate(SpaceClosure* cl);
366
367 // Return "true" if all generations have reached the
368 // maximal committed limit that they can reach, without a garbage
369 // collection.
370 virtual bool is_maximal_no_gc() const;
371
372 // Return the generation before "gen".
373 Generation* prev_gen(Generation* gen) const {
374 int l = gen->level();
375 guarantee(l == 1, "Out of bounds");
376 return _young_gen;
377 }
378
379 // Return the generation after "gen".
380 Generation* next_gen(Generation* gen) const {
381 int l = gen->level() + 1;
382 guarantee(l == 1, "Out of bounds");
383 return _old_gen;
384 }
385
386 Generation* get_gen(int i) const {
387 guarantee(i >= 0 && i < _n_gens, "Out of bounds");
388 if (i == 0) return _young_gen;
389 else return _old_gen;
390 }
391
392 int n_gens() const {
393 assert(_n_gens == gen_policy()->number_of_generations(), "Sanity");
394 return _n_gens;
395 }
396
397 // Convenience function to be used in situations where the heap type can be
398 // asserted to be this type.
399 static GenCollectedHeap* heap();
400
401 void set_par_threads(uint t);
402
403 // Invoke the "do_oop" method of one of the closures "not_older_gens"
404 // or "older_gens" on root locations for the generation at
405 // "level". (The "older_gens" closure is used for scanning references
406 // from older generations; "not_older_gens" is used everywhere else.)
407 // If "younger_gens_as_roots" is false, younger generations are
408 // not scanned as roots; in this case, the caller must be arranging to
409 // scan the younger generations itself. (For example, a generation might
410 // explicitly mark reachable objects in younger generations, to avoid
411 // excess storage retention.)
460 ALL_SINCE_SAVE_MARKS_CLOSURES(GCH_SINCE_SAVE_MARKS_ITERATE_DECL)
461
462 #undef GCH_SINCE_SAVE_MARKS_ITERATE_DECL
463
464 // Returns "true" iff no allocations have occurred in any generation at
465 // "level" or above since the last
466 // call to "save_marks".
467 bool no_allocs_since_save_marks(int level);
468
469 // Returns true if an incremental collection is likely to fail.
470 // We optionally consult the young gen, if asked to do so;
471 // otherwise we base our answer on whether the previous incremental
472 // collection attempt failed with no corrective action as of yet.
473 bool incremental_collection_will_fail(bool consult_young) {
474 // Assumes a 2-generation system; the first disjunct remembers if an
475 // incremental collection failed, even when we thought (second disjunct)
476 // that it would not.
477 assert(heap()->collector_policy()->is_generation_policy(),
478 "the following definition may not be suitable for an n(>2)-generation system");
479 return incremental_collection_failed() ||
480 (consult_young && !get_gen(0)->collection_attempt_is_safe());
481 }
482
483 // If a generation bails out of an incremental collection,
484 // it sets this flag.
485 bool incremental_collection_failed() const {
486 return _incremental_collection_failed;
487 }
488 void set_incremental_collection_failed() {
489 _incremental_collection_failed = true;
490 }
491 void clear_incremental_collection_failed() {
492 _incremental_collection_failed = false;
493 }
494
495 // Promotion of obj into gen failed. Try to promote obj to higher
496 // gens in ascending order; return the new location of obj if successful.
497 // Otherwise, try expand-and-allocate for obj in both the young and old
498 // generation; return the new location of obj if successful. Otherwise, return NULL.
499 oop handle_failed_promotion(Generation* old_gen,
500 oop obj,
|
352 // The functions below are helper functions that a subclass of
353 // "CollectedHeap" can use in the implementation of its virtual
354 // functions.
355
356 class GenClosure : public StackObj {
357 public:
358 virtual void do_generation(Generation* gen) = 0;
359 };
360
361 // Apply "cl.do_generation" to all generations in the heap
362 // If "old_to_young" determines the order.
363 void generation_iterate(GenClosure* cl, bool old_to_young);
364
365 void space_iterate(SpaceClosure* cl);
366
367 // Return "true" if all generations have reached the
368 // maximal committed limit that they can reach, without a garbage
369 // collection.
370 virtual bool is_maximal_no_gc() const;
371
372 int n_gens() const {
373 assert(_n_gens == gen_policy()->number_of_generations(), "Sanity");
374 return _n_gens;
375 }
376
377 // Convenience function to be used in situations where the heap type can be
378 // asserted to be this type.
379 static GenCollectedHeap* heap();
380
381 void set_par_threads(uint t);
382
383 // Invoke the "do_oop" method of one of the closures "not_older_gens"
384 // or "older_gens" on root locations for the generation at
385 // "level". (The "older_gens" closure is used for scanning references
386 // from older generations; "not_older_gens" is used everywhere else.)
387 // If "younger_gens_as_roots" is false, younger generations are
388 // not scanned as roots; in this case, the caller must be arranging to
389 // scan the younger generations itself. (For example, a generation might
390 // explicitly mark reachable objects in younger generations, to avoid
391 // excess storage retention.)
440 ALL_SINCE_SAVE_MARKS_CLOSURES(GCH_SINCE_SAVE_MARKS_ITERATE_DECL)
441
442 #undef GCH_SINCE_SAVE_MARKS_ITERATE_DECL
443
444 // Returns "true" iff no allocations have occurred in any generation at
445 // "level" or above since the last
446 // call to "save_marks".
447 bool no_allocs_since_save_marks(int level);
448
449 // Returns true if an incremental collection is likely to fail.
450 // We optionally consult the young gen, if asked to do so;
451 // otherwise we base our answer on whether the previous incremental
452 // collection attempt failed with no corrective action as of yet.
453 bool incremental_collection_will_fail(bool consult_young) {
454 // Assumes a 2-generation system; the first disjunct remembers if an
455 // incremental collection failed, even when we thought (second disjunct)
456 // that it would not.
457 assert(heap()->collector_policy()->is_generation_policy(),
458 "the following definition may not be suitable for an n(>2)-generation system");
459 return incremental_collection_failed() ||
460 (consult_young && !_young_gen->collection_attempt_is_safe());
461 }
462
463 // If a generation bails out of an incremental collection,
464 // it sets this flag.
465 bool incremental_collection_failed() const {
466 return _incremental_collection_failed;
467 }
468 void set_incremental_collection_failed() {
469 _incremental_collection_failed = true;
470 }
471 void clear_incremental_collection_failed() {
472 _incremental_collection_failed = false;
473 }
474
475 // Promotion of obj into gen failed. Try to promote obj to higher
476 // gens in ascending order; return the new location of obj if successful.
477 // Otherwise, try expand-and-allocate for obj in both the young and old
478 // generation; return the new location of obj if successful. Otherwise, return NULL.
479 oop handle_failed_promotion(Generation* old_gen,
480 oop obj,
|