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 13 matching lines...) Expand all Loading... |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #include "v8.h" | 28 #include "v8.h" |
29 | 29 |
30 #include "api.h" | 30 #include "api.h" |
31 #include "arguments.h" | 31 #include "arguments.h" |
32 #include "ast.h" | 32 #include "ast.h" |
33 #include "code-stubs.h" | 33 #include "code-stubs.h" |
| 34 #include "cpu-profiler.h" |
34 #include "gdb-jit.h" | 35 #include "gdb-jit.h" |
35 #include "ic-inl.h" | 36 #include "ic-inl.h" |
36 #include "stub-cache.h" | 37 #include "stub-cache.h" |
37 #include "vm-state-inl.h" | 38 #include "vm-state-inl.h" |
38 | 39 |
39 namespace v8 { | 40 namespace v8 { |
40 namespace internal { | 41 namespace internal { |
41 | 42 |
42 // ----------------------------------------------------------------------- | 43 // ----------------------------------------------------------------------- |
43 // StubCache implementation. | 44 // StubCache implementation. |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 Handle<Code> StubCache::ComputeStoreNormal(StrictModeFlag strict_mode) { | 492 Handle<Code> StubCache::ComputeStoreNormal(StrictModeFlag strict_mode) { |
492 return (strict_mode == kStrictMode) | 493 return (strict_mode == kStrictMode) |
493 ? isolate_->builtins()->Builtins::StoreIC_Normal_Strict() | 494 ? isolate_->builtins()->Builtins::StoreIC_Normal_Strict() |
494 : isolate_->builtins()->Builtins::StoreIC_Normal(); | 495 : isolate_->builtins()->Builtins::StoreIC_Normal(); |
495 } | 496 } |
496 | 497 |
497 | 498 |
498 Handle<Code> StubCache::ComputeStoreGlobal(Handle<Name> name, | 499 Handle<Code> StubCache::ComputeStoreGlobal(Handle<Name> name, |
499 Handle<GlobalObject> receiver, | 500 Handle<GlobalObject> receiver, |
500 Handle<PropertyCell> cell, | 501 Handle<PropertyCell> cell, |
| 502 Handle<Object> value, |
501 StrictModeFlag strict_mode) { | 503 StrictModeFlag strict_mode) { |
502 Handle<Code> stub = FindIC( | 504 Isolate* isolate = cell->GetIsolate(); |
| 505 Handle<Type> union_type(PropertyCell::UpdateType(cell, value), isolate); |
| 506 bool is_constant = union_type->IsConstant(); |
| 507 StoreGlobalStub stub(strict_mode, is_constant); |
| 508 |
| 509 Handle<Code> code = FindIC( |
503 name, Handle<JSObject>::cast(receiver), | 510 name, Handle<JSObject>::cast(receiver), |
504 Code::STORE_IC, Code::NORMAL, strict_mode); | 511 Code::STORE_IC, Code::NORMAL, stub.GetExtraICState()); |
505 if (!stub.is_null()) return stub; | 512 if (!code.is_null()) return code; |
506 | 513 |
507 StoreStubCompiler compiler(isolate_, strict_mode); | 514 if (is_constant) return stub.GetCode(isolate_); |
508 Handle<Code> code = compiler.CompileStoreGlobal(receiver, cell, name); | 515 |
| 516 // Replace the placeholder cell and global object map with the actual global |
| 517 // cell and receiver map. |
| 518 Handle<Map> cell_map(isolate_->heap()->global_property_cell_map()); |
| 519 Handle<Map> meta_map(isolate_->heap()->meta_map()); |
| 520 Handle<Object> receiver_map(receiver->map(), isolate_); |
| 521 code = stub.GetCodeCopyFromTemplate(isolate_); |
| 522 code->ReplaceNthObject(1, *meta_map, *receiver_map); |
| 523 code->ReplaceNthObject(1, *cell_map, *cell); |
509 JSObject::UpdateMapCodeCache(receiver, name, code); | 524 JSObject::UpdateMapCodeCache(receiver, name, code); |
| 525 |
510 return code; | 526 return code; |
511 } | 527 } |
512 | 528 |
513 | 529 |
514 Handle<Code> StubCache::ComputeStoreCallback( | 530 Handle<Code> StubCache::ComputeStoreCallback( |
515 Handle<Name> name, | 531 Handle<Name> name, |
516 Handle<JSObject> receiver, | 532 Handle<JSObject> receiver, |
517 Handle<JSObject> holder, | 533 Handle<JSObject> holder, |
518 Handle<ExecutableAccessorInfo> callback, | 534 Handle<ExecutableAccessorInfo> callback, |
519 StrictModeFlag strict_mode) { | 535 StrictModeFlag strict_mode) { |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
914 | 930 |
915 Handle<Code> StubCache::ComputeCompareNil(Handle<Map> receiver_map, | 931 Handle<Code> StubCache::ComputeCompareNil(Handle<Map> receiver_map, |
916 CompareNilICStub& stub) { | 932 CompareNilICStub& stub) { |
917 Handle<String> name(isolate_->heap()->empty_string()); | 933 Handle<String> name(isolate_->heap()->empty_string()); |
918 if (!receiver_map->is_shared()) { | 934 if (!receiver_map->is_shared()) { |
919 Handle<Code> cached_ic = FindIC(name, receiver_map, Code::COMPARE_NIL_IC, | 935 Handle<Code> cached_ic = FindIC(name, receiver_map, Code::COMPARE_NIL_IC, |
920 Code::NORMAL, stub.GetExtraICState()); | 936 Code::NORMAL, stub.GetExtraICState()); |
921 if (!cached_ic.is_null()) return cached_ic; | 937 if (!cached_ic.is_null()) return cached_ic; |
922 } | 938 } |
923 | 939 |
924 Handle<Code> ic = stub.GetCode(isolate_); | 940 Handle<Code> ic = stub.GetCodeCopyFromTemplate(isolate_); |
925 | 941 ic->ReplaceNthObject(1, isolate_->heap()->meta_map(), *receiver_map); |
926 // For monomorphic maps, use the code as a template, copying and replacing | |
927 // the monomorphic map that checks the object's type. | |
928 ic = isolate_->factory()->CopyCode(ic); | |
929 ic->ReplaceFirstMap(*receiver_map); | |
930 | 942 |
931 if (!receiver_map->is_shared()) { | 943 if (!receiver_map->is_shared()) { |
932 Map::UpdateCodeCache(receiver_map, name, ic); | 944 Map::UpdateCodeCache(receiver_map, name, ic); |
933 } | 945 } |
934 | 946 |
935 return ic; | 947 return ic; |
936 } | 948 } |
937 | 949 |
938 | 950 |
939 Handle<Code> StubCache::ComputeLoadElementPolymorphic( | 951 Handle<Code> StubCache::ComputeLoadElementPolymorphic( |
(...skipping 1097 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2037 if (lookup->IsFound() && | 2049 if (lookup->IsFound() && |
2038 lookup->IsCacheable() && | 2050 lookup->IsCacheable() && |
2039 lookup->type() == CONSTANT_FUNCTION) { | 2051 lookup->type() == CONSTANT_FUNCTION) { |
2040 // We only optimize constant function calls. | 2052 // We only optimize constant function calls. |
2041 Initialize(Handle<JSFunction>(lookup->GetConstantFunction())); | 2053 Initialize(Handle<JSFunction>(lookup->GetConstantFunction())); |
2042 } else { | 2054 } else { |
2043 Initialize(Handle<JSFunction>::null()); | 2055 Initialize(Handle<JSFunction>::null()); |
2044 } | 2056 } |
2045 } | 2057 } |
2046 | 2058 |
| 2059 |
2047 CallOptimization::CallOptimization(Handle<JSFunction> function) { | 2060 CallOptimization::CallOptimization(Handle<JSFunction> function) { |
2048 Initialize(function); | 2061 Initialize(function); |
2049 } | 2062 } |
2050 | 2063 |
2051 | 2064 |
2052 int CallOptimization::GetPrototypeDepthOfExpectedType( | 2065 int CallOptimization::GetPrototypeDepthOfExpectedType( |
2053 Handle<JSObject> object, | 2066 Handle<JSObject> object, |
2054 Handle<JSObject> holder) const { | 2067 Handle<JSObject> holder) const { |
2055 ASSERT(is_simple_api_call()); | 2068 ASSERT(is_simple_api_call()); |
2056 if (expected_receiver_type_.is_null()) return 0; | 2069 if (expected_receiver_type_.is_null()) return 0; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2099 Handle<FunctionTemplateInfo>( | 2112 Handle<FunctionTemplateInfo>( |
2100 FunctionTemplateInfo::cast(signature->receiver())); | 2113 FunctionTemplateInfo::cast(signature->receiver())); |
2101 } | 2114 } |
2102 } | 2115 } |
2103 | 2116 |
2104 is_simple_api_call_ = true; | 2117 is_simple_api_call_ = true; |
2105 } | 2118 } |
2106 | 2119 |
2107 | 2120 |
2108 } } // namespace v8::internal | 2121 } } // namespace v8::internal |
OLD | NEW |