Reviewers: Jakob,

Message:
PTAL

Description:
Use mock ArrayBuffer allocator to avoid really allocating 1Gb.

[email protected]

Please review this at https://codereview.chromium.org/61623009/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+37, -7 lines):
  M src/d8.h
  M src/d8.cc
  M test/mjsunit/mjsunit.status
  M test/mjsunit/regress/regress-319722-ArrayBuffer.js


Index: src/d8.cc
diff --git a/src/d8.cc b/src/d8.cc
index d227ac3a3dcea03755ced48391ac2616592f2bc0..eaec7d3c3f4d7021ac82a03bea5f57fb5b5ca9db 100644
--- a/src/d8.cc
+++ b/src/d8.cc
@@ -1364,6 +1364,9 @@ bool Shell::SetOptions(int argc, char* argv[]) {
     } else if (strcmp(argv[i], "--stress-deopt") == 0) {
       options.stress_deopt = true;
       argv[i] = NULL;
+    } else if (strcmp(argv[i], "--mock-arraybuffer-allocator") == 0) {
+      options.mock_arraybuffer_allocator = true;
+      argv[i] = NULL;
     } else if (strcmp(argv[i], "--noalways-opt") == 0) {
       // No support for stressing if we can't use --always-opt.
       options.stress_opt = false;
@@ -1673,6 +1676,19 @@ class ShellArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
 };


+class MockArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
+ public:
+  virtual void* Allocate(size_t) V8_OVERRIDE {
+    return malloc(0);
+  }
+  virtual void* AllocateUninitialized(size_t length) V8_OVERRIDE {
+    return malloc(0);
+  }
+  virtual void Free(void*, size_t) V8_OVERRIDE {
+  }
+};
+
+
 int Shell::Main(int argc, char* argv[]) {
   if (!SetOptions(argc, argv)) return 1;
   v8::V8::InitializeICU();
@@ -1683,7 +1699,12 @@ int Shell::Main(int argc, char* argv[]) {
   SetStandaloneFlagsViaCommandLine();
 #endif
   ShellArrayBufferAllocator array_buffer_allocator;
-  v8::V8::SetArrayBufferAllocator(&array_buffer_allocator);
+  MockArrayBufferAllocator mock_arraybuffer_allocator;
+  if (options.mock_arraybuffer_allocator) {
+    v8::V8::SetArrayBufferAllocator(&mock_arraybuffer_allocator);
+  } else {
+    v8::V8::SetArrayBufferAllocator(&array_buffer_allocator);
+  }
   int result = 0;
   Isolate* isolate = Isolate::GetCurrent();
 #ifndef V8_SHARED
Index: src/d8.h
diff --git a/src/d8.h b/src/d8.h
index 411dfdda3e12488a775a35a29b3548a93a838efd..8c1687e4366dc9a78ac83b31100008dec786cf29 100644
--- a/src/d8.h
+++ b/src/d8.h
@@ -233,6 +233,7 @@ class ShellOptions {
      test_shell(false),
      dump_heap_constants(false),
      expected_to_throw(false),
+     mock_arraybuffer_allocator(false),
      num_isolates(1),
      isolate_sources(NULL) { }

@@ -258,6 +259,7 @@ class ShellOptions {
   bool test_shell;
   bool dump_heap_constants;
   bool expected_to_throw;
+  bool mock_arraybuffer_allocator;
   int num_isolates;
   SourceGroup* isolate_sources;
 };
Index: test/mjsunit/mjsunit.status
diff --git a/test/mjsunit/mjsunit.status b/test/mjsunit/mjsunit.status
index 5134313d5f77c289c20e9a818501a20d1d154559..d975f2b0ebe4475a4697b2b0debebaf08efcf27a 100644
--- a/test/mjsunit/mjsunit.status
+++ b/test/mjsunit/mjsunit.status
@@ -99,10 +99,6 @@
############################################################################## # Long running test that reproduces memory leak and should be run manually.
   'regress/regress-2073': [SKIP],
-
- ##############################################################################
-  # Needs to allocate 1Gb of memory.
- 'regress/regress-319722-ArrayBuffer': [PASS, ['system == windows or system == macos or arch == arm or arch == android_arm or arch == android_ia32', SKIP]],
 }],  # ALWAYS

##############################################################################
Index: test/mjsunit/regress/regress-319722-ArrayBuffer.js
diff --git a/test/mjsunit/regress/regress-319722-ArrayBuffer.js b/test/mjsunit/regress/regress-319722-ArrayBuffer.js index c8aed9e38cf7647836b68ce0428c98b7ba374d6d..1849bd2247a4750336b29e68b41bbb7d6ba2d1af 100644
--- a/test/mjsunit/regress/regress-319722-ArrayBuffer.js
+++ b/test/mjsunit/regress/regress-319722-ArrayBuffer.js
@@ -25,9 +25,20 @@
 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

-// Flags: --nostress-opt --allow-natives-syntax
+// Flags: --nostress-opt --allow-natives-syntax --mock-arraybuffer-allocator
 var maxSize = %MaxSmi() + 1;
-var ab = new ArrayBuffer(maxSize);
+var ab;
+
+// Allocate the largest ArrayBuffer we can on this architecture.
+for (k = 8; k >= 1 && ab == null; k = k/2) {
+  try {
+    ab = new ArrayBuffer(maxSize * k);
+  } catch (e) {
+    ab = null;
+  }
+}
+
+assertTrue(ab != null);

 function TestArray(constr) {
   assertThrows(function() {


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to