Chromium Code Reviews| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 AllocationMemento* memento = | 50 AllocationMemento* memento = |
| 51 reinterpret_cast<AllocationMemento*>(new_space->top() + kHeapObjectTag); | 51 reinterpret_cast<AllocationMemento*>(new_space->top() + kHeapObjectTag); |
| 52 memento->set_map_no_write_barrier(heap->allocation_memento_map()); | 52 memento->set_map_no_write_barrier(heap->allocation_memento_map()); |
| 53 memento->set_allocation_site( | 53 memento->set_allocation_site( |
| 54 reinterpret_cast<AllocationSite*>(kHeapObjectTag), SKIP_WRITE_BARRIER); | 54 reinterpret_cast<AllocationSite*>(kHeapObjectTag), SKIP_WRITE_BARRIER); |
| 55 | 55 |
| 56 // Call GC to see if we can handle a poisonous memento right after the | 56 // Call GC to see if we can handle a poisonous memento right after the |
| 57 // current new space top pointer. | 57 // current new space top pointer. |
| 58 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 58 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
| 59 } | 59 } |
| 60 | |
| 61 | |
| 62 TEST(PretenuringCallNew) { | |
| 63 CcTest::InitializeVM(); | |
| 64 if (!i::FLAG_allocation_site_pretenuring) return; | |
| 65 if (!i::FLAG_pretenuring_call_new) return; | |
| 66 | |
| 67 v8::HandleScope scope(CcTest::isolate()); | |
| 68 Isolate* isolate = CcTest::i_isolate(); | |
| 69 Heap* heap = isolate->heap(); | |
| 70 | |
| 71 // We need to create several instances to get past the slack-tracking | |
| 72 // phase, where mementos aren't emitted. | |
| 73 int call_count = 10; | |
| 74 CHECK_GE(call_count, SharedFunctionInfo::kGenerousAllocationCount); | |
| 75 i::ScopedVector<char> test_buf(1024); | |
| 76 const char* program = | |
| 77 "function f() {" | |
| 78 " this.a = 3;" | |
| 79 " this.b = {};" | |
| 80 " return this;" | |
| 81 "};" | |
| 82 "var a;" | |
| 83 "for(var i = 0; i < %d; i++) {" | |
| 84 " a = new f();" | |
| 85 "}" | |
| 86 "a;"; | |
|
Hannes Payer (out of office)
2014/02/18 16:24:26
a == return a; ?
mvstanton
2014/02/19 08:40:26
Done.
| |
| 87 i::OS::SNPrintF(test_buf, program, call_count); | |
| 88 v8::Local<v8::Value> res = CompileRun(test_buf.start()); | |
| 89 Handle<JSObject> o = | |
| 90 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); | |
| 91 | |
| 92 // The object of class f should have a memento secreted behind it. | |
| 93 Address memento_address = o->address() + o->map()->instance_size(); | |
| 94 AllocationMemento* memento = | |
| 95 reinterpret_cast<AllocationMemento*>(memento_address + kHeapObjectTag); | |
| 96 CHECK_EQ(memento->map(), heap->allocation_memento_map()); | |
| 97 | |
| 98 // Furthermore, how many mementos did we create? The count should match | |
| 99 // call_count - SharedFunctionInfo::kGenerousAllocationCount. | |
| 100 AllocationSite* site = memento->GetAllocationSite(); | |
| 101 CHECK_EQ(call_count - SharedFunctionInfo::kGenerousAllocationCount, | |
| 102 site->pretenure_create_count()->value()); | |
| 103 } | |
| OLD | NEW |