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

Side by Side Diff: src/spaces.cc

Issue 7976003: Fix new space shrinking to reset from-space. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments by Lasse Reichstein. Created 9 years, 3 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 | « no previous file | test/cctest/test-heap.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 907 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 918
919 919
920 void NewSpace::Flip() { 920 void NewSpace::Flip() {
921 SemiSpace::Swap(&from_space_, &to_space_); 921 SemiSpace::Swap(&from_space_, &to_space_);
922 } 922 }
923 923
924 924
925 void NewSpace::Grow() { 925 void NewSpace::Grow() {
926 ASSERT(Capacity() < MaximumCapacity()); 926 ASSERT(Capacity() < MaximumCapacity());
927 if (to_space_.Grow()) { 927 if (to_space_.Grow()) {
928 // Only grow from space if we managed to grow to space. 928 // Only grow from space if we managed to grow to-space.
929 if (!from_space_.Grow()) { 929 if (!from_space_.Grow()) {
930 // If we managed to grow to space but couldn't grow from space, 930 // If we managed to grow to-space but couldn't grow from-space,
931 // attempt to shrink to space. 931 // attempt to shrink to-space.
932 if (!to_space_.ShrinkTo(from_space_.Capacity())) { 932 if (!to_space_.ShrinkTo(from_space_.Capacity())) {
933 // We are in an inconsistent state because we could not 933 // We are in an inconsistent state because we could not
934 // commit/uncommit memory from new space. 934 // commit/uncommit memory from new space.
935 V8::FatalProcessOutOfMemory("Failed to grow new space."); 935 V8::FatalProcessOutOfMemory("Failed to grow new space.");
936 } 936 }
937 } 937 }
938 } 938 }
939 ASSERT_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); 939 ASSERT_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_);
940 } 940 }
941 941
942 942
943 void NewSpace::Shrink() { 943 void NewSpace::Shrink() {
944 int new_capacity = Max(InitialCapacity(), 2 * SizeAsInt()); 944 int new_capacity = Max(InitialCapacity(), 2 * SizeAsInt());
945 int rounded_new_capacity = 945 int rounded_new_capacity =
946 RoundUp(new_capacity, static_cast<int>(OS::AllocateAlignment())); 946 RoundUp(new_capacity, static_cast<int>(OS::AllocateAlignment()));
947 if (rounded_new_capacity < Capacity() && 947 if (rounded_new_capacity < Capacity() &&
948 to_space_.ShrinkTo(rounded_new_capacity)) { 948 to_space_.ShrinkTo(rounded_new_capacity)) {
949 // Only shrink from space if we managed to shrink to space. 949 // Only shrink from-space if we managed to shrink to-space.
950 from_space_.Reset();
950 if (!from_space_.ShrinkTo(rounded_new_capacity)) { 951 if (!from_space_.ShrinkTo(rounded_new_capacity)) {
951 // If we managed to shrink to space but couldn't shrink from 952 // If we managed to shrink to-space but couldn't shrink from
952 // space, attempt to grow to space again. 953 // space, attempt to grow to-space again.
953 if (!to_space_.GrowTo(from_space_.Capacity())) { 954 if (!to_space_.GrowTo(from_space_.Capacity())) {
954 // We are in an inconsistent state because we could not 955 // We are in an inconsistent state because we could not
955 // commit/uncommit memory from new space. 956 // commit/uncommit memory from new space.
956 V8::FatalProcessOutOfMemory("Failed to shrink new space."); 957 V8::FatalProcessOutOfMemory("Failed to shrink new space.");
957 } 958 }
958 } 959 }
959 } 960 }
960 allocation_info_.limit = to_space_.page_high(); 961 allocation_info_.limit = to_space_.page_high();
961 ASSERT_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); 962 ASSERT_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_);
962 } 963 }
(...skipping 1537 matching lines...) Expand 10 before | Expand all | Expand 10 after
2500 for (HeapObject* obj = obj_it.Next(); obj != NULL; obj = obj_it.Next()) { 2501 for (HeapObject* obj = obj_it.Next(); obj != NULL; obj = obj_it.Next()) {
2501 if (obj->IsCode()) { 2502 if (obj->IsCode()) {
2502 Code* code = Code::cast(obj); 2503 Code* code = Code::cast(obj);
2503 isolate->code_kind_statistics()[code->kind()] += code->Size(); 2504 isolate->code_kind_statistics()[code->kind()] += code->Size();
2504 } 2505 }
2505 } 2506 }
2506 } 2507 }
2507 #endif // DEBUG 2508 #endif // DEBUG
2508 2509
2509 } } // namespace v8::internal 2510 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | test/cctest/test-heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698