Revision: 3010
Author: [email protected]
Date: Fri Oct  2 06:35:37 2009
Log: When allocation is forced because we already did two GCs we need to  
force GCs
even if we are attempting to allocate in young space.  There were a few  
cases
where this wasn't done.  Also misc. changes to make diagnosis of errors like
this one easier.
Review URL: http://codereview.chromium.org/251072
http://code.google.com/p/v8/source/detail?r=3010

Modified:
  /branches/bleeding_edge/src/api.cc
  /branches/bleeding_edge/src/heap.cc
  /branches/bleeding_edge/src/log-utils.cc
  /branches/bleeding_edge/src/utils.cc
  /branches/bleeding_edge/test/cctest/test-alloc.cc

=======================================
--- /branches/bleeding_edge/src/api.cc  Thu Oct  1 03:33:05 2009
+++ /branches/bleeding_edge/src/api.cc  Fri Oct  2 06:35:37 2009
@@ -107,6 +107,9 @@

  static void DefaultFatalErrorHandler(const char* location,
                                       const char* message) {
+#ifdef DEBUG
+  i::PrintF("Fatal Error: %s: %s\n", location, message);
+#endif
    ENTER_V8;
    API_Fatal(location, message);
  }
=======================================
--- /branches/bleeding_edge/src/heap.cc Thu Oct  1 08:18:05 2009
+++ /branches/bleeding_edge/src/heap.cc Fri Oct  2 06:35:37 2009
@@ -1250,6 +1250,10 @@
    // spaces.
    STATIC_ASSERT(HeapNumber::kSize <= Page::kMaxHeapObjectSize);
    AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE :  
NEW_SPACE;
+
+  // New space can't cope with forced allocation.
+  if (always_allocate()) space = OLD_DATA_SPACE;
+
    Object* result = AllocateRaw(HeapNumber::kSize, space, OLD_DATA_SPACE);
    if (result->IsFailure()) return result;

