Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Side by Side Diff: src/mark-compact.cc

Issue 19182002: Added mark bit cell iterator. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/mark-compact.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1921 matching lines...) Expand 10 before | Expand all | Expand 10 after
1932 1932
1933 1933
1934 static void DiscoverGreyObjectsOnPage(MarkingDeque* marking_deque, 1934 static void DiscoverGreyObjectsOnPage(MarkingDeque* marking_deque,
1935 MemoryChunk* p) { 1935 MemoryChunk* p) {
1936 ASSERT(!marking_deque->IsFull()); 1936 ASSERT(!marking_deque->IsFull());
1937 ASSERT(strcmp(Marking::kWhiteBitPattern, "00") == 0); 1937 ASSERT(strcmp(Marking::kWhiteBitPattern, "00") == 0);
1938 ASSERT(strcmp(Marking::kBlackBitPattern, "10") == 0); 1938 ASSERT(strcmp(Marking::kBlackBitPattern, "10") == 0);
1939 ASSERT(strcmp(Marking::kGreyBitPattern, "11") == 0); 1939 ASSERT(strcmp(Marking::kGreyBitPattern, "11") == 0);
1940 ASSERT(strcmp(Marking::kImpossibleBitPattern, "01") == 0); 1940 ASSERT(strcmp(Marking::kImpossibleBitPattern, "01") == 0);
1941 1941
1942 MarkBit::CellType* cells = p->markbits()->cells(); 1942 for (MarkBitCellIterator it(p); !it.Done(); it.Advance()) {
1943 Address cell_base = it.CurrentCellBase();
1944 MarkBit::CellType* cell = it.CurrentCell();
1943 1945
1944 int last_cell_index = 1946 const MarkBit::CellType current_cell = *cell;
1945 Bitmap::IndexToCell(
1946 Bitmap::CellAlignIndex(
1947 p->AddressToMarkbitIndex(p->area_end())));
1948
1949 Address cell_base = p->area_start();
1950 int cell_index = Bitmap::IndexToCell(
1951 Bitmap::CellAlignIndex(
1952 p->AddressToMarkbitIndex(cell_base)));
1953
1954
1955 for (;
1956 cell_index < last_cell_index;
1957 cell_index++, cell_base += 32 * kPointerSize) {
1958 ASSERT(static_cast<unsigned>(cell_index) ==
1959 Bitmap::IndexToCell(
1960 Bitmap::CellAlignIndex(
1961 p->AddressToMarkbitIndex(cell_base))));
1962
1963 const MarkBit::CellType current_cell = cells[cell_index];
1964 if (current_cell == 0) continue; 1947 if (current_cell == 0) continue;
1965 1948
1966 const MarkBit::CellType next_cell = cells[cell_index + 1]; 1949 MarkBit::CellType grey_objects;
1967 MarkBit::CellType grey_objects = current_cell & 1950 if (it.HasNext()) {
1968 ((current_cell >> 1) | (next_cell << (Bitmap::kBitsPerCell - 1))); 1951 const MarkBit::CellType next_cell = *(cell+1);
1952 grey_objects = current_cell &
1953 ((current_cell >> 1) | (next_cell << (Bitmap::kBitsPerCell - 1)));
1954 } else {
1955 grey_objects = current_cell & (current_cell >> 1);
1956 }
1969 1957
1970 int offset = 0; 1958 int offset = 0;
1971 while (grey_objects != 0) { 1959 while (grey_objects != 0) {
1972 int trailing_zeros = CompilerIntrinsics::CountTrailingZeros(grey_objects); 1960 int trailing_zeros = CompilerIntrinsics::CountTrailingZeros(grey_objects);
1973 grey_objects >>= trailing_zeros; 1961 grey_objects >>= trailing_zeros;
1974 offset += trailing_zeros; 1962 offset += trailing_zeros;
1975 MarkBit markbit(&cells[cell_index], 1 << offset, false); 1963 MarkBit markbit(cell, 1 << offset, false);
1976 ASSERT(Marking::IsGrey(markbit)); 1964 ASSERT(Marking::IsGrey(markbit));
1977 Marking::GreyToBlack(markbit); 1965 Marking::GreyToBlack(markbit);
1978 Address addr = cell_base + offset * kPointerSize; 1966 Address addr = cell_base + offset * kPointerSize;
1979 HeapObject* object = HeapObject::FromAddress(addr); 1967 HeapObject* object = HeapObject::FromAddress(addr);
1980 MemoryChunk::IncrementLiveBytesFromGC(object->address(), object->Size()); 1968 MemoryChunk::IncrementLiveBytesFromGC(object->address(), object->Size());
1981 marking_deque->PushBlack(object); 1969 marking_deque->PushBlack(object);
1982 if (marking_deque->IsFull()) return; 1970 if (marking_deque->IsFull()) return;
1983 offset += 2; 1971 offset += 2;
1984 grey_objects >>= 2; 1972 grey_objects >>= 2;
1985 } 1973 }
1986 1974
1987 grey_objects >>= (Bitmap::kBitsPerCell - 1); 1975 grey_objects >>= (Bitmap::kBitsPerCell - 1);
1988 } 1976 }
1989 } 1977 }
1990 1978
1991 1979
1992 int MarkCompactCollector::DiscoverAndPromoteBlackObjectsOnPage( 1980 int MarkCompactCollector::DiscoverAndPromoteBlackObjectsOnPage(
1993 NewSpace* new_space, 1981 NewSpace* new_space,
1994 NewSpacePage* p) { 1982 NewSpacePage* p) {
1995 ASSERT(strcmp(Marking::kWhiteBitPattern, "00") == 0); 1983 ASSERT(strcmp(Marking::kWhiteBitPattern, "00") == 0);
1996 ASSERT(strcmp(Marking::kBlackBitPattern, "10") == 0); 1984 ASSERT(strcmp(Marking::kBlackBitPattern, "10") == 0);
1997 ASSERT(strcmp(Marking::kGreyBitPattern, "11") == 0); 1985 ASSERT(strcmp(Marking::kGreyBitPattern, "11") == 0);
1998 ASSERT(strcmp(Marking::kImpossibleBitPattern, "01") == 0); 1986 ASSERT(strcmp(Marking::kImpossibleBitPattern, "01") == 0);
1999 1987
2000 MarkBit::CellType* cells = p->markbits()->cells(); 1988 MarkBit::CellType* cells = p->markbits()->cells();
2001 int survivors_size = 0; 1989 int survivors_size = 0;
2002 1990
2003 int last_cell_index = 1991 for (MarkBitCellIterator it(p); !it.Done(); it.Advance()) {
2004 Bitmap::IndexToCell( 1992 Address cell_base = it.CurrentCellBase();
2005 Bitmap::CellAlignIndex( 1993 MarkBit::CellType* cell = it.CurrentCell();
2006 p->AddressToMarkbitIndex(p->area_end())));
2007 1994
2008 Address cell_base = p->area_start(); 1995 MarkBit::CellType current_cell = *cell;
2009 int cell_index = Bitmap::IndexToCell(
2010 Bitmap::CellAlignIndex(
2011 p->AddressToMarkbitIndex(cell_base)));
2012
2013 for (;
2014 cell_index < last_cell_index;
2015 cell_index++, cell_base += 32 * kPointerSize) {
2016 ASSERT(static_cast<unsigned>(cell_index) ==
2017 Bitmap::IndexToCell(
2018 Bitmap::CellAlignIndex(
2019 p->AddressToMarkbitIndex(cell_base))));
2020
2021 MarkBit::CellType current_cell = cells[cell_index];
2022 if (current_cell == 0) continue; 1996 if (current_cell == 0) continue;
2023 1997
2024 int offset = 0; 1998 int offset = 0;
2025 while (current_cell != 0) { 1999 while (current_cell != 0) {
2026 int trailing_zeros = CompilerIntrinsics::CountTrailingZeros(current_cell); 2000 int trailing_zeros = CompilerIntrinsics::CountTrailingZeros(current_cell);
2027 current_cell >>= trailing_zeros; 2001 current_cell >>= trailing_zeros;
2028 offset += trailing_zeros; 2002 offset += trailing_zeros;
2029 Address address = cell_base + offset * kPointerSize; 2003 Address address = cell_base + offset * kPointerSize;
2030 HeapObject* object = HeapObject::FromAddress(address); 2004 HeapObject* object = HeapObject::FromAddress(address);
2031 2005
(...skipping 19 matching lines...) Expand all
2051 allocation = new_space->AllocateRaw(size); 2025 allocation = new_space->AllocateRaw(size);
2052 ASSERT(!allocation->IsFailure()); 2026 ASSERT(!allocation->IsFailure());
2053 } 2027 }
2054 Object* target = allocation->ToObjectUnchecked(); 2028 Object* target = allocation->ToObjectUnchecked();
2055 2029
2056 MigrateObject(HeapObject::cast(target)->address(), 2030 MigrateObject(HeapObject::cast(target)->address(),
2057 object->address(), 2031 object->address(),
2058 size, 2032 size,
2059 NEW_SPACE); 2033 NEW_SPACE);
2060 } 2034 }
2061 cells[cell_index] = 0; 2035 *cells = 0;
2062 } 2036 }
2063 return survivors_size; 2037 return survivors_size;
2064 } 2038 }
2065 2039
2066 2040
2067 static void DiscoverGreyObjectsInSpace(Heap* heap, 2041 static void DiscoverGreyObjectsInSpace(Heap* heap,
2068 MarkingDeque* marking_deque, 2042 MarkingDeque* marking_deque,
2069 PagedSpace* space) { 2043 PagedSpace* space) {
2070 if (!space->was_swept_conservatively()) { 2044 if (!space->was_swept_conservatively()) {
2071 HeapObjectIterator it(space); 2045 HeapObjectIterator it(space);
(...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after
2978 2952
2979 heap_->IncrementYoungSurvivorsCounter(survivors_size); 2953 heap_->IncrementYoungSurvivorsCounter(survivors_size);
2980 new_space->set_age_mark(new_space->top()); 2954 new_space->set_age_mark(new_space->top());
2981 } 2955 }
2982 2956
2983 2957
2984 void MarkCompactCollector::EvacuateLiveObjectsFromPage(Page* p) { 2958 void MarkCompactCollector::EvacuateLiveObjectsFromPage(Page* p) {
2985 AlwaysAllocateScope always_allocate; 2959 AlwaysAllocateScope always_allocate;
2986 PagedSpace* space = static_cast<PagedSpace*>(p->owner()); 2960 PagedSpace* space = static_cast<PagedSpace*>(p->owner());
2987 ASSERT(p->IsEvacuationCandidate() && !p->WasSwept()); 2961 ASSERT(p->IsEvacuationCandidate() && !p->WasSwept());
2988 MarkBit::CellType* cells = p->markbits()->cells();
2989 p->MarkSweptPrecisely(); 2962 p->MarkSweptPrecisely();
2990 2963
2991 int last_cell_index =
2992 Bitmap::IndexToCell(
2993 Bitmap::CellAlignIndex(
2994 p->AddressToMarkbitIndex(p->area_end())));
2995
2996 Address cell_base = p->area_start();
2997 int cell_index = Bitmap::IndexToCell(
2998 Bitmap::CellAlignIndex(
2999 p->AddressToMarkbitIndex(cell_base)));
3000
3001 int offsets[16]; 2964 int offsets[16];
3002 2965
3003 for (; 2966 for (MarkBitCellIterator it(p); !it.Done(); it.Advance()) {
3004 cell_index < last_cell_index; 2967 Address cell_base = it.CurrentCellBase();
3005 cell_index++, cell_base += 32 * kPointerSize) { 2968 MarkBit::CellType* cell = it.CurrentCell();
3006 ASSERT(static_cast<unsigned>(cell_index) ==
3007 Bitmap::IndexToCell(
3008 Bitmap::CellAlignIndex(
3009 p->AddressToMarkbitIndex(cell_base))));
3010 if (cells[cell_index] == 0) continue;
3011 2969
3012 int live_objects = MarkWordToObjectStarts(cells[cell_index], offsets); 2970 if (*cell == 0) continue;
2971
2972 int live_objects = MarkWordToObjectStarts(*cell, offsets);
3013 for (int i = 0; i < live_objects; i++) { 2973 for (int i = 0; i < live_objects; i++) {
3014 Address object_addr = cell_base + offsets[i] * kPointerSize; 2974 Address object_addr = cell_base + offsets[i] * kPointerSize;
3015 HeapObject* object = HeapObject::FromAddress(object_addr); 2975 HeapObject* object = HeapObject::FromAddress(object_addr);
3016 ASSERT(Marking::IsBlack(Marking::MarkBitFrom(object))); 2976 ASSERT(Marking::IsBlack(Marking::MarkBitFrom(object)));
3017 2977
3018 int size = object->Size(); 2978 int size = object->Size();
3019 2979
3020 MaybeObject* target = space->AllocateRaw(size); 2980 MaybeObject* target = space->AllocateRaw(size);
3021 if (target->IsFailure()) { 2981 if (target->IsFailure()) {
3022 // OS refused to give us memory. 2982 // OS refused to give us memory.
3023 V8::FatalProcessOutOfMemory("Evacuation"); 2983 V8::FatalProcessOutOfMemory("Evacuation");
3024 return; 2984 return;
3025 } 2985 }
3026 2986
3027 Object* target_object = target->ToObjectUnchecked(); 2987 Object* target_object = target->ToObjectUnchecked();
3028 2988
3029 MigrateObject(HeapObject::cast(target_object)->address(), 2989 MigrateObject(HeapObject::cast(target_object)->address(),
3030 object_addr, 2990 object_addr,
3031 size, 2991 size,
3032 space->identity()); 2992 space->identity());
3033 ASSERT(object->map_word().IsForwardingAddress()); 2993 ASSERT(object->map_word().IsForwardingAddress());
3034 } 2994 }
3035 2995
3036 // Clear marking bits for current cell. 2996 // Clear marking bits for current cell.
3037 cells[cell_index] = 0; 2997 *cell = 0;
3038 } 2998 }
3039 p->ResetLiveBytes(); 2999 p->ResetLiveBytes();
3040 } 3000 }
3041 3001
3042 3002
3043 void MarkCompactCollector::EvacuatePages() { 3003 void MarkCompactCollector::EvacuatePages() {
3044 int npages = evacuation_candidates_.length(); 3004 int npages = evacuation_candidates_.length();
3045 for (int i = 0; i < npages; i++) { 3005 for (int i = 0; i < npages; i++) {
3046 Page* p = evacuation_candidates_[i]; 3006 Page* p = evacuation_candidates_[i];
3047 ASSERT(p->IsEvacuationCandidate() || 3007 ASSERT(p->IsEvacuationCandidate() ||
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
3148 ASSERT(!p->IsEvacuationCandidate() && !p->WasSwept()); 3108 ASSERT(!p->IsEvacuationCandidate() && !p->WasSwept());
3149 ASSERT_EQ(skip_list_mode == REBUILD_SKIP_LIST, 3109 ASSERT_EQ(skip_list_mode == REBUILD_SKIP_LIST,
3150 space->identity() == CODE_SPACE); 3110 space->identity() == CODE_SPACE);
3151 ASSERT((p->skip_list() == NULL) || (skip_list_mode == REBUILD_SKIP_LIST)); 3111 ASSERT((p->skip_list() == NULL) || (skip_list_mode == REBUILD_SKIP_LIST));
3152 3112
3153 double start_time = 0.0; 3113 double start_time = 0.0;
3154 if (FLAG_print_cumulative_gc_stat) { 3114 if (FLAG_print_cumulative_gc_stat) {
3155 start_time = OS::TimeCurrentMillis(); 3115 start_time = OS::TimeCurrentMillis();
3156 } 3116 }
3157 3117
3158 MarkBit::CellType* cells = p->markbits()->cells();
3159 p->MarkSweptPrecisely(); 3118 p->MarkSweptPrecisely();
3160 3119
3161 int last_cell_index =
3162 Bitmap::IndexToCell(
3163 Bitmap::CellAlignIndex(
3164 p->AddressToMarkbitIndex(p->area_end())));
3165
3166 Address free_start = p->area_start(); 3120 Address free_start = p->area_start();
3167 int cell_index =
3168 Bitmap::IndexToCell(
3169 Bitmap::CellAlignIndex(
3170 p->AddressToMarkbitIndex(free_start)));
3171
3172 ASSERT(reinterpret_cast<intptr_t>(free_start) % (32 * kPointerSize) == 0); 3121 ASSERT(reinterpret_cast<intptr_t>(free_start) % (32 * kPointerSize) == 0);
3173 Address object_address = free_start;
3174 int offsets[16]; 3122 int offsets[16];
3175 3123
3176 SkipList* skip_list = p->skip_list(); 3124 SkipList* skip_list = p->skip_list();
3177 int curr_region = -1; 3125 int curr_region = -1;
3178 if ((skip_list_mode == REBUILD_SKIP_LIST) && skip_list) { 3126 if ((skip_list_mode == REBUILD_SKIP_LIST) && skip_list) {
3179 skip_list->Clear(); 3127 skip_list->Clear();
3180 } 3128 }
3181 3129
3182 for (; 3130 for (MarkBitCellIterator it(p); !it.Done(); it.Advance()) {
3183 cell_index < last_cell_index; 3131 Address cell_base = it.CurrentCellBase();
3184 cell_index++, object_address += 32 * kPointerSize) { 3132 MarkBit::CellType* cell = it.CurrentCell();
3185 ASSERT(static_cast<unsigned>(cell_index) == 3133 int live_objects = MarkWordToObjectStarts(*cell, offsets);
3186 Bitmap::IndexToCell(
3187 Bitmap::CellAlignIndex(
3188 p->AddressToMarkbitIndex(object_address))));
3189 int live_objects = MarkWordToObjectStarts(cells[cell_index], offsets);
3190 int live_index = 0; 3134 int live_index = 0;
3191 for ( ; live_objects != 0; live_objects--) { 3135 for ( ; live_objects != 0; live_objects--) {
3192 Address free_end = object_address + offsets[live_index++] * kPointerSize; 3136 Address free_end = cell_base + offsets[live_index++] * kPointerSize;
3193 if (free_end != free_start) { 3137 if (free_end != free_start) {
3194 space->Free(free_start, static_cast<int>(free_end - free_start)); 3138 space->Free(free_start, static_cast<int>(free_end - free_start));
3195 #ifdef ENABLE_GDB_JIT_INTERFACE 3139 #ifdef ENABLE_GDB_JIT_INTERFACE
3196 if (FLAG_gdbjit && space->identity() == CODE_SPACE) { 3140 if (FLAG_gdbjit && space->identity() == CODE_SPACE) {
3197 GDBJITInterface::RemoveCodeRange(free_start, free_end); 3141 GDBJITInterface::RemoveCodeRange(free_start, free_end);
3198 } 3142 }
3199 #endif 3143 #endif
3200 } 3144 }
3201 HeapObject* live_object = HeapObject::FromAddress(free_end); 3145 HeapObject* live_object = HeapObject::FromAddress(free_end);
3202 ASSERT(Marking::IsBlack(Marking::MarkBitFrom(live_object))); 3146 ASSERT(Marking::IsBlack(Marking::MarkBitFrom(live_object)));
3203 Map* map = live_object->map(); 3147 Map* map = live_object->map();
3204 int size = live_object->SizeFromMap(map); 3148 int size = live_object->SizeFromMap(map);
3205 if (sweeping_mode == SWEEP_AND_VISIT_LIVE_OBJECTS) { 3149 if (sweeping_mode == SWEEP_AND_VISIT_LIVE_OBJECTS) {
3206 live_object->IterateBody(map->instance_type(), size, v); 3150 live_object->IterateBody(map->instance_type(), size, v);
3207 } 3151 }
3208 if ((skip_list_mode == REBUILD_SKIP_LIST) && skip_list != NULL) { 3152 if ((skip_list_mode == REBUILD_SKIP_LIST) && skip_list != NULL) {
3209 int new_region_start = 3153 int new_region_start =
3210 SkipList::RegionNumber(free_end); 3154 SkipList::RegionNumber(free_end);
3211 int new_region_end = 3155 int new_region_end =
3212 SkipList::RegionNumber(free_end + size - kPointerSize); 3156 SkipList::RegionNumber(free_end + size - kPointerSize);
3213 if (new_region_start != curr_region || 3157 if (new_region_start != curr_region ||
3214 new_region_end != curr_region) { 3158 new_region_end != curr_region) {
3215 skip_list->AddObject(free_end, size); 3159 skip_list->AddObject(free_end, size);
3216 curr_region = new_region_end; 3160 curr_region = new_region_end;
3217 } 3161 }
3218 } 3162 }
3219 free_start = free_end + size; 3163 free_start = free_end + size;
3220 } 3164 }
3221 // Clear marking bits for current cell. 3165 // Clear marking bits for current cell.
3222 cells[cell_index] = 0; 3166 *cell = 0;
3223 } 3167 }
3224 if (free_start != p->area_end()) { 3168 if (free_start != p->area_end()) {
3225 space->Free(free_start, static_cast<int>(p->area_end() - free_start)); 3169 space->Free(free_start, static_cast<int>(p->area_end() - free_start));
3226 #ifdef ENABLE_GDB_JIT_INTERFACE 3170 #ifdef ENABLE_GDB_JIT_INTERFACE
3227 if (FLAG_gdbjit && space->identity() == CODE_SPACE) { 3171 if (FLAG_gdbjit && space->identity() == CODE_SPACE) {
3228 GDBJITInterface::RemoveCodeRange(free_start, p->area_end()); 3172 GDBJITInterface::RemoveCodeRange(free_start, p->area_end());
3229 } 3173 }
3230 #endif 3174 #endif
3231 } 3175 }
3232 p->ResetLiveBytes(); 3176 p->ResetLiveBytes();
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after
3879 template<MarkCompactCollector::SweepingParallelism mode> 3823 template<MarkCompactCollector::SweepingParallelism mode>
3880 intptr_t MarkCompactCollector::SweepConservatively(PagedSpace* space, 3824 intptr_t MarkCompactCollector::SweepConservatively(PagedSpace* space,
3881 FreeList* free_list, 3825 FreeList* free_list,
3882 Page* p) { 3826 Page* p) {
3883 ASSERT(!p->IsEvacuationCandidate() && !p->WasSwept()); 3827 ASSERT(!p->IsEvacuationCandidate() && !p->WasSwept());
3884 ASSERT((mode == MarkCompactCollector::SWEEP_IN_PARALLEL && 3828 ASSERT((mode == MarkCompactCollector::SWEEP_IN_PARALLEL &&
3885 free_list != NULL) || 3829 free_list != NULL) ||
3886 (mode == MarkCompactCollector::SWEEP_SEQUENTIALLY && 3830 (mode == MarkCompactCollector::SWEEP_SEQUENTIALLY &&
3887 free_list == NULL)); 3831 free_list == NULL));
3888 3832
3889 MarkBit::CellType* cells = p->markbits()->cells();
3890 p->MarkSweptConservatively(); 3833 p->MarkSweptConservatively();
3891 3834
3892 int last_cell_index =
3893 Bitmap::IndexToCell(
3894 Bitmap::CellAlignIndex(
3895 p->AddressToMarkbitIndex(p->area_end())));
3896
3897 int cell_index =
3898 Bitmap::IndexToCell(
3899 Bitmap::CellAlignIndex(
3900 p->AddressToMarkbitIndex(p->area_start())));
3901
3902 intptr_t freed_bytes = 0; 3835 intptr_t freed_bytes = 0;
3903 3836 size_t size = 0;
3904 // This is the start of the 32 word block that we are currently looking at.
3905 Address block_address = p->area_start();
3906 3837
3907 // Skip over all the dead objects at the start of the page and mark them free. 3838 // Skip over all the dead objects at the start of the page and mark them free.
3908 for (; 3839 Address cell_base = 0;
3909 cell_index < last_cell_index; 3840 MarkBit::CellType* cell = NULL;
3910 cell_index++, block_address += 32 * kPointerSize) { 3841 MarkBitCellIterator it(p);
3911 if (cells[cell_index] != 0) break; 3842 for (; !it.Done(); it.Advance()) {
3843 cell_base = it.CurrentCellBase();
3844 cell = it.CurrentCell();
3845 if (*cell != 0) break;
3912 } 3846 }
3913 size_t size = block_address - p->area_start(); 3847
3914 if (cell_index == last_cell_index) { 3848 if (it.Done()) {
3849 size = p->area_end() - p->area_start();
3915 freed_bytes += Free<mode>(space, free_list, p->area_start(), 3850 freed_bytes += Free<mode>(space, free_list, p->area_start(),
3916 static_cast<int>(size)); 3851 static_cast<int>(size));
3917 ASSERT_EQ(0, p->LiveBytes()); 3852 ASSERT_EQ(0, p->LiveBytes());
3918 return freed_bytes; 3853 return freed_bytes;
3919 } 3854 }
3855
3920 // Grow the size of the start-of-page free space a little to get up to the 3856 // Grow the size of the start-of-page free space a little to get up to the
3921 // first live object. 3857 // first live object.
3922 Address free_end = StartOfLiveObject(block_address, cells[cell_index]); 3858 Address free_end = StartOfLiveObject(cell_base, *cell);
3923 // Free the first free space. 3859 // Free the first free space.
3924 size = free_end - p->area_start(); 3860 size = free_end - p->area_start();
3925 freed_bytes += Free<mode>(space, free_list, p->area_start(), 3861 freed_bytes += Free<mode>(space, free_list, p->area_start(),
3926 static_cast<int>(size)); 3862 static_cast<int>(size));
3927 3863
3928 // The start of the current free area is represented in undigested form by 3864 // The start of the current free area is represented in undigested form by
3929 // the address of the last 32-word section that contained a live object and 3865 // the address of the last 32-word section that contained a live object and
3930 // the marking bitmap for that cell, which describes where the live object 3866 // the marking bitmap for that cell, which describes where the live object
3931 // started. Unless we find a large free space in the bitmap we will not 3867 // started. Unless we find a large free space in the bitmap we will not
3932 // digest this pair into a real address. We start the iteration here at the 3868 // digest this pair into a real address. We start the iteration here at the
3933 // first word in the marking bit map that indicates a live object. 3869 // first word in the marking bit map that indicates a live object.
3934 Address free_start = block_address; 3870 Address free_start = cell_base;
3935 uint32_t free_start_cell = cells[cell_index]; 3871 MarkBit::CellType free_start_cell = *cell;
3936 3872
3937 for ( ; 3873 for (; !it.Done(); it.Advance()) {
3938 cell_index < last_cell_index; 3874 cell_base = it.CurrentCellBase();
3939 cell_index++, block_address += 32 * kPointerSize) { 3875 cell = it.CurrentCell();
3940 ASSERT((unsigned)cell_index == 3876 if (*cell != 0) {
3941 Bitmap::IndexToCell(
3942 Bitmap::CellAlignIndex(
3943 p->AddressToMarkbitIndex(block_address))));
3944 uint32_t cell = cells[cell_index];
3945 if (cell != 0) {
3946 // We have a live object. Check approximately whether it is more than 32 3877 // We have a live object. Check approximately whether it is more than 32
3947 // words since the last live object. 3878 // words since the last live object.
3948 if (block_address - free_start > 32 * kPointerSize) { 3879 if (cell_base - free_start > 32 * kPointerSize) {
3949 free_start = DigestFreeStart(free_start, free_start_cell); 3880 free_start = DigestFreeStart(free_start, free_start_cell);
3950 if (block_address - free_start > 32 * kPointerSize) { 3881 if (cell_base - free_start > 32 * kPointerSize) {
3951 // Now that we know the exact start of the free space it still looks 3882 // Now that we know the exact start of the free space it still looks
3952 // like we have a large enough free space to be worth bothering with. 3883 // like we have a large enough free space to be worth bothering with.
3953 // so now we need to find the start of the first live object at the 3884 // so now we need to find the start of the first live object at the
3954 // end of the free space. 3885 // end of the free space.
3955 free_end = StartOfLiveObject(block_address, cell); 3886 free_end = StartOfLiveObject(cell_base, *cell);
3956 freed_bytes += Free<mode>(space, free_list, free_start, 3887 freed_bytes += Free<mode>(space, free_list, free_start,
3957 static_cast<int>(free_end - free_start)); 3888 static_cast<int>(free_end - free_start));
3958 } 3889 }
3959 } 3890 }
3960 // Update our undigested record of where the current free area started. 3891 // Update our undigested record of where the current free area started.
3961 free_start = block_address; 3892 free_start = cell_base;
3962 free_start_cell = cell; 3893 free_start_cell = *cell;
3963 // Clear marking bits for current cell. 3894 // Clear marking bits for current cell.
3964 cells[cell_index] = 0; 3895 *cell = 0;
3965 } 3896 }
3966 } 3897 }
3967 3898
3968 // Handle the free space at the end of the page. 3899 // Handle the free space at the end of the page.
3969 if (block_address - free_start > 32 * kPointerSize) { 3900 if (cell_base - free_start > 32 * kPointerSize) {
3970 free_start = DigestFreeStart(free_start, free_start_cell); 3901 free_start = DigestFreeStart(free_start, free_start_cell);
3971 freed_bytes += Free<mode>(space, free_list, free_start, 3902 freed_bytes += Free<mode>(space, free_list, free_start,
3972 static_cast<int>(block_address - free_start)); 3903 static_cast<int>(p->area_end() - free_start));
3973 } 3904 }
3974 3905
3975 p->ResetLiveBytes(); 3906 p->ResetLiveBytes();
3976 return freed_bytes; 3907 return freed_bytes;
3977 } 3908 }
3978 3909
3979 3910
3980 void MarkCompactCollector::SweepInParallel(PagedSpace* space, 3911 void MarkCompactCollector::SweepInParallel(PagedSpace* space,
3981 FreeList* private_free_list, 3912 FreeList* private_free_list,
3982 FreeList* free_list) { 3913 FreeList* free_list) {
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
4372 while (buffer != NULL) { 4303 while (buffer != NULL) {
4373 SlotsBuffer* next_buffer = buffer->next(); 4304 SlotsBuffer* next_buffer = buffer->next();
4374 DeallocateBuffer(buffer); 4305 DeallocateBuffer(buffer);
4375 buffer = next_buffer; 4306 buffer = next_buffer;
4376 } 4307 }
4377 *buffer_address = NULL; 4308 *buffer_address = NULL;
4378 } 4309 }
4379 4310
4380 4311
4381 } } // namespace v8::internal 4312 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/mark-compact.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698