OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 TEST(BadMementoAfterTopForceScavenge) { | 88 TEST(BadMementoAfterTopForceScavenge) { |
89 CcTest::InitializeVM(); | 89 CcTest::InitializeVM(); |
90 if (!i::FLAG_allocation_site_pretenuring) return; | 90 if (!i::FLAG_allocation_site_pretenuring) return; |
91 v8::HandleScope scope(CcTest::isolate()); | 91 v8::HandleScope scope(CcTest::isolate()); |
92 | 92 |
93 SetUpNewSpaceWithPoisonedMementoAtTop(); | 93 SetUpNewSpaceWithPoisonedMementoAtTop(); |
94 | 94 |
95 // Force GC to test the poisoned memento handling | 95 // Force GC to test the poisoned memento handling |
96 CcTest::i_isolate()->heap()->CollectGarbage(i::NEW_SPACE); | 96 CcTest::i_isolate()->heap()->CollectGarbage(i::NEW_SPACE); |
97 } | 97 } |
98 | |
99 | |
100 TEST(PretenuringCallNew) { | |
101 CcTest::InitializeVM(); | |
102 if (!i::FLAG_allocation_site_pretenuring) return; | |
103 if (!i::FLAG_pretenuring_call_new) return; | |
104 if (i::FLAG_always_opt) return; | |
105 | |
106 v8::HandleScope scope(CcTest::isolate()); | |
107 Isolate* isolate = CcTest::i_isolate(); | |
108 Heap* heap = isolate->heap(); | |
109 | |
110 int call_count = 10; | |
111 i::ScopedVector<char> test_buf(1024); | |
112 const char* program = | |
113 "function f() {" | |
114 " this.a = 3;" | |
115 " this.b = {};" | |
116 " return this;" | |
117 "};" | |
118 "var a;" | |
119 "for(var i = 0; i < %d; i++) {" | |
120 " a = new f();" | |
121 "}" | |
122 "a;"; | |
123 i::SNPrintF(test_buf, program, call_count); | |
124 v8::Local<v8::Value> res = CompileRun(test_buf.start()); | |
125 Handle<JSObject> o = | |
126 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); | |
127 | |
128 // The object of class f should have a memento secreted behind it. | |
129 Address memento_address = o->address() + o->map()->instance_size(); | |
130 AllocationMemento* memento = | |
131 reinterpret_cast<AllocationMemento*>(memento_address + kHeapObjectTag); | |
132 CHECK_EQ(memento->map(), heap->allocation_memento_map()); | |
133 | |
134 // Furthermore, how many mementos did we create? The count should match | |
135 // call_count. Note, that mementos are allocated during the inobject slack | |
136 // tracking phase. | |
137 AllocationSite* site = memento->GetAllocationSite(); | |
138 CHECK_EQ(call_count, site->pretenure_create_count()->value()); | |
139 } | |
OLD | NEW |