Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(759)

Side by Side Diff: test/cctest/test-api.cc

Issue 573003: ia32: Fuse map and type checks in call ICs for API functions. (Closed)
Patch Set: Rewrote a comment. Created 10 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« src/stub-cache.h ('K') | « src/x64/stub-cache-x64.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2007-2009 the V8 project authors. All rights reserved. 1 // Copyright 2007-2009 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 5775 matching lines...) Expand 10 before | Expand all | Expand 10 after
5786 " for (var i = 0; i < 10; i++) {" 5786 " for (var i = 0; i < 10; i++) {"
5787 " result += o.parseFloat('239');" 5787 " result += o.parseFloat('239');"
5788 " }" 5788 " }"
5789 " result" 5789 " result"
5790 "} catch(e) {" 5790 "} catch(e) {"
5791 " e" 5791 " e"
5792 "};"); 5792 "};");
5793 CHECK_EQ(239 * 10, value->Int32Value()); 5793 CHECK_EQ(239 * 10, value->Int32Value());
5794 } 5794 }
5795 5795
5796 static v8::Handle<Value> InterceptorCallICFastApi(Local<String> name,
antonm 2010/02/08 12:07:38 I know that's boring, but apparently you didn't co
Vitaly Repeshko 2010/02/09 16:15:24 Thanks, added a test. Yeah, it's boring...
5797 const AccessorInfo& info) {
5798 ApiTestFuzzer::Fuzz();
5799 int* call_count = reinterpret_cast<int*>(v8::External::Unwrap(info.Data()));
5800 ++(*call_count);
5801 if ((*call_count) % 200 == 0) {
5802 v8::internal::Heap::CollectAllGarbage(true);
5803 }
5804 return v8::Handle<Value>();
5805 }
5806
5807 static v8::Handle<Value> FastApiCallback_TrivialSignature(
5808 const v8::Arguments& args) {
5809 ApiTestFuzzer::Fuzz();
5810 CHECK_EQ(args.This(), args.Holder());
5811 CHECK(args.Data()->Equals(v8_str("method_data")));
5812 return v8::Integer::New(args[0]->Int32Value() + 1);
5813 }
5814
5815 static v8::Handle<Value> FastApiCallback_SimpleSignature(
5816 const v8::Arguments& args) {
5817 ApiTestFuzzer::Fuzz();
5818 CHECK_EQ(args.This()->GetPrototype(), args.Holder());
5819 CHECK(args.Data()->Equals(v8_str("method_data")));
5820 // Note, we're using HasRealNamedProperty instead of Has to avoid
5821 // invoking the interceptor again.
5822 CHECK(args.Holder()->HasRealNamedProperty(v8_str("foo")));
5823 return v8::Integer::New(args[0]->Int32Value() + 1);
5824 }
5825
5826 static void GenerateSomeGarbage() {
5827 CompileRun(
5828 "var garbage;"
5829 "for (var i = 0; i < 1000; i++) {"
5830 " garbage = [1/i, \"garbage\" + i, garbage, {foo: garbage}];"
5831 "}"
5832 "garbage = undefined;");
5833 }
5834
5835 THREADED_TEST(InterceptorCallICFastApi_TrivialSignature) {
5836 int interceptor_call_count = 0;
5837 v8::HandleScope scope;
5838 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
5839 v8::Handle<v8::FunctionTemplate> method_templ =
5840 v8::FunctionTemplate::New(FastApiCallback_TrivialSignature,
5841 v8_str("method_data"),
5842 v8::Handle<v8::Signature>());
5843 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
5844 proto_templ->Set(v8_str("method"), method_templ);
5845 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
5846 templ->SetNamedPropertyHandler(InterceptorCallICFastApi,
5847 NULL, NULL, NULL, NULL,
5848 v8::External::Wrap(&interceptor_call_count));
5849 LocalContext context;
5850 v8::Handle<v8::Function> fun = fun_templ->GetFunction();
5851 GenerateSomeGarbage();
Mads Ager (chromium) 2010/02/08 08:56:58 Could you document why you generate some extra gar
Vitaly Repeshko 2010/02/09 16:15:24 Done.
5852 context->Global()->Set(v8_str("o"), fun->NewInstance());
5853 v8::Handle<Value> value = CompileRun(
5854 "var result = 0;"
5855 "for (var i = 0; i < 1000; i++) {"
Mads Ager (chromium) 2010/02/08 08:56:58 I think we use 1000 in other places as well, but d
Vitaly Repeshko 2010/02/09 16:15:24 Sure we don't need that many. Reduced iterations b
5856 " result = o.method(41);"
5857 "}");
5858 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value());
antonm 2010/02/08 12:07:38 if you add result as a last line of script, you co
Vitaly Repeshko 2010/02/09 16:15:24 Yup, but I prefer a slightly more uniform way here
5859 CHECK_EQ(1000, interceptor_call_count);
5860 }
5861
5862 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature) {
5863 int interceptor_call_count = 0;
5864 v8::HandleScope scope;
5865 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
5866 v8::Handle<v8::FunctionTemplate> method_templ =
5867 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
5868 v8_str("method_data"),
5869 v8::Signature::New(fun_templ));
5870 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
5871 proto_templ->Set(v8_str("method"), method_templ);
5872 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
5873 templ->SetNamedPropertyHandler(InterceptorCallICFastApi,
5874 NULL, NULL, NULL, NULL,
5875 v8::External::Wrap(&interceptor_call_count));
5876 LocalContext context;
5877 v8::Handle<v8::Function> fun = fun_templ->GetFunction();
5878 GenerateSomeGarbage();
5879 context->Global()->Set(v8_str("o"), fun->NewInstance());
5880 v8::Handle<Value> value = CompileRun(
5881 "o.foo = 17;"
5882 "var receiver = {};"
5883 "receiver.__proto__ = o;"
5884 "var result = 0;"
5885 "for (var i = 0; i < 1000; i++) {"
5886 " result = receiver.method(41);"
5887 "}");
5888 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value());
5889 CHECK_EQ(1000, interceptor_call_count);
5890 }
5891
5892 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss) {
5893 int interceptor_call_count = 0;
5894 v8::HandleScope scope;
5895 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
5896 v8::Handle<v8::FunctionTemplate> method_templ =
5897 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
5898 v8_str("method_data"),
5899 v8::Signature::New(fun_templ));
5900 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
5901 proto_templ->Set(v8_str("method"), method_templ);
5902 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
5903 templ->SetNamedPropertyHandler(InterceptorCallICFastApi,
5904 NULL, NULL, NULL, NULL,
5905 v8::External::Wrap(&interceptor_call_count));
5906 LocalContext context;
5907 v8::Handle<v8::Function> fun = fun_templ->GetFunction();
5908 GenerateSomeGarbage();
5909 context->Global()->Set(v8_str("o"), fun->NewInstance());
5910 v8::Handle<Value> value = CompileRun(
5911 "o.foo = 17;"
5912 "var receiver = {};"
5913 "receiver.__proto__ = o;"
5914 "var result = 0;"
5915 "var saved_result = 0;"
5916 "for (var i = 0; i < 1000; i++) {"
5917 " result = receiver.method(41);"
5918 " if (i == 500) {"
5919 " saved_result = result;"
5920 " receiver = {method: function(x) { return x - 1 }};"
5921 " }"
5922 "}");
5923 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value());
5924 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
5925 CHECK(interceptor_call_count >= 500);
5926 }
5927
5928 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_TypeError) {
5929 int interceptor_call_count = 0;
5930 v8::HandleScope scope;
5931 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
5932 v8::Handle<v8::FunctionTemplate> method_templ =
5933 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
5934 v8_str("method_data"),
5935 v8::Signature::New(fun_templ));
5936 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
5937 proto_templ->Set(v8_str("method"), method_templ);
5938 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
5939 templ->SetNamedPropertyHandler(InterceptorCallICFastApi,
5940 NULL, NULL, NULL, NULL,
5941 v8::External::Wrap(&interceptor_call_count));
5942 LocalContext context;
5943 v8::Handle<v8::Function> fun = fun_templ->GetFunction();
5944 GenerateSomeGarbage();
5945 context->Global()->Set(v8_str("o"), fun->NewInstance());
5946 v8::TryCatch try_catch;
5947 v8::Handle<Value> value = CompileRun(
5948 "o.foo = 17;"
5949 "var receiver = {};"
5950 "receiver.__proto__ = o;"
5951 "var result = 0;"
5952 "var saved_result = 0;"
5953 "for (var i = 0; i < 1000; i++) {"
5954 " result = receiver.method(41);"
5955 " if (i == 500) {"
5956 " saved_result = result;"
5957 " receiver = {method: receiver.method};"
5958 " }"
5959 "}");
5960 CHECK(try_catch.HasCaught());
5961 CHECK_EQ(v8_str("TypeError: Illegal invocation"),
5962 try_catch.Exception()->ToString());
5963 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
5964 CHECK(interceptor_call_count >= 500);
5965 }
5966
5967 THREADED_TEST(CallICFastApi_TrivialSignature) {
5968 v8::HandleScope scope;
5969 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
5970 v8::Handle<v8::FunctionTemplate> method_templ =
5971 v8::FunctionTemplate::New(FastApiCallback_TrivialSignature,
5972 v8_str("method_data"),
5973 v8::Handle<v8::Signature>());
5974 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
5975 proto_templ->Set(v8_str("method"), method_templ);
5976 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
5977 LocalContext context;
5978 v8::Handle<v8::Function> fun = fun_templ->GetFunction();
5979 GenerateSomeGarbage();
5980 context->Global()->Set(v8_str("o"), fun->NewInstance());
5981 v8::Handle<Value> value = CompileRun(
5982 "var result = 0;"
5983 "for (var i = 0; i < 1000; i++) {"
5984 " result = o.method(41);"
5985 "}");
5986
5987 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value());
5988 }
5989
5990 THREADED_TEST(CallICFastApi_SimpleSignature) {
5991 v8::HandleScope scope;
5992 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
5993 v8::Handle<v8::FunctionTemplate> method_templ =
5994 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
5995 v8_str("method_data"),
5996 v8::Signature::New(fun_templ));
5997 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
5998 proto_templ->Set(v8_str("method"), method_templ);
5999 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
6000 LocalContext context;
6001 v8::Handle<v8::Function> fun = fun_templ->GetFunction();
6002 GenerateSomeGarbage();
6003 context->Global()->Set(v8_str("o"), fun->NewInstance());
6004 v8::Handle<Value> value = CompileRun(
6005 "o.foo = 17;"
6006 "var receiver = {};"
6007 "receiver.__proto__ = o;"
6008 "var result = 0;"
6009 "for (var i = 0; i < 1000; i++) {"
6010 " result = receiver.method(41);"
6011 "}");
6012
6013 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value());
6014 }
6015
6016 THREADED_TEST(CallICFastApi_SimpleSignature_Miss) {
6017 v8::HandleScope scope;
6018 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
6019 v8::Handle<v8::FunctionTemplate> method_templ =
6020 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
6021 v8_str("method_data"),
6022 v8::Signature::New(fun_templ));
6023 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
6024 proto_templ->Set(v8_str("method"), method_templ);
6025 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
6026 LocalContext context;
6027 v8::Handle<v8::Function> fun = fun_templ->GetFunction();
6028 GenerateSomeGarbage();
6029 context->Global()->Set(v8_str("o"), fun->NewInstance());
6030 v8::Handle<Value> value = CompileRun(
6031 "o.foo = 17;"
6032 "var receiver = {};"
6033 "receiver.__proto__ = o;"
6034 "var result = 0;"
6035 "var saved_result = 0;"
6036 "for (var i = 0; i < 1000; i++) {"
6037 " result = receiver.method(41);"
6038 " if (i == 500) {"
6039 " saved_result = result;"
6040 " receiver = {method: function(x) { return x - 1 }};"
6041 " }"
6042 "}");
6043 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value());
6044 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
6045 }
6046
5796 6047
5797 static int interceptor_call_count = 0; 6048 static int interceptor_call_count = 0;
5798 6049
5799 static v8::Handle<Value> InterceptorICRefErrorGetter(Local<String> name, 6050 static v8::Handle<Value> InterceptorICRefErrorGetter(Local<String> name,
5800 const AccessorInfo& info) { 6051 const AccessorInfo& info) {
5801 ApiTestFuzzer::Fuzz(); 6052 ApiTestFuzzer::Fuzz();
5802 if (v8_str("x")->Equals(name) && interceptor_call_count++ < 20) { 6053 if (v8_str("x")->Equals(name) && interceptor_call_count++ < 20) {
5803 return call_ic_function2; 6054 return call_ic_function2;
5804 } 6055 }
5805 return v8::Handle<Value>(); 6056 return v8::Handle<Value>();
(...skipping 3016 matching lines...) Expand 10 before | Expand all | Expand 10 after
8822 CompileRun(source_exception); 9073 CompileRun(source_exception);
8823 other_context->Exit(); 9074 other_context->Exit();
8824 v8::internal::Heap::CollectAllGarbage(false); 9075 v8::internal::Heap::CollectAllGarbage(false);
8825 if (GetGlobalObjectsCount() == 1) break; 9076 if (GetGlobalObjectsCount() == 1) break;
8826 } 9077 }
8827 CHECK_GE(2, gc_count); 9078 CHECK_GE(2, gc_count);
8828 CHECK_EQ(1, GetGlobalObjectsCount()); 9079 CHECK_EQ(1, GetGlobalObjectsCount());
8829 9080
8830 other_context.Dispose(); 9081 other_context.Dispose();
8831 } 9082 }
OLDNEW
« src/stub-cache.h ('K') | « src/x64/stub-cache-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698