351 // The functions below are helper functions that a subclass of 352 // "CollectedHeap" can use in the implementation of its virtual 353 // functions. 354 355 class GenClosure : public StackObj { 356 public: 357 virtual void do_generation(Generation* gen) = 0; 358 }; 359 360 // Apply "cl.do_generation" to all generations in the heap 361 // If "old_to_young" determines the order. 362 void generation_iterate(GenClosure* cl, bool old_to_young); 363 364 void space_iterate(SpaceClosure* cl); 365 366 // Return "true" if all generations have reached the 367 // maximal committed limit that they can reach, without a garbage 368 // collection. 369 virtual bool is_maximal_no_gc() const; 370 371 // Return the generation before "gen", or else NULL. 372 Generation* prev_gen(Generation* gen) const { 373 int l = gen->level(); 374 if (l == 0) return NULL; 375 else return _gens[l-1]; 376 } 377 378 // Return the generation after "gen", or else NULL. 379 Generation* next_gen(Generation* gen) const { 380 int l = gen->level() + 1; 381 if (l == _n_gens) return NULL; 382 else return _gens[l]; 383 } 384 385 Generation* get_gen(int i) const { 386 if (i >= 0 && i < _n_gens) 387 return _gens[i]; 388 else 389 return NULL; 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 468 assert(heap()->collector_policy()->is_two_generation_policy(), 469 "the following definition may not be suitable for an n(>2)-generation system"); 470 return incremental_collection_failed() || 471 (consult_young && !get_gen(0)->collection_attempt_is_safe()); 472 } 473 474 // If a generation bails out of an incremental collection, 475 // it sets this flag. 476 bool incremental_collection_failed() const { 477 return _incremental_collection_failed; 478 } 479 void set_incremental_collection_failed() { 480 _incremental_collection_failed = true; 481 } 482 void clear_incremental_collection_failed() { 483 _incremental_collection_failed = false; 484 } 485 486 // Promotion of obj into gen failed. Try to promote obj to higher 487 // gens in ascending order; return the new location of obj if successful. 488 // Otherwise, try expand-and-allocate for obj in each generation starting at 489 // gen; return the new location of obj if successful. Otherwise, return NULL. 490 oop handle_failed_promotion(Generation* gen, 491 oop obj, 492 size_t obj_size); 493 494 private: 495 // Accessor for memory state verification support 496 NOT_PRODUCT( 497 static size_t skip_header_HeapWords() { return _skip_header_HeapWords; } 498 ) 499 500 // Override 501 void check_for_non_bad_heap_word_value(HeapWord* addr, 502 size_t size) PRODUCT_RETURN; 503 504 // For use by mark-sweep. As implemented, mark-sweep-compact is global 505 // in an essential way: compaction is performed across generations, by 506 // iterating over spaces. 507 void prepare_for_compaction(); 508 509 // Perform a full collection of the first max_level+1 generations. 510 // This is the low level interface used by the public versions of | 351 // The functions below are helper functions that a subclass of 352 // "CollectedHeap" can use in the implementation of its virtual 353 // functions. 354 355 class GenClosure : public StackObj { 356 public: 357 virtual void do_generation(Generation* gen) = 0; 358 }; 359 360 // Apply "cl.do_generation" to all generations in the heap 361 // If "old_to_young" determines the order. 362 void generation_iterate(GenClosure* cl, bool old_to_young); 363 364 void space_iterate(SpaceClosure* cl); 365 366 // Return "true" if all generations have reached the 367 // maximal committed limit that they can reach, without a garbage 368 // collection. 369 virtual bool is_maximal_no_gc() const; 370 371 // Return the generation before "gen". 372 Generation* prev_gen(Generation* gen) const { 373 int l = gen->level(); 374 guarantee(l > 0, "Out of bounds"); 375 return _gens[l-1]; 376 } 377 378 // Return the generation after "gen". 379 Generation* next_gen(Generation* gen) const { 380 int l = gen->level() + 1; 381 guarantee(l < _n_gens, "Out of bounds"); 382 return _gens[l]; 383 } 384 385 Generation* get_gen(int i) const { 386 guarantee(i >= 0 && i < _n_gens, "Out of bounds"); 387 return _gens[i]; 388 } 389 390 int n_gens() const { 391 assert(_n_gens == gen_policy()->number_of_generations(), "Sanity"); 392 return _n_gens; 393 } 394 395 // Convenience function to be used in situations where the heap type can be 396 // asserted to be this type. 397 static GenCollectedHeap* heap(); 398 399 void set_par_threads(uint t); 400 401 // Invoke the "do_oop" method of one of the closures "not_older_gens" 402 // or "older_gens" on root locations for the generation at 403 // "level". (The "older_gens" closure is used for scanning references 404 // from older generations; "not_older_gens" is used everywhere else.) 405 // If "younger_gens_as_roots" is false, younger generations are 406 // not scanned as roots; in this case, the caller must be arranging to 407 // scan the younger generations itself. (For example, a generation might 466 assert(heap()->collector_policy()->is_two_generation_policy(), 467 "the following definition may not be suitable for an n(>2)-generation system"); 468 return incremental_collection_failed() || 469 (consult_young && !get_gen(0)->collection_attempt_is_safe()); 470 } 471 472 // If a generation bails out of an incremental collection, 473 // it sets this flag. 474 bool incremental_collection_failed() const { 475 return _incremental_collection_failed; 476 } 477 void set_incremental_collection_failed() { 478 _incremental_collection_failed = true; 479 } 480 void clear_incremental_collection_failed() { 481 _incremental_collection_failed = false; 482 } 483 484 // Promotion of obj into gen failed. Try to promote obj to higher 485 // gens in ascending order; return the new location of obj if successful. 486 // Otherwise, try expand-and-allocate for obj in both the young and old 487 // generation; return the new location of obj if successful. Otherwise, return NULL. 488 oop handle_failed_promotion(Generation* old_gen, 489 oop obj, 490 size_t obj_size); 491 492 private: 493 // Accessor for memory state verification support 494 NOT_PRODUCT( 495 static size_t skip_header_HeapWords() { return _skip_header_HeapWords; } 496 ) 497 498 // Override 499 void check_for_non_bad_heap_word_value(HeapWord* addr, 500 size_t size) PRODUCT_RETURN; 501 502 // For use by mark-sweep. As implemented, mark-sweep-compact is global 503 // in an essential way: compaction is performed across generations, by 504 // iterating over spaces. 505 void prepare_for_compaction(); 506 507 // Perform a full collection of the first max_level+1 generations. 508 // This is the low level interface used by the public versions of |