OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 | 92 |
93 | 93 |
94 static void CheckNumber(Isolate* isolate, double value, const char* string) { | 94 static void CheckNumber(Isolate* isolate, double value, const char* string) { |
95 Handle<Object> number = isolate->factory()->NewNumber(value); | 95 Handle<Object> number = isolate->factory()->NewNumber(value); |
96 CHECK(number->IsNumber()); | 96 CHECK(number->IsNumber()); |
97 Handle<Object> print_string = | 97 Handle<Object> print_string = |
98 Object::ToString(isolate, number).ToHandleChecked(); | 98 Object::ToString(isolate, number).ToHandleChecked(); |
99 CHECK(String::cast(*print_string)->IsUtf8EqualTo(CStrVector(string))); | 99 CHECK(String::cast(*print_string)->IsUtf8EqualTo(CStrVector(string))); |
100 } | 100 } |
101 | 101 |
| 102 void CheckEmbeddedObjectsAreEqual(Handle<Code> lhs, Handle<Code> rhs) { |
| 103 int mode_mask = RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT); |
| 104 RelocIterator lhs_it(*lhs, mode_mask); |
| 105 RelocIterator rhs_it(*rhs, mode_mask); |
| 106 while (!lhs_it.done() && !rhs_it.done()) { |
| 107 CHECK(lhs_it.rinfo()->target_object() == rhs_it.rinfo()->target_object()); |
| 108 |
| 109 lhs_it.next(); |
| 110 rhs_it.next(); |
| 111 } |
| 112 CHECK(lhs_it.done() == rhs_it.done()); |
| 113 } |
| 114 |
| 115 HEAP_TEST(TestNewSpaceRefsInCopiedCode) { |
| 116 CcTest::InitializeVM(); |
| 117 Isolate* isolate = CcTest::i_isolate(); |
| 118 Factory* factory = isolate->factory(); |
| 119 Heap* heap = isolate->heap(); |
| 120 HandleScope sc(isolate); |
| 121 |
| 122 Handle<Object> value = factory->NewNumber(1.000123); |
| 123 CHECK(heap->InNewSpace(*value)); |
| 124 |
| 125 i::byte buffer[i::Assembler::kMinimalBufferSize]; |
| 126 MacroAssembler masm(isolate, buffer, sizeof(buffer), |
| 127 v8::internal::CodeObjectRequired::kYes); |
| 128 // Add a new-space reference to the code. |
| 129 masm.Push(value); |
| 130 |
| 131 CodeDesc desc; |
| 132 masm.GetCode(&desc); |
| 133 Handle<Code> code = isolate->factory()->NewCode( |
| 134 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); |
| 135 |
| 136 Code* tmp = nullptr; |
| 137 heap->CopyCode(*code).To(&tmp); |
| 138 Handle<Code> copy(tmp); |
| 139 |
| 140 CheckEmbeddedObjectsAreEqual(code, copy); |
| 141 heap->CollectAllAvailableGarbage(); |
| 142 CheckEmbeddedObjectsAreEqual(code, copy); |
| 143 } |
102 | 144 |
103 static void CheckFindCodeObject(Isolate* isolate) { | 145 static void CheckFindCodeObject(Isolate* isolate) { |
104 // Test FindCodeObject | 146 // Test FindCodeObject |
105 #define __ assm. | 147 #define __ assm. |
106 | 148 |
107 Assembler assm(isolate, NULL, 0); | 149 Assembler assm(isolate, NULL, 0); |
108 | 150 |
109 __ nop(); // supported on all architectures | 151 __ nop(); // supported on all architectures |
110 | 152 |
111 CodeDesc desc; | 153 CodeDesc desc; |
(...skipping 6931 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7043 chunk, chunk->area_end() - kPointerSize, chunk->area_end()); | 7085 chunk, chunk->area_end() - kPointerSize, chunk->area_end()); |
7044 slots[chunk->area_end() - kPointerSize] = false; | 7086 slots[chunk->area_end() - kPointerSize] = false; |
7045 RememberedSet<OLD_TO_NEW>::Iterate(chunk, [&slots](Address addr) { | 7087 RememberedSet<OLD_TO_NEW>::Iterate(chunk, [&slots](Address addr) { |
7046 CHECK(slots[addr]); | 7088 CHECK(slots[addr]); |
7047 return KEEP_SLOT; | 7089 return KEEP_SLOT; |
7048 }); | 7090 }); |
7049 } | 7091 } |
7050 | 7092 |
7051 } // namespace internal | 7093 } // namespace internal |
7052 } // namespace v8 | 7094 } // namespace v8 |
OLD | NEW |