OLD | NEW |
---|---|
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 4153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4164 NoHandleAllocation ha; | 4164 NoHandleAllocation ha; |
4165 ASSERT(args.length() == 2); | 4165 ASSERT(args.length() == 2); |
4166 | 4166 |
4167 Handle<Object> object = args.at<Object>(0); | 4167 Handle<Object> object = args.at<Object>(0); |
4168 Handle<Object> key = args.at<Object>(1); | 4168 Handle<Object> key = args.at<Object>(1); |
4169 | 4169 |
4170 return Runtime::GetObjectProperty(isolate, object, key); | 4170 return Runtime::GetObjectProperty(isolate, object, key); |
4171 } | 4171 } |
4172 | 4172 |
4173 | 4173 |
4174 MaybeObject* TransitionElements(Handle<Object> object, | |
4175 ElementsKind to_kind, | |
4176 Isolate* isolate) { | |
4177 HandleScope scope(isolate); | |
4178 if (!object->IsJSObject()) return isolate->ThrowIllegalOperation(); | |
4179 ElementsKind from_kind = | |
4180 Handle<JSObject>::cast(object)->map()->elements_kind(); | |
4181 if (Map::IsValidElementsTransition(from_kind, to_kind)) { | |
4182 Handle<Object> result = | |
4183 TransitionElementsKind(Handle<JSObject>::cast(object), to_kind); | |
4184 if (result.is_null()) return isolate->ThrowIllegalOperation(); | |
4185 return *result; | |
4186 } | |
4187 return isolate->ThrowIllegalOperation(); | |
4188 } | |
4189 | |
4190 | |
4174 // KeyedStringGetProperty is called from KeyedLoadIC::GenerateGeneric. | 4191 // KeyedStringGetProperty is called from KeyedLoadIC::GenerateGeneric. |
4175 RUNTIME_FUNCTION(MaybeObject*, Runtime_KeyedGetProperty) { | 4192 RUNTIME_FUNCTION(MaybeObject*, Runtime_KeyedGetProperty) { |
4176 NoHandleAllocation ha; | 4193 NoHandleAllocation ha; |
4177 ASSERT(args.length() == 2); | 4194 ASSERT(args.length() == 2); |
4178 | 4195 |
4179 // Fast cases for getting named properties of the receiver JSObject | 4196 // Fast cases for getting named properties of the receiver JSObject |
4180 // itself. | 4197 // itself. |
4181 // | 4198 // |
4182 // The global proxy objects has to be excluded since LocalLookup on | 4199 // The global proxy objects has to be excluded since LocalLookup on |
4183 // the global proxy object can return a valid result even though the | 4200 // the global proxy object can return a valid result even though the |
4184 // global proxy object never has properties. This is the case | 4201 // global proxy object never has properties. This is the case |
4185 // because the global proxy object forwards everything to its hidden | 4202 // because the global proxy object forwards everything to its hidden |
4186 // prototype including local lookups. | 4203 // prototype including local lookups. |
4187 // | 4204 // |
4188 // Additionally, we need to make sure that we do not cache results | 4205 // Additionally, we need to make sure that we do not cache results |
4189 // for objects that require access checks. | 4206 // for objects that require access checks. |
4190 if (args[0]->IsJSObject() && | 4207 if (args[0]->IsJSObject()) { |
4191 !args[0]->IsJSGlobalProxy() && | 4208 if (!args[0]->IsJSGlobalProxy() && |
4192 !args[0]->IsAccessCheckNeeded() && | 4209 !args[0]->IsAccessCheckNeeded() && |
4193 args[1]->IsString()) { | 4210 args[1]->IsString()) { |
4194 JSObject* receiver = JSObject::cast(args[0]); | 4211 JSObject* receiver = JSObject::cast(args[0]); |
4195 String* key = String::cast(args[1]); | 4212 String* key = String::cast(args[1]); |
4196 if (receiver->HasFastProperties()) { | 4213 if (receiver->HasFastProperties()) { |
4197 // Attempt to use lookup cache. | 4214 // Attempt to use lookup cache. |
4198 Map* receiver_map = receiver->map(); | 4215 Map* receiver_map = receiver->map(); |
4199 KeyedLookupCache* keyed_lookup_cache = isolate->keyed_lookup_cache(); | 4216 KeyedLookupCache* keyed_lookup_cache = isolate->keyed_lookup_cache(); |
4200 int offset = keyed_lookup_cache->Lookup(receiver_map, key); | 4217 int offset = keyed_lookup_cache->Lookup(receiver_map, key); |
4201 if (offset != -1) { | 4218 if (offset != -1) { |
4202 Object* value = receiver->FastPropertyAt(offset); | 4219 Object* value = receiver->FastPropertyAt(offset); |
4203 return value->IsTheHole() ? isolate->heap()->undefined_value() : value; | 4220 return value->IsTheHole() |
4204 } | 4221 ? isolate->heap()->undefined_value() |
4205 // Lookup cache miss. Perform lookup and update the cache if appropriate. | 4222 : value; |
4206 LookupResult result(isolate); | 4223 } |
4207 receiver->LocalLookup(key, &result); | 4224 // Lookup cache miss. Perform lookup and update the cache if |
4208 if (result.IsProperty() && result.type() == FIELD) { | 4225 // appropriate. |
4209 int offset = result.GetFieldIndex(); | 4226 LookupResult result(isolate); |
4210 keyed_lookup_cache->Update(receiver_map, key, offset); | 4227 receiver->LocalLookup(key, &result); |
4211 return receiver->FastPropertyAt(offset); | 4228 if (result.IsProperty() && result.type() == FIELD) { |
4229 int offset = result.GetFieldIndex(); | |
4230 keyed_lookup_cache->Update(receiver_map, key, offset); | |
4231 return receiver->FastPropertyAt(offset); | |
4232 } | |
4233 } else { | |
4234 // Attempt dictionary lookup. | |
4235 StringDictionary* dictionary = receiver->property_dictionary(); | |
4236 int entry = dictionary->FindEntry(key); | |
4237 if ((entry != StringDictionary::kNotFound) && | |
4238 (dictionary->DetailsAt(entry).type() == NORMAL)) { | |
4239 Object* value = dictionary->ValueAt(entry); | |
4240 if (!receiver->IsGlobalObject()) return value; | |
4241 value = JSGlobalPropertyCell::cast(value)->value(); | |
4242 if (!value->IsTheHole()) return value; | |
4243 // If value is the hole do the general lookup. | |
4244 } | |
4212 } | 4245 } |
4213 } else { | 4246 } else { |
4214 // Attempt dictionary lookup. | 4247 // JSObject without a string key. If the key is a Smi, check for a |
4215 StringDictionary* dictionary = receiver->property_dictionary(); | 4248 // definite out-of-bounds access to elements, which is a strong indicator |
4216 int entry = dictionary->FindEntry(key); | 4249 // that subsequent accesses will also call the runtime. Proactively |
4217 if ((entry != StringDictionary::kNotFound) && | 4250 // transition elements to FAST_ELEMENTS to avoid excessive boxing of |
4218 (dictionary->DetailsAt(entry).type() == NORMAL)) { | 4251 // doubles for those future calls in the case that the elements would |
4219 Object* value = dictionary->ValueAt(entry); | 4252 // become FAST_DOUBLE_ELEMENTS. |
4220 if (!receiver->IsGlobalObject()) return value; | 4253 if (args.at<Object>(1)->IsSmi()) { |
4221 value = JSGlobalPropertyCell::cast(value)->value(); | 4254 Handle<JSObject> js_object(args.at<JSObject>(0)); |
4222 if (!value->IsTheHole()) return value; | 4255 ElementsKind elements_kind = js_object->GetElementsKind(); |
4223 // If value is the hole do the general lookup. | 4256 if (elements_kind == FAST_SMI_ONLY_ELEMENTS || |
4257 elements_kind == FAST_DOUBLE_ELEMENTS) { | |
4258 FixedArrayBase* elements = js_object->elements(); | |
4259 if (args.at<Smi>(1)->value() >= elements->length()) { | |
4260 MaybeObject* maybe_object = TransitionElements(js_object, | |
4261 FAST_ELEMENTS, | |
4262 isolate); | |
4263 if (maybe_object->IsFailure()) return maybe_object; | |
4264 } | |
4265 } | |
Yang
2011/10/28 08:44:54
I would merge "else { if [...] }" to "else if [...
| |
4224 } | 4266 } |
4225 } | 4267 } |
4226 } else if (args[0]->IsString() && args[1]->IsSmi()) { | 4268 } else if (args[0]->IsString() && args[1]->IsSmi()) { |
4227 // Fast case for string indexing using [] with a smi index. | 4269 // Fast case for string indexing using [] with a smi index. |
4228 HandleScope scope(isolate); | 4270 HandleScope scope(isolate); |
4229 Handle<String> str = args.at<String>(0); | 4271 Handle<String> str = args.at<String>(0); |
4230 int index = args.smi_at(1); | 4272 int index = args.smi_at(1); |
4231 if (index >= 0 && index < str->length()) { | 4273 if (index >= 0 && index < str->length()) { |
4232 Handle<Object> result = GetCharAt(str, index); | 4274 Handle<Object> result = GetCharAt(str, index); |
4233 return *result; | 4275 return *result; |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4602 | 4644 |
4603 return Runtime::SetObjectProperty(isolate, | 4645 return Runtime::SetObjectProperty(isolate, |
4604 object, | 4646 object, |
4605 key, | 4647 key, |
4606 value, | 4648 value, |
4607 attributes, | 4649 attributes, |
4608 strict_mode); | 4650 strict_mode); |
4609 } | 4651 } |
4610 | 4652 |
4611 | 4653 |
4612 MaybeObject* TransitionElements(Handle<Object> object, | |
4613 ElementsKind to_kind, | |
4614 Isolate* isolate) { | |
4615 HandleScope scope(isolate); | |
4616 if (!object->IsJSObject()) return isolate->ThrowIllegalOperation(); | |
4617 ElementsKind from_kind = | |
4618 Handle<JSObject>::cast(object)->map()->elements_kind(); | |
4619 if (Map::IsValidElementsTransition(from_kind, to_kind)) { | |
4620 Handle<Object> result = | |
4621 TransitionElementsKind(Handle<JSObject>::cast(object), to_kind); | |
4622 if (result.is_null()) return isolate->ThrowIllegalOperation(); | |
4623 return *result; | |
4624 } | |
4625 return isolate->ThrowIllegalOperation(); | |
4626 } | |
4627 | |
4628 | |
4629 RUNTIME_FUNCTION(MaybeObject*, Runtime_TransitionElementsSmiToDouble) { | 4654 RUNTIME_FUNCTION(MaybeObject*, Runtime_TransitionElementsSmiToDouble) { |
4630 NoHandleAllocation ha; | 4655 NoHandleAllocation ha; |
4631 RUNTIME_ASSERT(args.length() == 1); | 4656 RUNTIME_ASSERT(args.length() == 1); |
4632 Handle<Object> object = args.at<Object>(0); | 4657 Handle<Object> object = args.at<Object>(0); |
4633 return TransitionElements(object, FAST_DOUBLE_ELEMENTS, isolate); | 4658 return TransitionElements(object, FAST_DOUBLE_ELEMENTS, isolate); |
4634 } | 4659 } |
4635 | 4660 |
4636 | 4661 |
4637 RUNTIME_FUNCTION(MaybeObject*, Runtime_TransitionElementsDoubleToObject) { | 4662 RUNTIME_FUNCTION(MaybeObject*, Runtime_TransitionElementsDoubleToObject) { |
4638 NoHandleAllocation ha; | 4663 NoHandleAllocation ha; |
(...skipping 8887 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
13526 } else { | 13551 } else { |
13527 // Handle last resort GC and make sure to allow future allocations | 13552 // Handle last resort GC and make sure to allow future allocations |
13528 // to grow the heap without causing GCs (if possible). | 13553 // to grow the heap without causing GCs (if possible). |
13529 isolate->counters()->gc_last_resort_from_js()->Increment(); | 13554 isolate->counters()->gc_last_resort_from_js()->Increment(); |
13530 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags); | 13555 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags); |
13531 } | 13556 } |
13532 } | 13557 } |
13533 | 13558 |
13534 | 13559 |
13535 } } // namespace v8::internal | 13560 } } // namespace v8::internal |
OLD | NEW |