Chromium Code Reviews| Index: test/cctest/heap/test-heap.cc |
| diff --git a/test/cctest/heap/test-heap.cc b/test/cctest/heap/test-heap.cc |
| index f76b6ba7a4cde08c7c3a331ebb477b52f2222d9c..18e9df8139cce0685fce219823b9fca923c1c345 100644 |
| --- a/test/cctest/heap/test-heap.cc |
| +++ b/test/cctest/heap/test-heap.cc |
| @@ -99,6 +99,51 @@ static void CheckNumber(Isolate* isolate, double value, const char* string) { |
| CHECK(String::cast(*print_string)->IsUtf8EqualTo(CStrVector(string))); |
| } |
| +AllocationResult TestCopyCode(Heap* heap, Code* code) { |
| + return heap->CopyCode(code); |
| +} |
| + |
| +void CheckEmbeddedObjectsAreEqual(Handle<Code> lhs, Handle<Code> rhs) { |
| + int mode_mask = RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT); |
| + RelocIterator lhs_it(*lhs, mode_mask); |
| + RelocIterator rhs_it(*rhs, mode_mask); |
| + while (!lhs_it.done() && !rhs_it.done()) { |
| + CHECK(lhs_it.rinfo()->target_object() == rhs_it.rinfo()->target_object()); |
| + |
| + lhs_it.next(); |
| + rhs_it.next(); |
| + } |
| + CHECK(lhs_it.done() == rhs_it.done()); |
| +} |
| + |
| +TEST(TestNewSpaceRefsInCopiedCode) { |
| + CcTest::InitializeVM(); |
| + Isolate* isolate = CcTest::i_isolate(); |
| + Factory* factory = isolate->factory(); |
| + Heap* heap = isolate->heap(); |
| + HandleScope sc(isolate); |
| + |
| + Handle<Object> value = factory->NewNumber(1.000123); |
|
Michael Lippautz
2016/08/02 19:07:58
CHECK for object being in new space
ahaas
2016/08/03 08:47:42
Done.
|
| + |
| + i::byte buffer[i::Assembler::kMinimalBufferSize]; |
| + MacroAssembler masm(isolate, buffer, sizeof(buffer), |
| + v8::internal::CodeObjectRequired::kYes); |
| + // Add a new-space reference to the code. |
| + masm.Push(value); |
| + |
| + CodeDesc desc; |
| + masm.GetCode(&desc); |
| + Handle<Code> code = isolate->factory()->NewCode( |
|
Michael Lippautz
2016/08/02 19:07:57
Cool stuff!
|
| + desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); |
| + |
| + Code* tmp; |
| + TestCopyCode(heap, *code).To(&tmp); |
| + Handle<Code> copy(tmp); |
| + |
| + CheckEmbeddedObjectsAreEqual(code, copy); |
| + heap->CollectAllAvailableGarbage(); |
| + CheckEmbeddedObjectsAreEqual(code, copy); |
| +} |
| static void CheckFindCodeObject(Isolate* isolate) { |
| // Test FindCodeObject |