@@ -1261,7 +1265,8 @@

  Object* Heap::AllocateHeapNumber(double value) {
    // Use general version, if we're forced to always allocate.
-  if (always_allocate()) return AllocateHeapNumber(value, NOT_TENURED);
+  if (always_allocate()) return AllocateHeapNumber(value, TENURED);
+
    // This version of AllocateHeapNumber is optimized for
    // allocation in new space.
    STATIC_ASSERT(HeapNumber::kSize <= Page::kMaxHeapObjectSize);
@@ -1862,6 +1867,9 @@
    AllocationSpace space =
        size > MaxObjectSizeInPagedSpace() ? LO_SPACE : NEW_SPACE;

+  // New space can't cope with forced allocation.
+  if (always_allocate()) space = LO_SPACE;
+
    Object* result = AllocateRaw(size, space, OLD_DATA_SPACE);

    if (result->IsFailure()) return result;
@@ -1889,6 +1897,9 @@
                                   PretenureFlag pretenure) {
    AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE :  
NEW_SPACE;

+  // New space can't cope with forced allocation.
+  if (always_allocate()) space = OLD_DATA_SPACE;
+
    Object* result = AllocateRaw(PixelArray::kAlignedSize, space,  
OLD_DATA_SPACE);

    if (result->IsFailure()) return result;
@@ -2532,13 +2543,17 @@

  Object* Heap::AllocateRawAsciiString(int length, PretenureFlag pretenure) {
    AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE :  
NEW_SPACE;
+
+  // New space can't cope with forced allocation.
+  if (always_allocate()) space = OLD_DATA_SPACE;
+
    int size = SeqAsciiString::SizeFor(length);

    Object* result = Failure::OutOfMemoryException();
    if (space == NEW_SPACE) {
      result = size <= kMaxObjectSizeInNewSpace
          ? new_space_.AllocateRaw(size)
-        : lo_space_->AllocateRawFixedArray(size);
+        : lo_space_->AllocateRaw(size);
    } else {
      if (size > MaxObjectSizeInPagedSpace()) space = LO_SPACE;
      result = AllocateRaw(size, space, OLD_DATA_SPACE);
@@ -2565,13 +2580,17 @@

  Object* Heap::AllocateRawTwoByteString(int length, PretenureFlag  
pretenure) {
    AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE :  
NEW_SPACE;
+
+  // New space can't cope with forced allocation.
+  if (always_allocate()) space = OLD_DATA_SPACE;
+
    int size = SeqTwoByteString::SizeFor(length);

    Object* result = Failure::OutOfMemoryException();
    if (space == NEW_SPACE) {
      result = size <= kMaxObjectSizeInNewSpace
          ? new_space_.AllocateRaw(size)
-        : lo_space_->AllocateRawFixedArray(size);
+        : lo_space_->AllocateRaw(size);
    } else {
      if (size > MaxObjectSizeInPagedSpace()) space = LO_SPACE;
      result = AllocateRaw(size, space, OLD_DATA_SPACE);
@@ -2609,7 +2628,7 @@

  Object* Heap::AllocateRawFixedArray(int length) {
    // Use the general function if we're forced to always allocate.
-  if (always_allocate()) return AllocateFixedArray(length, NOT_TENURED);
+  if (always_allocate()) return AllocateFixedArray(length, TENURED);
    // Allocate the raw data for a fixed array.
    int size = FixedArray::SizeFor(length);
    return size <= kMaxObjectSizeInNewSpace
@@ -2662,6 +2681,9 @@
    ASSERT(empty_fixed_array()->IsFixedArray());
    if (length == 0) return empty_fixed_array();

+  // New space can't cope with forced allocation.
+  if (always_allocate()) pretenure = TENURED;
+
    int size = FixedArray::SizeFor(length);
    Object* result = Failure::OutOfMemoryException();
    if (pretenure != TENURED) {
=======================================
--- /branches/bleeding_edge/src/log-utils.cc    Fri Sep 18 06:23:58 2009
+++ /branches/bleeding_edge/src/log-utils.cc    Fri Oct  2 06:35:37 2009
@@ -163,7 +163,7 @@

  void Log::Close() {
    if (Write == WriteToFile) {
-    fclose(output_handle_);
+    if (output_handle_ != NULL) fclose(output_handle_);
      output_handle_ = NULL;
    } else if (Write == WriteToMemory) {
      delete output_buffer_;
=======================================
--- /branches/bleeding_edge/src/utils.cc        Mon May 25 03:05:56 2009
+++ /branches/bleeding_edge/src/utils.cc        Fri Oct  2 06:35:37 2009
@@ -239,7 +239,7 @@
    FILE* f = OS::FOpen(filename, "wb");
    if (f == NULL) {
      if (verbose) {
-      OS::PrintError("Cannot open file %s for reading.\n", filename);
+      OS::PrintError("Cannot open file %s for writing.\n", filename);
      }
      return 0;
    }
=======================================
--- /branches/bleeding_edge/test/cctest/test-alloc.cc   Thu Oct  1 08:18:05  
2009
+++ /branches/bleeding_edge/test/cctest/test-alloc.cc   Fri Oct  2 06:35:37  
2009
@@ -43,7 +43,14 @@
    NewSpace* new_space = Heap::new_space();
    static const int kNewSpaceFillerSize = ByteArray::SizeFor(0);
    while (new_space->Available() > kNewSpaceFillerSize) {
+    int available_before = new_space->Available();
      CHECK(!Heap::AllocateByteArray(0)->IsFailure());
+    if (available_before == new_space->Available()) {
+      // It seems that we are avoiding new space allocations when
+      // allocation is forced, so no need to fill up new space
+      // in order to make the test harder.
+      break;
+    }
    }
    CHECK(!Heap::AllocateByteArray(100)->IsFailure());
    CHECK(!Heap::AllocateFixedArray(100, NOT_TENURED)->IsFailure());

--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to