Mercurial > hg > graal-jvmci-8
comparison src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp @ 1521:a8127dc669ba
6951188: CMS: move PromotionInfo into its own file
Summary: Moved PromotionInfo and friends into new files promotionInfo.{h,c}pp from their previous compactibleFreeListSpace.{h,c}pp home.
Reviewed-by: apetrusenko
author | ysr |
---|---|
date | Mon, 10 May 2010 12:31:52 -0700 |
parents | 05b775309e59 |
children | c18cbe5936b8 2d127394260e |
comparison
equal
deleted
inserted
replaced
1520:bb843ebc7c55 | 1521:a8127dc669ba |
---|---|
1924 assert(_promoInfo.noPromotions(), "_promoInfo inconsistency"); \ | 1924 assert(_promoInfo.noPromotions(), "_promoInfo inconsistency"); \ |
1925 } | 1925 } |
1926 | 1926 |
1927 ALL_SINCE_SAVE_MARKS_CLOSURES(CFLS_OOP_SINCE_SAVE_MARKS_DEFN) | 1927 ALL_SINCE_SAVE_MARKS_CLOSURES(CFLS_OOP_SINCE_SAVE_MARKS_DEFN) |
1928 | 1928 |
1929 ////////////////////////////////////////////////////////////////////////////// | |
1930 // We go over the list of promoted objects, removing each from the list, | |
1931 // and applying the closure (this may, in turn, add more elements to | |
1932 // the tail of the promoted list, and these newly added objects will | |
1933 // also be processed) until the list is empty. | |
1934 // To aid verification and debugging, in the non-product builds | |
1935 // we actually forward _promoHead each time we process a promoted oop. | |
1936 // Note that this is not necessary in general (i.e. when we don't need to | |
1937 // call PromotionInfo::verify()) because oop_iterate can only add to the | |
1938 // end of _promoTail, and never needs to look at _promoHead. | |
1939 | |
1940 #define PROMOTED_OOPS_ITERATE_DEFN(OopClosureType, nv_suffix) \ | |
1941 \ | |
1942 void PromotionInfo::promoted_oops_iterate##nv_suffix(OopClosureType* cl) { \ | |
1943 NOT_PRODUCT(verify()); \ | |
1944 PromotedObject *curObj, *nextObj; \ | |
1945 for (curObj = _promoHead; curObj != NULL; curObj = nextObj) { \ | |
1946 if ((nextObj = curObj->next()) == NULL) { \ | |
1947 /* protect ourselves against additions due to closure application \ | |
1948 below by resetting the list. */ \ | |
1949 assert(_promoTail == curObj, "Should have been the tail"); \ | |
1950 _promoHead = _promoTail = NULL; \ | |
1951 } \ | |
1952 if (curObj->hasDisplacedMark()) { \ | |
1953 /* restore displaced header */ \ | |
1954 oop(curObj)->set_mark(nextDisplacedHeader()); \ | |
1955 } else { \ | |
1956 /* restore prototypical header */ \ | |
1957 oop(curObj)->init_mark(); \ | |
1958 } \ | |
1959 /* The "promoted_mark" should now not be set */ \ | |
1960 assert(!curObj->hasPromotedMark(), \ | |
1961 "Should have been cleared by restoring displaced mark-word"); \ | |
1962 NOT_PRODUCT(_promoHead = nextObj); \ | |
1963 if (cl != NULL) oop(curObj)->oop_iterate(cl); \ | |
1964 if (nextObj == NULL) { /* start at head of list reset above */ \ | |
1965 nextObj = _promoHead; \ | |
1966 } \ | |
1967 } \ | |
1968 assert(noPromotions(), "post-condition violation"); \ | |
1969 assert(_promoHead == NULL && _promoTail == NULL, "emptied promoted list");\ | |
1970 assert(_spoolHead == _spoolTail, "emptied spooling buffers"); \ | |
1971 assert(_firstIndex == _nextIndex, "empty buffer"); \ | |
1972 } | |
1973 | |
1974 // This should have been ALL_SINCE_...() just like the others, | |
1975 // but, because the body of the method above is somehwat longer, | |
1976 // the MSVC compiler cannot cope; as a workaround, we split the | |
1977 // macro into its 3 constituent parts below (see original macro | |
1978 // definition in specializedOopClosures.hpp). | |
1979 SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES_YOUNG(PROMOTED_OOPS_ITERATE_DEFN) | |
1980 PROMOTED_OOPS_ITERATE_DEFN(OopsInGenClosure,_v) | |
1981 | |
1982 | 1929 |
1983 void CompactibleFreeListSpace::object_iterate_since_last_GC(ObjectClosure* cl) { | 1930 void CompactibleFreeListSpace::object_iterate_since_last_GC(ObjectClosure* cl) { |
1984 // ugghh... how would one do this efficiently for a non-contiguous space? | 1931 // ugghh... how would one do this efficiently for a non-contiguous space? |
1985 guarantee(false, "NYI"); | 1932 guarantee(false, "NYI"); |
1986 } | 1933 } |
2502 gclog_or_tty->print("growth: %8.5f deficit: %8.5f\n", | 2449 gclog_or_tty->print("growth: %8.5f deficit: %8.5f\n", |
2503 (double)(total.splitBirths()+total.coalBirths()-total.splitDeaths()-total.coalDeaths())/ | 2450 (double)(total.splitBirths()+total.coalBirths()-total.splitDeaths()-total.coalDeaths())/ |
2504 (total.prevSweep() != 0 ? (double)total.prevSweep() : 1.0), | 2451 (total.prevSweep() != 0 ? (double)total.prevSweep() : 1.0), |
2505 (double)(total.desired() - total.count())/(total.desired() != 0 ? (double)total.desired() : 1.0)); | 2452 (double)(total.desired() - total.count())/(total.desired() != 0 ? (double)total.desired() : 1.0)); |
2506 _dictionary->printDictCensus(); | 2453 _dictionary->printDictCensus(); |
2507 } | |
2508 | |
2509 // Return the next displaced header, incrementing the pointer and | |
2510 // recycling spool area as necessary. | |
2511 markOop PromotionInfo::nextDisplacedHeader() { | |
2512 assert(_spoolHead != NULL, "promotionInfo inconsistency"); | |
2513 assert(_spoolHead != _spoolTail || _firstIndex < _nextIndex, | |
2514 "Empty spool space: no displaced header can be fetched"); | |
2515 assert(_spoolHead->bufferSize > _firstIndex, "Off by one error at head?"); | |
2516 markOop hdr = _spoolHead->displacedHdr[_firstIndex]; | |
2517 // Spool forward | |
2518 if (++_firstIndex == _spoolHead->bufferSize) { // last location in this block | |
2519 // forward to next block, recycling this block into spare spool buffer | |
2520 SpoolBlock* tmp = _spoolHead->nextSpoolBlock; | |
2521 assert(_spoolHead != _spoolTail, "Spooling storage mix-up"); | |
2522 _spoolHead->nextSpoolBlock = _spareSpool; | |
2523 _spareSpool = _spoolHead; | |
2524 _spoolHead = tmp; | |
2525 _firstIndex = 1; | |
2526 NOT_PRODUCT( | |
2527 if (_spoolHead == NULL) { // all buffers fully consumed | |
2528 assert(_spoolTail == NULL && _nextIndex == 1, | |
2529 "spool buffers processing inconsistency"); | |
2530 } | |
2531 ) | |
2532 } | |
2533 return hdr; | |
2534 } | |
2535 | |
2536 void PromotionInfo::track(PromotedObject* trackOop) { | |
2537 track(trackOop, oop(trackOop)->klass()); | |
2538 } | |
2539 | |
2540 void PromotionInfo::track(PromotedObject* trackOop, klassOop klassOfOop) { | |
2541 // make a copy of header as it may need to be spooled | |
2542 markOop mark = oop(trackOop)->mark(); | |
2543 trackOop->clearNext(); | |
2544 if (mark->must_be_preserved_for_cms_scavenge(klassOfOop)) { | |
2545 // save non-prototypical header, and mark oop | |
2546 saveDisplacedHeader(mark); | |
2547 trackOop->setDisplacedMark(); | |
2548 } else { | |
2549 // we'd like to assert something like the following: | |
2550 // assert(mark == markOopDesc::prototype(), "consistency check"); | |
2551 // ... but the above won't work because the age bits have not (yet) been | |
2552 // cleared. The remainder of the check would be identical to the | |
2553 // condition checked in must_be_preserved() above, so we don't really | |
2554 // have anything useful to check here! | |
2555 } | |
2556 if (_promoTail != NULL) { | |
2557 assert(_promoHead != NULL, "List consistency"); | |
2558 _promoTail->setNext(trackOop); | |
2559 _promoTail = trackOop; | |
2560 } else { | |
2561 assert(_promoHead == NULL, "List consistency"); | |
2562 _promoHead = _promoTail = trackOop; | |
2563 } | |
2564 // Mask as newly promoted, so we can skip over such objects | |
2565 // when scanning dirty cards | |
2566 assert(!trackOop->hasPromotedMark(), "Should not have been marked"); | |
2567 trackOop->setPromotedMark(); | |
2568 } | |
2569 | |
2570 // Save the given displaced header, incrementing the pointer and | |
2571 // obtaining more spool area as necessary. | |
2572 void PromotionInfo::saveDisplacedHeader(markOop hdr) { | |
2573 assert(_spoolHead != NULL && _spoolTail != NULL, | |
2574 "promotionInfo inconsistency"); | |
2575 assert(_spoolTail->bufferSize > _nextIndex, "Off by one error at tail?"); | |
2576 _spoolTail->displacedHdr[_nextIndex] = hdr; | |
2577 // Spool forward | |
2578 if (++_nextIndex == _spoolTail->bufferSize) { // last location in this block | |
2579 // get a new spooling block | |
2580 assert(_spoolTail->nextSpoolBlock == NULL, "tail should terminate spool list"); | |
2581 _splice_point = _spoolTail; // save for splicing | |
2582 _spoolTail->nextSpoolBlock = getSpoolBlock(); // might fail | |
2583 _spoolTail = _spoolTail->nextSpoolBlock; // might become NULL ... | |
2584 // ... but will attempt filling before next promotion attempt | |
2585 _nextIndex = 1; | |
2586 } | |
2587 } | |
2588 | |
2589 // Ensure that spooling space exists. Return false if spooling space | |
2590 // could not be obtained. | |
2591 bool PromotionInfo::ensure_spooling_space_work() { | |
2592 assert(!has_spooling_space(), "Only call when there is no spooling space"); | |
2593 // Try and obtain more spooling space | |
2594 SpoolBlock* newSpool = getSpoolBlock(); | |
2595 assert(newSpool == NULL || | |
2596 (newSpool->bufferSize != 0 && newSpool->nextSpoolBlock == NULL), | |
2597 "getSpoolBlock() sanity check"); | |
2598 if (newSpool == NULL) { | |
2599 return false; | |
2600 } | |
2601 _nextIndex = 1; | |
2602 if (_spoolTail == NULL) { | |
2603 _spoolTail = newSpool; | |
2604 if (_spoolHead == NULL) { | |
2605 _spoolHead = newSpool; | |
2606 _firstIndex = 1; | |
2607 } else { | |
2608 assert(_splice_point != NULL && _splice_point->nextSpoolBlock == NULL, | |
2609 "Splice point invariant"); | |
2610 // Extra check that _splice_point is connected to list | |
2611 #ifdef ASSERT | |
2612 { | |
2613 SpoolBlock* blk = _spoolHead; | |
2614 for (; blk->nextSpoolBlock != NULL; | |
2615 blk = blk->nextSpoolBlock); | |
2616 assert(blk != NULL && blk == _splice_point, | |
2617 "Splice point incorrect"); | |
2618 } | |
2619 #endif // ASSERT | |
2620 _splice_point->nextSpoolBlock = newSpool; | |
2621 } | |
2622 } else { | |
2623 assert(_spoolHead != NULL, "spool list consistency"); | |
2624 _spoolTail->nextSpoolBlock = newSpool; | |
2625 _spoolTail = newSpool; | |
2626 } | |
2627 return true; | |
2628 } | |
2629 | |
2630 // Get a free spool buffer from the free pool, getting a new block | |
2631 // from the heap if necessary. | |
2632 SpoolBlock* PromotionInfo::getSpoolBlock() { | |
2633 SpoolBlock* res; | |
2634 if ((res = _spareSpool) != NULL) { | |
2635 _spareSpool = _spareSpool->nextSpoolBlock; | |
2636 res->nextSpoolBlock = NULL; | |
2637 } else { // spare spool exhausted, get some from heap | |
2638 res = (SpoolBlock*)(space()->allocateScratch(refillSize())); | |
2639 if (res != NULL) { | |
2640 res->init(); | |
2641 } | |
2642 } | |
2643 assert(res == NULL || res->nextSpoolBlock == NULL, "postcondition"); | |
2644 return res; | |
2645 } | |
2646 | |
2647 void PromotionInfo::startTrackingPromotions() { | |
2648 assert(_spoolHead == _spoolTail && _firstIndex == _nextIndex, | |
2649 "spooling inconsistency?"); | |
2650 _firstIndex = _nextIndex = 1; | |
2651 _tracking = true; | |
2652 } | |
2653 | |
2654 #define CMSPrintPromoBlockInfo 1 | |
2655 | |
2656 void PromotionInfo::stopTrackingPromotions(uint worker_id) { | |
2657 assert(_spoolHead == _spoolTail && _firstIndex == _nextIndex, | |
2658 "spooling inconsistency?"); | |
2659 _firstIndex = _nextIndex = 1; | |
2660 _tracking = false; | |
2661 if (CMSPrintPromoBlockInfo > 1) { | |
2662 print_statistics(worker_id); | |
2663 } | |
2664 } | |
2665 | |
2666 void PromotionInfo::print_statistics(uint worker_id) const { | |
2667 assert(_spoolHead == _spoolTail && _firstIndex == _nextIndex, | |
2668 "Else will undercount"); | |
2669 assert(CMSPrintPromoBlockInfo > 0, "Else unnecessary call"); | |
2670 // Count the number of blocks and slots in the free pool | |
2671 size_t slots = 0; | |
2672 size_t blocks = 0; | |
2673 for (SpoolBlock* cur_spool = _spareSpool; | |
2674 cur_spool != NULL; | |
2675 cur_spool = cur_spool->nextSpoolBlock) { | |
2676 // the first entry is just a self-pointer; indices 1 through | |
2677 // bufferSize - 1 are occupied (thus, bufferSize - 1 slots). | |
2678 guarantee((void*)cur_spool->displacedHdr == (void*)&cur_spool->displacedHdr, | |
2679 "first entry of displacedHdr should be self-referential"); | |
2680 slots += cur_spool->bufferSize - 1; | |
2681 blocks++; | |
2682 } | |
2683 if (_spoolHead != NULL) { | |
2684 slots += _spoolHead->bufferSize - 1; | |
2685 blocks++; | |
2686 } | |
2687 gclog_or_tty->print_cr(" [worker %d] promo_blocks = %d, promo_slots = %d ", | |
2688 worker_id, blocks, slots); | |
2689 } | |
2690 | |
2691 // When _spoolTail is not NULL, then the slot <_spoolTail, _nextIndex> | |
2692 // points to the next slot available for filling. | |
2693 // The set of slots holding displaced headers are then all those in the | |
2694 // right-open interval denoted by: | |
2695 // | |
2696 // [ <_spoolHead, _firstIndex>, <_spoolTail, _nextIndex> ) | |
2697 // | |
2698 // When _spoolTail is NULL, then the set of slots with displaced headers | |
2699 // is all those starting at the slot <_spoolHead, _firstIndex> and | |
2700 // going up to the last slot of last block in the linked list. | |
2701 // In this lartter case, _splice_point points to the tail block of | |
2702 // this linked list of blocks holding displaced headers. | |
2703 void PromotionInfo::verify() const { | |
2704 // Verify the following: | |
2705 // 1. the number of displaced headers matches the number of promoted | |
2706 // objects that have displaced headers | |
2707 // 2. each promoted object lies in this space | |
2708 debug_only( | |
2709 PromotedObject* junk = NULL; | |
2710 assert(junk->next_addr() == (void*)(oop(junk)->mark_addr()), | |
2711 "Offset of PromotedObject::_next is expected to align with " | |
2712 " the OopDesc::_mark within OopDesc"); | |
2713 ) | |
2714 // FIXME: guarantee???? | |
2715 guarantee(_spoolHead == NULL || _spoolTail != NULL || | |
2716 _splice_point != NULL, "list consistency"); | |
2717 guarantee(_promoHead == NULL || _promoTail != NULL, "list consistency"); | |
2718 // count the number of objects with displaced headers | |
2719 size_t numObjsWithDisplacedHdrs = 0; | |
2720 for (PromotedObject* curObj = _promoHead; curObj != NULL; curObj = curObj->next()) { | |
2721 guarantee(space()->is_in_reserved((HeapWord*)curObj), "Containment"); | |
2722 // the last promoted object may fail the mark() != NULL test of is_oop(). | |
2723 guarantee(curObj->next() == NULL || oop(curObj)->is_oop(), "must be an oop"); | |
2724 if (curObj->hasDisplacedMark()) { | |
2725 numObjsWithDisplacedHdrs++; | |
2726 } | |
2727 } | |
2728 // Count the number of displaced headers | |
2729 size_t numDisplacedHdrs = 0; | |
2730 for (SpoolBlock* curSpool = _spoolHead; | |
2731 curSpool != _spoolTail && curSpool != NULL; | |
2732 curSpool = curSpool->nextSpoolBlock) { | |
2733 // the first entry is just a self-pointer; indices 1 through | |
2734 // bufferSize - 1 are occupied (thus, bufferSize - 1 slots). | |
2735 guarantee((void*)curSpool->displacedHdr == (void*)&curSpool->displacedHdr, | |
2736 "first entry of displacedHdr should be self-referential"); | |
2737 numDisplacedHdrs += curSpool->bufferSize - 1; | |
2738 } | |
2739 guarantee((_spoolHead == _spoolTail) == (numDisplacedHdrs == 0), | |
2740 "internal consistency"); | |
2741 guarantee(_spoolTail != NULL || _nextIndex == 1, | |
2742 "Inconsistency between _spoolTail and _nextIndex"); | |
2743 // We overcounted (_firstIndex-1) worth of slots in block | |
2744 // _spoolHead and we undercounted (_nextIndex-1) worth of | |
2745 // slots in block _spoolTail. We make an appropriate | |
2746 // adjustment by subtracting the first and adding the | |
2747 // second: - (_firstIndex - 1) + (_nextIndex - 1) | |
2748 numDisplacedHdrs += (_nextIndex - _firstIndex); | |
2749 guarantee(numDisplacedHdrs == numObjsWithDisplacedHdrs, "Displaced hdr count"); | |
2750 } | |
2751 | |
2752 void PromotionInfo::print_on(outputStream* st) const { | |
2753 SpoolBlock* curSpool = NULL; | |
2754 size_t i = 0; | |
2755 st->print_cr("start & end indices: [" SIZE_FORMAT ", " SIZE_FORMAT ")", | |
2756 _firstIndex, _nextIndex); | |
2757 for (curSpool = _spoolHead; curSpool != _spoolTail && curSpool != NULL; | |
2758 curSpool = curSpool->nextSpoolBlock) { | |
2759 curSpool->print_on(st); | |
2760 st->print_cr(" active "); | |
2761 i++; | |
2762 } | |
2763 for (curSpool = _spoolTail; curSpool != NULL; | |
2764 curSpool = curSpool->nextSpoolBlock) { | |
2765 curSpool->print_on(st); | |
2766 st->print_cr(" inactive "); | |
2767 i++; | |
2768 } | |
2769 for (curSpool = _spareSpool; curSpool != NULL; | |
2770 curSpool = curSpool->nextSpoolBlock) { | |
2771 curSpool->print_on(st); | |
2772 st->print_cr(" free "); | |
2773 i++; | |
2774 } | |
2775 st->print_cr(SIZE_FORMAT " header spooling blocks", i); | |
2776 } | |
2777 | |
2778 void SpoolBlock::print_on(outputStream* st) const { | |
2779 st->print("[" PTR_FORMAT "," PTR_FORMAT "), " SIZE_FORMAT " HeapWords -> " PTR_FORMAT, | |
2780 this, (HeapWord*)displacedHdr + bufferSize, | |
2781 bufferSize, nextSpoolBlock); | |
2782 } | 2454 } |
2783 | 2455 |
2784 /////////////////////////////////////////////////////////////////////////// | 2456 /////////////////////////////////////////////////////////////////////////// |
2785 // CFLS_LAB | 2457 // CFLS_LAB |
2786 /////////////////////////////////////////////////////////////////////////// | 2458 /////////////////////////////////////////////////////////////////////////// |