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

Side by Side Diff: src/ic.cc

Issue 6334015: Support StringLength in hydrogen (similar to ArrayLength). (Closed)
Patch Set: Created 9 years, 11 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
« no previous file with comments | « src/ic.h ('k') | src/stub-cache.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-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 804 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 MaybeObject* LoadIC::Load(State state, 815 MaybeObject* LoadIC::Load(State state,
816 Handle<Object> object, 816 Handle<Object> object,
817 Handle<String> name) { 817 Handle<String> name) {
818 // If the object is undefined or null it's illegal to try to get any 818 // If the object is undefined or null it's illegal to try to get any
819 // of its properties; throw a TypeError in that case. 819 // of its properties; throw a TypeError in that case.
820 if (object->IsUndefined() || object->IsNull()) { 820 if (object->IsUndefined() || object->IsNull()) {
821 return TypeError("non_object_property_load", object, name); 821 return TypeError("non_object_property_load", object, name);
822 } 822 }
823 823
824 if (FLAG_use_ic) { 824 if (FLAG_use_ic) {
825 Code* non_monomorphic_stub =
826 (state == UNINITIALIZED) ? pre_monomorphic_stub() : megamorphic_stub();
827
825 // Use specialized code for getting the length of strings and 828 // Use specialized code for getting the length of strings and
826 // string wrapper objects. The length property of string wrapper 829 // string wrapper objects. The length property of string wrapper
827 // objects is read-only and therefore always returns the length of 830 // objects is read-only and therefore always returns the length of
828 // the underlying string value. See ECMA-262 15.5.5.1. 831 // the underlying string value. See ECMA-262 15.5.5.1.
829 if ((object->IsString() || object->IsStringWrapper()) && 832 if ((object->IsString() || object->IsStringWrapper()) &&
830 name->Equals(Heap::length_symbol())) { 833 name->Equals(Heap::length_symbol())) {
831 HandleScope scope; 834 HandleScope scope;
835 #ifdef DEBUG
836 if (FLAG_trace_ic) PrintF("[LoadIC : +#length /string]\n");
837 #endif
838 if (state == PREMONOMORPHIC) {
839 if (object->IsString()) {
840 Map* map = HeapObject::cast(*object)->map();
841 const int offset = String::kLengthOffset;
842 PatchInlinedLoad(address(), map, offset);
843 set_target(Builtins::builtin(Builtins::LoadIC_StringLength));
844 } else {
845 set_target(Builtins::builtin(Builtins::LoadIC_StringWrapperLength));
846 }
847 } else if (state == MONOMORPHIC && object->IsStringWrapper()) {
848 set_target(Builtins::builtin(Builtins::LoadIC_StringWrapperLength));
849 } else {
850 set_target(non_monomorphic_stub);
851 }
832 // Get the string if we have a string wrapper object. 852 // Get the string if we have a string wrapper object.
833 if (object->IsJSValue()) { 853 if (object->IsJSValue()) {
834 object = Handle<Object>(Handle<JSValue>::cast(object)->value()); 854 object = Handle<Object>(Handle<JSValue>::cast(object)->value());
835 } 855 }
836 #ifdef DEBUG
837 if (FLAG_trace_ic) PrintF("[LoadIC : +#length /string]\n");
838 #endif
839 Map* map = HeapObject::cast(*object)->map();
840 if (object->IsString()) {
841 const int offset = String::kLengthOffset;
842 PatchInlinedLoad(address(), map, offset);
843 }
844
845 Code* target = NULL;
846 target = Builtins::builtin(Builtins::LoadIC_StringLength);
847 set_target(target);
848 return Smi::FromInt(String::cast(*object)->length()); 856 return Smi::FromInt(String::cast(*object)->length());
849 } 857 }
850 858
851 // Use specialized code for getting the length of arrays. 859 // Use specialized code for getting the length of arrays.
852 if (object->IsJSArray() && name->Equals(Heap::length_symbol())) { 860 if (object->IsJSArray() && name->Equals(Heap::length_symbol())) {
853 #ifdef DEBUG 861 #ifdef DEBUG
854 if (FLAG_trace_ic) PrintF("[LoadIC : +#length /array]\n"); 862 if (FLAG_trace_ic) PrintF("[LoadIC : +#length /array]\n");
855 #endif 863 #endif
856 Map* map = HeapObject::cast(*object)->map(); 864 if (state == PREMONOMORPHIC) {
857 const int offset = JSArray::kLengthOffset; 865 Map* map = HeapObject::cast(*object)->map();
858 PatchInlinedLoad(address(), map, offset); 866 const int offset = JSArray::kLengthOffset;
859 867 PatchInlinedLoad(address(), map, offset);
860 Code* target = Builtins::builtin(Builtins::LoadIC_ArrayLength); 868 set_target(Builtins::builtin(Builtins::LoadIC_ArrayLength));
861 set_target(target); 869 } else {
870 set_target(non_monomorphic_stub);
871 }
862 return JSArray::cast(*object)->length(); 872 return JSArray::cast(*object)->length();
863 } 873 }
864 874
865 // Use specialized code for getting prototype of functions. 875 // Use specialized code for getting prototype of functions.
866 if (object->IsJSFunction() && name->Equals(Heap::prototype_symbol()) && 876 if (object->IsJSFunction() && name->Equals(Heap::prototype_symbol()) &&
867 JSFunction::cast(*object)->should_have_prototype()) { 877 JSFunction::cast(*object)->should_have_prototype()) {
868 #ifdef DEBUG 878 #ifdef DEBUG
869 if (FLAG_trace_ic) PrintF("[LoadIC : +#prototype /function]\n"); 879 if (FLAG_trace_ic) PrintF("[LoadIC : +#prototype /function]\n");
870 #endif 880 #endif
871 Code* target = Builtins::builtin(Builtins::LoadIC_FunctionPrototype); 881 if (state == PREMONOMORPHIC) {
872 set_target(target); 882 set_target(Builtins::builtin(Builtins::LoadIC_FunctionPrototype));
883 } else {
884 set_target(non_monomorphic_stub);
885 }
873 return Accessors::FunctionGetPrototype(*object, 0); 886 return Accessors::FunctionGetPrototype(*object, 0);
874 } 887 }
875 } 888 }
876 889
877 // Check if the name is trivially convertible to an index and get 890 // Check if the name is trivially convertible to an index and get
878 // the element if so. 891 // the element if so.
879 uint32_t index; 892 uint32_t index;
880 if (name->AsArrayIndex(&index)) return object->GetElement(index); 893 if (name->AsArrayIndex(&index)) return object->GetElement(index);
881 894
882 // Named lookup in the object. 895 // Named lookup in the object.
(...skipping 1347 matching lines...) Expand 10 before | Expand all | Expand 10 after
2230 #undef ADDR 2243 #undef ADDR
2231 }; 2244 };
2232 2245
2233 2246
2234 Address IC::AddressFromUtilityId(IC::UtilityId id) { 2247 Address IC::AddressFromUtilityId(IC::UtilityId id) {
2235 return IC_utilities[id]; 2248 return IC_utilities[id];
2236 } 2249 }
2237 2250
2238 2251
2239 } } // namespace v8::internal 2252 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/ic.h ('k') | src/stub-cache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698