ASSERT !heap.vm()->isInitializingObject() when finishing DFG compilation at beginning of GC
https://bugs.webkit.org/show_bug.cgi?id=125472

Reviewed by Geoff Garen.

This patch makes it look like it's okay to allocate so that the DFG plan finalization stuff 
can do what it needs to do. We already expected that we might do allocation during plan 
finalization and we increased the deferral depth to handle this, but we need to fix this other 
ASSERT stuff too.

* GNUmakefile.list.am:
* JavaScriptCore.vcxproj/JavaScriptCore.vcxproj:
* JavaScriptCore.vcxproj/JavaScriptCore.vcxproj.filters:
* JavaScriptCore.xcodeproj/project.pbxproj:
* heap/Heap.cpp:
(JSC::Heap::collect):
* heap/Heap.h:
* heap/RecursiveAllocationScope.h: Added.
(JSC::RecursiveAllocationScope::RecursiveAllocationScope):
(JSC::RecursiveAllocationScope::~RecursiveAllocationScope):
* runtime/VM.h:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@160377 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/JavaScriptCore/heap/Heap.cpp b/Source/JavaScriptCore/heap/Heap.cpp
index 7aeee69..2f8e7f6 100644
--- a/Source/JavaScriptCore/heap/Heap.cpp
+++ b/Source/JavaScriptCore/heap/Heap.cpp
@@ -35,13 +35,14 @@
 #include "HeapStatistics.h"
 #include "IncrementalSweeper.h"
 #include "Interpreter.h"
-#include "VM.h"
 #include "JSGlobalObject.h"
 #include "JSLock.h"
 #include "JSONObject.h"
 #include "Operations.h"
+#include "RecursiveAllocationScope.h"
 #include "Tracing.h"
 #include "UnlinkedCodeBlock.h"
+#include "VM.h"
 #include "WeakSetInlines.h"
 #include <algorithm>
 #include <wtf/RAMSize.h>
@@ -754,9 +755,10 @@
     JAVASCRIPTCORE_GC_BEGIN();
     RELEASE_ASSERT(m_operationInProgress == NoOperation);
     
-    m_deferralDepth++; // Make sure that we don't GC in this call.
-    m_vm->prepareToDiscardCode();
-    m_deferralDepth--; // Decrement deferal manually, so we don't GC when we do so, since we are already GCing!.
+    {
+        RecursiveAllocationScope scope(*this);
+        m_vm->prepareToDiscardCode();
+    }
     
     m_operationInProgress = Collection;
     m_extraMemoryUsage = 0;