| 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 19527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19538 constraints.set_max_old_space_size(4); | 19538 constraints.set_max_old_space_size(4); |
| 19539 v8::SetResourceConstraints(CcTest::isolate(), &constraints); | 19539 v8::SetResourceConstraints(CcTest::isolate(), &constraints); |
| 19540 break; | 19540 break; |
| 19541 } | 19541 } |
| 19542 | 19542 |
| 19543 case SetFatalHandler: | 19543 case SetFatalHandler: |
| 19544 v8::V8::SetFatalErrorHandler(NULL); | 19544 v8::V8::SetFatalErrorHandler(NULL); |
| 19545 break; | 19545 break; |
| 19546 | 19546 |
| 19547 case SetCounterFunction: | 19547 case SetCounterFunction: |
| 19548 v8::V8::SetCounterFunction(NULL); | 19548 CcTest::isolate()->SetCounterFunction(NULL); |
| 19549 break; | 19549 break; |
| 19550 | 19550 |
| 19551 case SetCreateHistogramFunction: | 19551 case SetCreateHistogramFunction: |
| 19552 v8::V8::SetCreateHistogramFunction(NULL); | 19552 CcTest::isolate()->SetCreateHistogramFunction(NULL); |
| 19553 break; | 19553 break; |
| 19554 | 19554 |
| 19555 case SetAddHistogramSampleFunction: | 19555 case SetAddHistogramSampleFunction: |
| 19556 v8::V8::SetAddHistogramSampleFunction(NULL); | 19556 CcTest::isolate()->SetAddHistogramSampleFunction(NULL); |
| 19557 break; | 19557 break; |
| 19558 } | 19558 } |
| 19559 isolate->Exit(); | 19559 isolate->Exit(); |
| 19560 isolate->Dispose(); | 19560 isolate->Dispose(); |
| 19561 result_ = true; | 19561 result_ = true; |
| 19562 } | 19562 } |
| 19563 | 19563 |
| 19564 bool result() { return result_; } | 19564 bool result() { return result_; } |
| 19565 | 19565 |
| 19566 private: | 19566 private: |
| (...skipping 1330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 20897 } | 20897 } |
| 20898 isolate->RunMicrotasks(); | 20898 isolate->RunMicrotasks(); |
| 20899 { | 20899 { |
| 20900 Context::Scope context_scope(context); | 20900 Context::Scope context_scope(context); |
| 20901 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value()); | 20901 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value()); |
| 20902 } | 20902 } |
| 20903 isolate->SetAutorunMicrotasks(true); | 20903 isolate->SetAutorunMicrotasks(true); |
| 20904 } | 20904 } |
| 20905 | 20905 |
| 20906 | 20906 |
| 20907 #ifdef DEBUG |
| 20907 static int probes_counter = 0; | 20908 static int probes_counter = 0; |
| 20908 static int misses_counter = 0; | 20909 static int misses_counter = 0; |
| 20909 static int updates_counter = 0; | 20910 static int updates_counter = 0; |
| 20910 | 20911 |
| 20911 | 20912 |
| 20912 static int* LookupCounter(const char* name) { | 20913 static int* LookupCounter(const char* name) { |
| 20913 if (strcmp(name, "c:V8.MegamorphicStubCacheProbes") == 0) { | 20914 if (strcmp(name, "c:V8.MegamorphicStubCacheProbes") == 0) { |
| 20914 return &probes_counter; | 20915 return &probes_counter; |
| 20915 } else if (strcmp(name, "c:V8.MegamorphicStubCacheMisses") == 0) { | 20916 } else if (strcmp(name, "c:V8.MegamorphicStubCacheMisses") == 0) { |
| 20916 return &misses_counter; | 20917 return &misses_counter; |
| 20917 } else if (strcmp(name, "c:V8.MegamorphicStubCacheUpdates") == 0) { | 20918 } else if (strcmp(name, "c:V8.MegamorphicStubCacheUpdates") == 0) { |
| 20918 return &updates_counter; | 20919 return &updates_counter; |
| 20919 } | 20920 } |
| 20920 return NULL; | 20921 return NULL; |
| 20921 } | 20922 } |
| 20922 | 20923 |
| 20923 | 20924 |
| 20924 static const char* kMegamorphicTestProgram = | 20925 static const char* kMegamorphicTestProgram = |
| 20925 "function ClassA() { };" | 20926 "function ClassA() { };" |
| 20926 "function ClassB() { };" | 20927 "function ClassB() { };" |
| 20927 "ClassA.prototype.foo = function() { };" | 20928 "ClassA.prototype.foo = function() { };" |
| 20928 "ClassB.prototype.foo = function() { };" | 20929 "ClassB.prototype.foo = function() { };" |
| 20929 "function fooify(obj) { obj.foo(); };" | 20930 "function fooify(obj) { obj.foo(); };" |
| 20930 "var a = new ClassA();" | 20931 "var a = new ClassA();" |
| 20931 "var b = new ClassB();" | 20932 "var b = new ClassB();" |
| 20932 "for (var i = 0; i < 10000; i++) {" | 20933 "for (var i = 0; i < 10000; i++) {" |
| 20933 " fooify(a);" | 20934 " fooify(a);" |
| 20934 " fooify(b);" | 20935 " fooify(b);" |
| 20935 "}"; | 20936 "}"; |
| 20937 #endif |
| 20936 | 20938 |
| 20937 | 20939 |
| 20938 static void StubCacheHelper(bool primary) { | 20940 static void StubCacheHelper(bool primary) { |
| 20939 V8::SetCounterFunction(LookupCounter); | |
| 20940 USE(kMegamorphicTestProgram); | |
| 20941 #ifdef DEBUG | 20941 #ifdef DEBUG |
| 20942 i::FLAG_native_code_counters = true; | 20942 i::FLAG_native_code_counters = true; |
| 20943 if (primary) { | 20943 if (primary) { |
| 20944 i::FLAG_test_primary_stub_cache = true; | 20944 i::FLAG_test_primary_stub_cache = true; |
| 20945 } else { | 20945 } else { |
| 20946 i::FLAG_test_secondary_stub_cache = true; | 20946 i::FLAG_test_secondary_stub_cache = true; |
| 20947 } | 20947 } |
| 20948 i::FLAG_crankshaft = false; | 20948 i::FLAG_crankshaft = false; |
| 20949 LocalContext env; | 20949 LocalContext env; |
| 20950 env->GetIsolate()->SetCounterFunction(LookupCounter); |
| 20950 v8::HandleScope scope(env->GetIsolate()); | 20951 v8::HandleScope scope(env->GetIsolate()); |
| 20951 int initial_probes = probes_counter; | 20952 int initial_probes = probes_counter; |
| 20952 int initial_misses = misses_counter; | 20953 int initial_misses = misses_counter; |
| 20953 int initial_updates = updates_counter; | 20954 int initial_updates = updates_counter; |
| 20954 CompileRun(kMegamorphicTestProgram); | 20955 CompileRun(kMegamorphicTestProgram); |
| 20955 int probes = probes_counter - initial_probes; | 20956 int probes = probes_counter - initial_probes; |
| 20956 int misses = misses_counter - initial_misses; | 20957 int misses = misses_counter - initial_misses; |
| 20957 int updates = updates_counter - initial_updates; | 20958 int updates = updates_counter - initial_updates; |
| 20958 CHECK_LT(updates, 10); | 20959 CHECK_LT(updates, 10); |
| 20959 CHECK_LT(misses, 10); | 20960 CHECK_LT(misses, 10); |
| 20960 // TODO(verwaest): Update this test to overflow the degree of polymorphism | 20961 // TODO(verwaest): Update this test to overflow the degree of polymorphism |
| 20961 // before megamorphism. The number of probes will only work once we teach the | 20962 // before megamorphism. The number of probes will only work once we teach the |
| 20962 // serializer to embed references to counters in the stubs, given that the | 20963 // serializer to embed references to counters in the stubs, given that the |
| 20963 // megamorphic_stub_cache_probes is updated in a snapshot-generated stub. | 20964 // megamorphic_stub_cache_probes is updated in a snapshot-generated stub. |
| 20964 CHECK_GE(probes, 0); | 20965 CHECK_GE(probes, 0); |
| 20965 #endif | 20966 #endif |
| 20966 } | 20967 } |
| 20967 | 20968 |
| 20968 | 20969 |
| 20969 TEST(SecondaryStubCache) { | 20970 TEST(SecondaryStubCache) { |
| 20970 StubCacheHelper(true); | 20971 StubCacheHelper(true); |
| 20971 } | 20972 } |
| 20972 | 20973 |
| 20973 | 20974 |
| 20974 TEST(PrimaryStubCache) { | 20975 TEST(PrimaryStubCache) { |
| 20975 StubCacheHelper(false); | 20976 StubCacheHelper(false); |
| 20976 } | 20977 } |
| 20977 | 20978 |
| 20978 | 20979 |
| 20980 #ifdef DEBUG |
| 20979 static int cow_arrays_created_runtime = 0; | 20981 static int cow_arrays_created_runtime = 0; |
| 20980 | 20982 |
| 20981 | 20983 |
| 20982 static int* LookupCounterCOWArrays(const char* name) { | 20984 static int* LookupCounterCOWArrays(const char* name) { |
| 20983 if (strcmp(name, "c:V8.COWArraysCreatedRuntime") == 0) { | 20985 if (strcmp(name, "c:V8.COWArraysCreatedRuntime") == 0) { |
| 20984 return &cow_arrays_created_runtime; | 20986 return &cow_arrays_created_runtime; |
| 20985 } | 20987 } |
| 20986 return NULL; | 20988 return NULL; |
| 20987 } | 20989 } |
| 20990 #endif |
| 20988 | 20991 |
| 20989 | 20992 |
| 20990 TEST(CheckCOWArraysCreatedRuntimeCounter) { | 20993 TEST(CheckCOWArraysCreatedRuntimeCounter) { |
| 20991 V8::SetCounterFunction(LookupCounterCOWArrays); | |
| 20992 #ifdef DEBUG | 20994 #ifdef DEBUG |
| 20993 i::FLAG_native_code_counters = true; | 20995 i::FLAG_native_code_counters = true; |
| 20994 LocalContext env; | 20996 LocalContext env; |
| 20997 env->GetIsolate()->SetCounterFunction(LookupCounterCOWArrays); |
| 20995 v8::HandleScope scope(env->GetIsolate()); | 20998 v8::HandleScope scope(env->GetIsolate()); |
| 20996 int initial_cow_arrays = cow_arrays_created_runtime; | 20999 int initial_cow_arrays = cow_arrays_created_runtime; |
| 20997 CompileRun("var o = [1, 2, 3];"); | 21000 CompileRun("var o = [1, 2, 3];"); |
| 20998 CHECK_EQ(1, cow_arrays_created_runtime - initial_cow_arrays); | 21001 CHECK_EQ(1, cow_arrays_created_runtime - initial_cow_arrays); |
| 20999 CompileRun("var o = {foo: [4, 5, 6], bar: [3, 0]};"); | 21002 CompileRun("var o = {foo: [4, 5, 6], bar: [3, 0]};"); |
| 21000 CHECK_EQ(3, cow_arrays_created_runtime - initial_cow_arrays); | 21003 CHECK_EQ(3, cow_arrays_created_runtime - initial_cow_arrays); |
| 21001 CompileRun("var o = {foo: [1, 2, 3, [4, 5, 6]], bar: 'hi'};"); | 21004 CompileRun("var o = {foo: [1, 2, 3, [4, 5, 6]], bar: 'hi'};"); |
| 21002 CHECK_EQ(4, cow_arrays_created_runtime - initial_cow_arrays); | 21005 CHECK_EQ(4, cow_arrays_created_runtime - initial_cow_arrays); |
| 21003 #endif | 21006 #endif |
| 21004 } | 21007 } |
| (...skipping 1794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 22799 call_eval_context = v8::Context::New(isolate); | 22802 call_eval_context = v8::Context::New(isolate); |
| 22800 v8::Context::Scope scope(call_eval_context); | 22803 v8::Context::Scope scope(call_eval_context); |
| 22801 call_eval_bound_function = | 22804 call_eval_bound_function = |
| 22802 Local<Function>::Cast(CompileRun("eval.bind(this, '1')")); | 22805 Local<Function>::Cast(CompileRun("eval.bind(this, '1')")); |
| 22803 } | 22806 } |
| 22804 env->Global()->Set(v8_str("CallEval"), | 22807 env->Global()->Set(v8_str("CallEval"), |
| 22805 v8::FunctionTemplate::New(isolate, CallEval)->GetFunction()); | 22808 v8::FunctionTemplate::New(isolate, CallEval)->GetFunction()); |
| 22806 Local<Value> result = CompileRun("CallEval();"); | 22809 Local<Value> result = CompileRun("CallEval();"); |
| 22807 CHECK_EQ(result, v8::Integer::New(isolate, 1)); | 22810 CHECK_EQ(result, v8::Integer::New(isolate, 1)); |
| 22808 } | 22811 } |
| OLD | NEW |