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

Unified Diff: test/cctest/test-alloc.cc

Issue 243087: Recommit coderanges putting code objects within a 2 GB range, reserving only ... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/spaces.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-alloc.cc
===================================================================
--- test/cctest/test-alloc.cc (revision 3016)
+++ test/cctest/test-alloc.cc (working copy)
@@ -151,3 +151,65 @@
CHECK_EQ(42, result->Int32Value());
env->Exit();
}
+
+
+// CodeRange test.
+// Tests memory management in a CodeRange by allocating and freeing blocks,
+// using a pseudorandom generator to choose block sizes geometrically
+// distributed between 2 * Page::kPageSize and 2^5 + 1 * Page::kPageSize.
+// Ensure that the freed chunks are collected and reused by allocating (in
+// total) more than the size of the CodeRange.
+
+// This pseudorandom generator does not need to be particularly good.
+// Use the lower half of the V8::Random() generator.
+unsigned int Pseudorandom() {
+ static uint32_t lo = 2345;
+ lo = 18273 * (lo & 0xFFFF) + (lo >> 16); // Provably not 0.
+ return lo & 0xFFFF;
+}
+
+
+// Plain old data class. Represents a block of allocated memory.
+class Block {
+ public:
+ Block(void* base_arg, int size_arg)
+ : base(base_arg), size(size_arg) {}
+
+ void *base;
+ int size;
+};
+
+
+TEST(CodeRange) {
+ const int code_range_size = 16*MB;
+ CodeRange::Setup(code_range_size);
+ int current_allocated = 0;
+ int total_allocated = 0;
+ List<Block> blocks(1000);
+
+ while (total_allocated < 5 * code_range_size) {
+ if (current_allocated < code_range_size / 10) {
+ // Allocate a block.
+ // Geometrically distributed sizes, greater than Page::kPageSize.
+ size_t requested = (Page::kPageSize << (Pseudorandom() % 6)) +
+ Pseudorandom() % 5000 + 1;
+ size_t allocated = 0;
+ void* base = CodeRange::AllocateRawMemory(requested, &allocated);
+ blocks.Add(Block(base, allocated));
+ current_allocated += allocated;
+ total_allocated += allocated;
+ } else {
+ // Free a block.
+ int index = Pseudorandom() % blocks.length();
+ CodeRange::FreeRawMemory(blocks[index].base, blocks[index].size);
+ current_allocated -= blocks[index].size;
+ if (index < blocks.length() - 1) {
+ blocks[index] = blocks.RemoveLast();
+ } else {
+ blocks.RemoveLast();
+ }
+ }
+ }
+
+ CodeRange::TearDown();
+}
« no previous file with comments | « src/spaces.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698