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

Side by Side Diff: src/ic.cc

Issue 255543003: CodeStubs contain their corresponding Isolate* now. (part 2) (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
OLDNEW
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 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 if (FLAG_use_ic) { 582 if (FLAG_use_ic) {
583 // Use specialized code for getting prototype of functions. 583 // Use specialized code for getting prototype of functions.
584 if (object->IsJSFunction() && 584 if (object->IsJSFunction() &&
585 String::Equals(isolate()->factory()->prototype_string(), name) && 585 String::Equals(isolate()->factory()->prototype_string(), name) &&
586 Handle<JSFunction>::cast(object)->should_have_prototype()) { 586 Handle<JSFunction>::cast(object)->should_have_prototype()) {
587 Handle<Code> stub; 587 Handle<Code> stub;
588 if (state() == UNINITIALIZED) { 588 if (state() == UNINITIALIZED) {
589 stub = pre_monomorphic_stub(); 589 stub = pre_monomorphic_stub();
590 } else if (state() == PREMONOMORPHIC) { 590 } else if (state() == PREMONOMORPHIC) {
591 FunctionPrototypeStub function_prototype_stub(isolate(), kind()); 591 FunctionPrototypeStub function_prototype_stub(isolate(), kind());
592 stub = function_prototype_stub.GetCode(isolate()); 592 stub = function_prototype_stub.GetCode();
593 } else if (state() != MEGAMORPHIC) { 593 } else if (state() != MEGAMORPHIC) {
594 ASSERT(state() != GENERIC); 594 ASSERT(state() != GENERIC);
595 stub = megamorphic_stub(); 595 stub = megamorphic_stub();
596 } 596 }
597 if (!stub.is_null()) { 597 if (!stub.is_null()) {
598 set_target(*stub); 598 set_target(*stub);
599 if (FLAG_trace_ic) PrintF("[LoadIC : +#prototype /function]\n"); 599 if (FLAG_trace_ic) PrintF("[LoadIC : +#prototype /function]\n");
600 } 600 }
601 return Accessors::FunctionGetPrototype(Handle<JSFunction>::cast(object)); 601 return Accessors::FunctionGetPrototype(Handle<JSFunction>::cast(object));
602 } 602 }
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 Handle<Code> LoadIC::megamorphic_stub() { 845 Handle<Code> LoadIC::megamorphic_stub() {
846 return isolate()->stub_cache()->ComputeLoad(MEGAMORPHIC, extra_ic_state()); 846 return isolate()->stub_cache()->ComputeLoad(MEGAMORPHIC, extra_ic_state());
847 } 847 }
848 848
849 849
850 Handle<Code> LoadIC::SimpleFieldLoad(int offset, 850 Handle<Code> LoadIC::SimpleFieldLoad(int offset,
851 bool inobject, 851 bool inobject,
852 Representation representation) { 852 Representation representation) {
853 if (kind() == Code::LOAD_IC) { 853 if (kind() == Code::LOAD_IC) {
854 LoadFieldStub stub(isolate(), inobject, offset, representation); 854 LoadFieldStub stub(isolate(), inobject, offset, representation);
855 return stub.GetCode(isolate()); 855 return stub.GetCode();
856 } else { 856 } else {
857 KeyedLoadFieldStub stub(isolate(), inobject, offset, representation); 857 KeyedLoadFieldStub stub(isolate(), inobject, offset, representation);
858 return stub.GetCode(isolate()); 858 return stub.GetCode();
859 } 859 }
860 } 860 }
861 861
862 862
863 void LoadIC::UpdateCaches(LookupResult* lookup, 863 void LoadIC::UpdateCaches(LookupResult* lookup,
864 Handle<Object> object, 864 Handle<Object> object,
865 Handle<String> name) { 865 Handle<String> name) {
866 if (state() == UNINITIALIZED) { 866 if (state() == UNINITIALIZED) {
867 // This is the first time we execute this inline cache. 867 // This is the first time we execute this inline cache.
868 // Set the target to the pre monomorphic stub to delay 868 // Set the target to the pre monomorphic stub to delay
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
934 if (object->IsString() && 934 if (object->IsString() &&
935 String::Equals(isolate()->factory()->length_string(), name)) { 935 String::Equals(isolate()->factory()->length_string(), name)) {
936 int length_index = String::kLengthOffset / kPointerSize; 936 int length_index = String::kLengthOffset / kPointerSize;
937 return SimpleFieldLoad(length_index); 937 return SimpleFieldLoad(length_index);
938 } 938 }
939 939
940 if (object->IsStringWrapper() && 940 if (object->IsStringWrapper() &&
941 String::Equals(isolate()->factory()->length_string(), name)) { 941 String::Equals(isolate()->factory()->length_string(), name)) {
942 if (kind() == Code::LOAD_IC) { 942 if (kind() == Code::LOAD_IC) {
943 StringLengthStub string_length_stub(isolate()); 943 StringLengthStub string_length_stub(isolate());
944 return string_length_stub.GetCode(isolate()); 944 return string_length_stub.GetCode();
945 } else { 945 } else {
946 KeyedStringLengthStub string_length_stub(isolate()); 946 KeyedStringLengthStub string_length_stub(isolate());
947 return string_length_stub.GetCode(isolate()); 947 return string_length_stub.GetCode();
948 } 948 }
949 } 949 }
950 950
951 Handle<HeapType> type = CurrentTypeOf(object, isolate()); 951 Handle<HeapType> type = CurrentTypeOf(object, isolate());
952 Handle<JSObject> holder(lookup->holder()); 952 Handle<JSObject> holder(lookup->holder());
953 LoadStubCompiler compiler(isolate(), kNoExtraICState, cache_holder, kind()); 953 LoadStubCompiler compiler(isolate(), kNoExtraICState, cache_holder, kind());
954 954
955 switch (lookup->type()) { 955 switch (lookup->type()) {
956 case FIELD: { 956 case FIELD: {
957 PropertyIndex field = lookup->GetFieldIndex(); 957 PropertyIndex field = lookup->GetFieldIndex();
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
1418 // The stub generated for the global object picks the value directly 1418 // The stub generated for the global object picks the value directly
1419 // from the property cell. So the property must be directly on the 1419 // from the property cell. So the property must be directly on the
1420 // global object. 1420 // global object.
1421 Handle<GlobalObject> global = receiver->IsJSGlobalProxy() 1421 Handle<GlobalObject> global = receiver->IsJSGlobalProxy()
1422 ? handle(GlobalObject::cast(receiver->GetPrototype())) 1422 ? handle(GlobalObject::cast(receiver->GetPrototype()))
1423 : Handle<GlobalObject>::cast(receiver); 1423 : Handle<GlobalObject>::cast(receiver);
1424 Handle<PropertyCell> cell(global->GetPropertyCell(lookup), isolate()); 1424 Handle<PropertyCell> cell(global->GetPropertyCell(lookup), isolate());
1425 Handle<HeapType> union_type = PropertyCell::UpdatedType(cell, value); 1425 Handle<HeapType> union_type = PropertyCell::UpdatedType(cell, value);
1426 StoreGlobalStub stub( 1426 StoreGlobalStub stub(
1427 isolate(), union_type->IsConstant(), receiver->IsJSGlobalProxy()); 1427 isolate(), union_type->IsConstant(), receiver->IsJSGlobalProxy());
1428 Handle<Code> code = stub.GetCodeCopyFromTemplate( 1428 Handle<Code> code = stub.GetCodeCopyFromTemplate(global, cell);
1429 isolate(), global, cell);
1430 // TODO(verwaest): Move caching of these NORMAL stubs outside as well. 1429 // TODO(verwaest): Move caching of these NORMAL stubs outside as well.
1431 HeapObject::UpdateMapCodeCache(receiver, name, code); 1430 HeapObject::UpdateMapCodeCache(receiver, name, code);
1432 return code; 1431 return code;
1433 } 1432 }
1434 ASSERT(holder.is_identical_to(receiver)); 1433 ASSERT(holder.is_identical_to(receiver));
1435 return isolate()->builtins()->StoreIC_Normal(); 1434 return isolate()->builtins()->StoreIC_Normal();
1436 case CALLBACKS: { 1435 case CALLBACKS: {
1437 Handle<Object> callback(lookup->GetCallbackObject(), isolate()); 1436 Handle<Object> callback(lookup->GetCallbackObject(), isolate());
1438 if (callback->IsExecutableAccessorInfo()) { 1437 if (callback->IsExecutableAccessorInfo()) {
1439 Handle<ExecutableAccessorInfo> info = 1438 Handle<ExecutableAccessorInfo> info =
(...skipping 1066 matching lines...) Expand 10 before | Expand all | Expand 10 after
2506 // Check if we have a string operation here. 2505 // Check if we have a string operation here.
2507 Handle<Code> target; 2506 Handle<Code> target;
2508 if (!allocation_site.is_null() || state.ShouldCreateAllocationMementos()) { 2507 if (!allocation_site.is_null() || state.ShouldCreateAllocationMementos()) {
2509 // Setup the allocation site on-demand. 2508 // Setup the allocation site on-demand.
2510 if (allocation_site.is_null()) { 2509 if (allocation_site.is_null()) {
2511 allocation_site = isolate()->factory()->NewAllocationSite(); 2510 allocation_site = isolate()->factory()->NewAllocationSite();
2512 } 2511 }
2513 2512
2514 // Install the stub with an allocation site. 2513 // Install the stub with an allocation site.
2515 BinaryOpICWithAllocationSiteStub stub(isolate(), state); 2514 BinaryOpICWithAllocationSiteStub stub(isolate(), state);
2516 target = stub.GetCodeCopyFromTemplate(isolate(), allocation_site); 2515 target = stub.GetCodeCopyFromTemplate(allocation_site);
2517 2516
2518 // Sanity check the trampoline stub. 2517 // Sanity check the trampoline stub.
2519 ASSERT_EQ(*allocation_site, target->FindFirstAllocationSite()); 2518 ASSERT_EQ(*allocation_site, target->FindFirstAllocationSite());
2520 } else { 2519 } else {
2521 // Install the generic stub. 2520 // Install the generic stub.
2522 BinaryOpICStub stub(isolate(), state); 2521 BinaryOpICStub stub(isolate(), state);
2523 target = stub.GetCode(isolate()); 2522 target = stub.GetCode();
2524 2523
2525 // Sanity check the generic stub. 2524 // Sanity check the generic stub.
2526 ASSERT_EQ(NULL, target->FindFirstAllocationSite()); 2525 ASSERT_EQ(NULL, target->FindFirstAllocationSite());
2527 } 2526 }
2528 set_target(*target); 2527 set_target(*target);
2529 2528
2530 if (FLAG_trace_ic) { 2529 if (FLAG_trace_ic) {
2531 char buffer[150]; 2530 char buffer[150];
2532 NoAllocationStringAllocator allocator( 2531 NoAllocationStringAllocator allocator(
2533 buffer, static_cast<unsigned>(sizeof(buffer))); 2532 buffer, static_cast<unsigned>(sizeof(buffer)));
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
2586 isolate, 2585 isolate,
2587 result, 2586 result,
2588 ic.Transition(allocation_site, left, right)); 2587 ic.Transition(allocation_site, left, right));
2589 return *result; 2588 return *result;
2590 } 2589 }
2591 2590
2592 2591
2593 Code* CompareIC::GetRawUninitialized(Isolate* isolate, Token::Value op) { 2592 Code* CompareIC::GetRawUninitialized(Isolate* isolate, Token::Value op) {
2594 ICCompareStub stub(isolate, op, UNINITIALIZED, UNINITIALIZED, UNINITIALIZED); 2593 ICCompareStub stub(isolate, op, UNINITIALIZED, UNINITIALIZED, UNINITIALIZED);
2595 Code* code = NULL; 2594 Code* code = NULL;
2596 CHECK(stub.FindCodeInCache(&code, isolate)); 2595 CHECK(stub.FindCodeInCache(&code));
2597 return code; 2596 return code;
2598 } 2597 }
2599 2598
2600 2599
2601 Handle<Code> CompareIC::GetUninitialized(Isolate* isolate, Token::Value op) { 2600 Handle<Code> CompareIC::GetUninitialized(Isolate* isolate, Token::Value op) {
2602 ICCompareStub stub(isolate, op, UNINITIALIZED, UNINITIALIZED, UNINITIALIZED); 2601 ICCompareStub stub(isolate, op, UNINITIALIZED, UNINITIALIZED, UNINITIALIZED);
2603 return stub.GetCode(isolate); 2602 return stub.GetCode();
2604 } 2603 }
2605 2604
2606 2605
2607 const char* CompareIC::GetStateName(State state) { 2606 const char* CompareIC::GetStateName(State state) {
2608 switch (state) { 2607 switch (state) {
2609 case UNINITIALIZED: return "UNINITIALIZED"; 2608 case UNINITIALIZED: return "UNINITIALIZED";
2610 case SMI: return "SMI"; 2609 case SMI: return "SMI";
2611 case NUMBER: return "NUMBER"; 2610 case NUMBER: return "NUMBER";
2612 case INTERNALIZED_STRING: return "INTERNALIZED_STRING"; 2611 case INTERNALIZED_STRING: return "INTERNALIZED_STRING";
2613 case STRING: return "STRING"; 2612 case STRING: return "STRING";
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
2770 &previous_right, &previous_state, NULL); 2769 &previous_right, &previous_state, NULL);
2771 State new_left = NewInputState(previous_left, x); 2770 State new_left = NewInputState(previous_left, x);
2772 State new_right = NewInputState(previous_right, y); 2771 State new_right = NewInputState(previous_right, y);
2773 State state = TargetState(previous_state, previous_left, previous_right, 2772 State state = TargetState(previous_state, previous_left, previous_right,
2774 HasInlinedSmiCode(address()), x, y); 2773 HasInlinedSmiCode(address()), x, y);
2775 ICCompareStub stub(isolate(), op_, new_left, new_right, state); 2774 ICCompareStub stub(isolate(), op_, new_left, new_right, state);
2776 if (state == KNOWN_OBJECT) { 2775 if (state == KNOWN_OBJECT) {
2777 stub.set_known_map( 2776 stub.set_known_map(
2778 Handle<Map>(Handle<JSObject>::cast(x)->map(), isolate())); 2777 Handle<Map>(Handle<JSObject>::cast(x)->map(), isolate()));
2779 } 2778 }
2780 Handle<Code> new_target = stub.GetCode(isolate()); 2779 Handle<Code> new_target = stub.GetCode();
2781 set_target(*new_target); 2780 set_target(*new_target);
2782 2781
2783 if (FLAG_trace_ic) { 2782 if (FLAG_trace_ic) {
2784 PrintF("[CompareIC in "); 2783 PrintF("[CompareIC in ");
2785 JavaScriptFrame::PrintTop(isolate(), stdout, false, true); 2784 JavaScriptFrame::PrintTop(isolate(), stdout, false, true);
2786 PrintF(" ((%s+%s=%s)->(%s+%s=%s))#%s @ %p]\n", 2785 PrintF(" ((%s+%s=%s)->(%s+%s=%s))#%s @ %p]\n",
2787 GetStateName(previous_left), 2786 GetStateName(previous_left),
2788 GetStateName(previous_right), 2787 GetStateName(previous_right),
2789 GetStateName(previous_state), 2788 GetStateName(previous_state),
2790 GetStateName(new_left), 2789 GetStateName(new_left),
2791 GetStateName(new_right), 2790 GetStateName(new_right),
2792 GetStateName(state), 2791 GetStateName(state),
2793 Token::Name(op_), 2792 Token::Name(op_),
2794 static_cast<void*>(*stub.GetCode(isolate()))); 2793 static_cast<void*>(*stub.GetCode()));
2795 } 2794 }
2796 2795
2797 // Activate inlined smi code. 2796 // Activate inlined smi code.
2798 if (previous_state == UNINITIALIZED) { 2797 if (previous_state == UNINITIALIZED) {
2799 PatchInlinedSmiCode(address(), ENABLE_INLINED_SMI_CHECK); 2798 PatchInlinedSmiCode(address(), ENABLE_INLINED_SMI_CHECK);
2800 } 2799 }
2801 2800
2802 return *new_target; 2801 return *new_target;
2803 } 2802 }
2804 2803
(...skipping 12 matching lines...) Expand all
2817 ConstantPoolArray* constant_pool) { 2816 ConstantPoolArray* constant_pool) {
2818 if (IsCleared(target)) return; 2817 if (IsCleared(target)) return;
2819 ExtraICState state = target->extra_ic_state(); 2818 ExtraICState state = target->extra_ic_state();
2820 2819
2821 CompareNilICStub stub(target->GetIsolate(), 2820 CompareNilICStub stub(target->GetIsolate(),
2822 state, 2821 state,
2823 HydrogenCodeStub::UNINITIALIZED); 2822 HydrogenCodeStub::UNINITIALIZED);
2824 stub.ClearState(); 2823 stub.ClearState();
2825 2824
2826 Code* code = NULL; 2825 Code* code = NULL;
2827 CHECK(stub.FindCodeInCache(&code, target->GetIsolate())); 2826 CHECK(stub.FindCodeInCache(&code));
2828 2827
2829 SetTargetAtAddress(address, code, constant_pool); 2828 SetTargetAtAddress(address, code, constant_pool);
2830 } 2829 }
2831 2830
2832 2831
2833 Handle<Object> CompareNilIC::DoCompareNilSlow(Isolate* isolate, 2832 Handle<Object> CompareNilIC::DoCompareNilSlow(Isolate* isolate,
2834 NilValue nil, 2833 NilValue nil,
2835 Handle<Object> object) { 2834 Handle<Object> object) {
2836 if (object->IsNull() || object->IsUndefined()) { 2835 if (object->IsNull() || object->IsUndefined()) {
2837 return handle(Smi::FromInt(true), isolate); 2836 return handle(Smi::FromInt(true), isolate);
(...skipping 16 matching lines...) Expand all
2854 NilValue nil = stub.GetNilValue(); 2853 NilValue nil = stub.GetNilValue();
2855 2854
2856 // Find or create the specialized stub to support the new set of types. 2855 // Find or create the specialized stub to support the new set of types.
2857 Handle<Code> code; 2856 Handle<Code> code;
2858 if (stub.IsMonomorphic()) { 2857 if (stub.IsMonomorphic()) {
2859 Handle<Map> monomorphic_map(already_monomorphic && FirstTargetMap() != NULL 2858 Handle<Map> monomorphic_map(already_monomorphic && FirstTargetMap() != NULL
2860 ? FirstTargetMap() 2859 ? FirstTargetMap()
2861 : HeapObject::cast(*object)->map()); 2860 : HeapObject::cast(*object)->map());
2862 code = isolate()->stub_cache()->ComputeCompareNil(monomorphic_map, stub); 2861 code = isolate()->stub_cache()->ComputeCompareNil(monomorphic_map, stub);
2863 } else { 2862 } else {
2864 code = stub.GetCode(isolate()); 2863 code = stub.GetCode();
2865 } 2864 }
2866 set_target(*code); 2865 set_target(*code);
2867 return DoCompareNilSlow(isolate(), nil, object); 2866 return DoCompareNilSlow(isolate(), nil, object);
2868 } 2867 }
2869 2868
2870 2869
2871 RUNTIME_FUNCTION(CompareNilIC_Miss) { 2870 RUNTIME_FUNCTION(CompareNilIC_Miss) {
2872 HandleScope scope(isolate); 2871 HandleScope scope(isolate);
2873 Handle<Object> object = args.at<Object>(0); 2872 Handle<Object> object = args.at<Object>(0);
2874 CompareNilIC ic(isolate); 2873 CompareNilIC ic(isolate);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
2920 case Token::SHL: 2919 case Token::SHL:
2921 return Builtins::SHL; 2920 return Builtins::SHL;
2922 break; 2921 break;
2923 } 2922 }
2924 } 2923 }
2925 2924
2926 2925
2927 Handle<Object> ToBooleanIC::ToBoolean(Handle<Object> object) { 2926 Handle<Object> ToBooleanIC::ToBoolean(Handle<Object> object) {
2928 ToBooleanStub stub(isolate(), target()->extra_ic_state()); 2927 ToBooleanStub stub(isolate(), target()->extra_ic_state());
2929 bool to_boolean_value = stub.UpdateStatus(object); 2928 bool to_boolean_value = stub.UpdateStatus(object);
2930 Handle<Code> code = stub.GetCode(isolate()); 2929 Handle<Code> code = stub.GetCode();
2931 set_target(*code); 2930 set_target(*code);
2932 return handle(Smi::FromInt(to_boolean_value ? 1 : 0), isolate()); 2931 return handle(Smi::FromInt(to_boolean_value ? 1 : 0), isolate());
2933 } 2932 }
2934 2933
2935 2934
2936 RUNTIME_FUNCTION(ToBooleanIC_Miss) { 2935 RUNTIME_FUNCTION(ToBooleanIC_Miss) {
2937 ASSERT(args.length() == 1); 2936 ASSERT(args.length() == 1);
2938 HandleScope scope(isolate); 2937 HandleScope scope(isolate);
2939 Handle<Object> object = args.at<Object>(0); 2938 Handle<Object> object = args.at<Object>(0);
2940 ToBooleanIC ic(isolate); 2939 ToBooleanIC ic(isolate);
2941 return *ic.ToBoolean(object); 2940 return *ic.ToBoolean(object);
2942 } 2941 }
2943 2942
2944 2943
2945 static const Address IC_utilities[] = { 2944 static const Address IC_utilities[] = {
2946 #define ADDR(name) FUNCTION_ADDR(name), 2945 #define ADDR(name) FUNCTION_ADDR(name),
2947 IC_UTIL_LIST(ADDR) 2946 IC_UTIL_LIST(ADDR)
2948 NULL 2947 NULL
2949 #undef ADDR 2948 #undef ADDR
2950 }; 2949 };
2951 2950
2952 2951
2953 Address IC::AddressFromUtilityId(IC::UtilityId id) { 2952 Address IC::AddressFromUtilityId(IC::UtilityId id) {
2954 return IC_utilities[id]; 2953 return IC_utilities[id];
2955 } 2954 }
2956 2955
2957 2956
2958 } } // namespace v8::internal 2957 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698