| 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 2671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2682 | 2682 |
| 2683 CHECK(CcTest::heap()->InNewSpace(o->elements())); | 2683 CHECK(CcTest::heap()->InNewSpace(o->elements())); |
| 2684 } | 2684 } |
| 2685 | 2685 |
| 2686 | 2686 |
| 2687 static int CountMapTransitions(Map* map) { | 2687 static int CountMapTransitions(Map* map) { |
| 2688 return map->transitions()->number_of_transitions(); | 2688 return map->transitions()->number_of_transitions(); |
| 2689 } | 2689 } |
| 2690 | 2690 |
| 2691 | 2691 |
| 2692 // Snippet should have a function "f" that returns an object. The object |
| 2693 // should have a memento behind it in optimized code if there hasn't |
| 2694 // been enough data to decide on pretenuring. |
| 2695 static void VerifyResultHasMemento(const char* snippet) { |
| 2696 i::ScopedVector<char> source(1024); |
| 2697 i::OS::SNPrintF( |
| 2698 source, |
| 2699 "%s" |
| 2700 "f(); gc();" |
| 2701 "f(); f();" |
| 2702 "%%OptimizeFunctionOnNextCall(f);" |
| 2703 "f();", |
| 2704 snippet); |
| 2705 |
| 2706 v8::Local<v8::Value> res = CompileRun(source.start()); |
| 2707 Handle<JSObject> o = |
| 2708 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); |
| 2709 CHECK(CcTest::heap()->InNewSpace(*o)); |
| 2710 AllocationMemento* memento = CcTest::heap()->FindAllocationMemento(*o); |
| 2711 CHECK(memento != NULL); |
| 2712 } |
| 2713 |
| 2714 |
| 2715 TEST(MementosEmittedFromOptimizedCode) { |
| 2716 i::FLAG_allow_natives_syntax = true; |
| 2717 i::FLAG_expose_gc = true; |
| 2718 CcTest::InitializeVM(); |
| 2719 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; |
| 2720 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; |
| 2721 v8::HandleScope scope(CcTest::isolate()); |
| 2722 |
| 2723 VerifyResultHasMemento("function f() { return [1, 2, 3]; };"); |
| 2724 VerifyResultHasMemento("function f() { return { foo: 'bar' }; };"); |
| 2725 |
| 2726 // String binary ops. Not currently working. |
| 2727 // TODO(mvstanton): Talk to benedikt about this. Currently we refuse to |
| 2728 // emit mementos in string add if we aren't creating a stub. We should |
| 2729 // understand the performance consequences. It seems that we'd need to |
| 2730 // 1) allow inlining of stringadd in optimized functions, 2) be able |
| 2731 // to pass an allocation site argument to HStringAdd, 3) both. |
| 2732 // VerifyResultHasMemento("function f() { return 'hi' + 'gee'; };"); |
| 2733 |
| 2734 // The tests below require us to be able to pretenure call new. |
| 2735 if (i::FLAG_pretenuring_call_new) { |
| 2736 // This allocation could be inlined. |
| 2737 VerifyResultHasMemento( |
| 2738 "function Blargh() { this.foo = 3; return this; };" |
| 2739 "function f() { return new Blargh(); };"); |
| 2740 // Object isn't inlineable, a stub is called. |
| 2741 VerifyResultHasMemento("function f() { return new Object(); };"); |
| 2742 // Array has a different path, this one will inline the constructor. |
| 2743 VerifyResultHasMemento("function f() { return new Array(); };"); |
| 2744 // This one will call a stub, passing the request to create a memento. |
| 2745 VerifyResultHasMemento("function f() { return new Array(100); };"); |
| 2746 } |
| 2747 } |
| 2748 |
| 2749 |
| 2692 // Test that map transitions are cleared and maps are collected with | 2750 // Test that map transitions are cleared and maps are collected with |
| 2693 // incremental marking as well. | 2751 // incremental marking as well. |
| 2694 TEST(Regress1465) { | 2752 TEST(Regress1465) { |
| 2695 i::FLAG_stress_compaction = false; | 2753 i::FLAG_stress_compaction = false; |
| 2696 i::FLAG_allow_natives_syntax = true; | 2754 i::FLAG_allow_natives_syntax = true; |
| 2697 i::FLAG_trace_incremental_marking = true; | 2755 i::FLAG_trace_incremental_marking = true; |
| 2698 CcTest::InitializeVM(); | 2756 CcTest::InitializeVM(); |
| 2699 v8::HandleScope scope(CcTest::isolate()); | 2757 v8::HandleScope scope(CcTest::isolate()); |
| 2700 static const int transitions_count = 256; | 2758 static const int transitions_count = 256; |
| 2701 | 2759 |
| (...skipping 1624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4326 #ifdef DEBUG | 4384 #ifdef DEBUG |
| 4327 TEST(PathTracer) { | 4385 TEST(PathTracer) { |
| 4328 CcTest::InitializeVM(); | 4386 CcTest::InitializeVM(); |
| 4329 v8::HandleScope scope(CcTest::isolate()); | 4387 v8::HandleScope scope(CcTest::isolate()); |
| 4330 | 4388 |
| 4331 v8::Local<v8::Value> result = CompileRun("'abc'"); | 4389 v8::Local<v8::Value> result = CompileRun("'abc'"); |
| 4332 Handle<Object> o = v8::Utils::OpenHandle(*result); | 4390 Handle<Object> o = v8::Utils::OpenHandle(*result); |
| 4333 CcTest::i_isolate()->heap()->TracePathToObject(*o); | 4391 CcTest::i_isolate()->heap()->TracePathToObject(*o); |
| 4334 } | 4392 } |
| 4335 #endif // DEBUG | 4393 #endif // DEBUG |
| OLD | NEW |