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

Side by Side Diff: src/runtime.cc

Issue 14146005: Track representations of fields (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Make double support consistent. Now DOUBLE always contains smi or heapnumber Created 7 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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 bool should_transform = 242 bool should_transform =
243 !is_result_from_cache && boilerplate->HasFastProperties(); 243 !is_result_from_cache && boilerplate->HasFastProperties();
244 if (should_transform || has_function_literal) { 244 if (should_transform || has_function_literal) {
245 // Normalize the properties of object to avoid n^2 behavior 245 // Normalize the properties of object to avoid n^2 behavior
246 // when extending the object multiple properties. Indicate the number of 246 // when extending the object multiple properties. Indicate the number of
247 // properties to be added. 247 // properties to be added.
248 JSObject::NormalizeProperties( 248 JSObject::NormalizeProperties(
249 boilerplate, KEEP_INOBJECT_PROPERTIES, length / 2); 249 boilerplate, KEEP_INOBJECT_PROPERTIES, length / 2);
250 } 250 }
251 251
252 // TODO(verwaest): This does not catch the case where the object stays in fast
253 // most from the beginning. However, since it may go slow by adding
254 // properties, currently only assume we'll ever be fast if we ensure
255 // converting it back to fast mode.
256 bool will_be_fast = should_transform && !has_function_literal;
252 for (int index = 0; index < length; index +=2) { 257 for (int index = 0; index < length; index +=2) {
253 Handle<Object> key(constant_properties->get(index+0), isolate); 258 Handle<Object> key(constant_properties->get(index+0), isolate);
254 Handle<Object> value(constant_properties->get(index+1), isolate); 259 Handle<Object> value(constant_properties->get(index+1), isolate);
255 if (value->IsFixedArray()) { 260 if (value->IsFixedArray()) {
256 // The value contains the constant_properties of a 261 // The value contains the constant_properties of a
257 // simple object or array literal. 262 // simple object or array literal.
258 Handle<FixedArray> array = Handle<FixedArray>::cast(value); 263 Handle<FixedArray> array = Handle<FixedArray>::cast(value);
259 value = CreateLiteralBoilerplate(isolate, literals, array); 264 value = CreateLiteralBoilerplate(isolate, literals, array);
260 if (value.is_null()) return value; 265 if (value.is_null()) return value;
266 } else if (value->IsUndefined()) {
267 // TODO(verwaest): Support storage types in the boilerplate.
268 // if (will_be_fast) {
269 // value = isolate->factory()->the_hole_value();
270 // } else {
271 // value = Handle<Object>(Smi::FromInt(0), isolate);
272 // }
261 } 273 }
262 Handle<Object> result; 274 Handle<Object> result;
263 uint32_t element_index = 0; 275 uint32_t element_index = 0;
264 if (key->IsInternalizedString()) { 276 if (key->IsInternalizedString()) {
265 if (Handle<String>::cast(key)->AsArrayIndex(&element_index)) { 277 if (Handle<String>::cast(key)->AsArrayIndex(&element_index)) {
266 // Array index as string (uint32). 278 // Array index as string (uint32).
267 result = JSObject::SetOwnElement( 279 result = JSObject::SetOwnElement(
268 boilerplate, element_index, value, kNonStrictMode); 280 boilerplate, element_index, value, kNonStrictMode);
269 } else { 281 } else {
270 Handle<String> name(String::cast(*key)); 282 Handle<String> name(String::cast(*key));
(...skipping 21 matching lines...) Expand all
292 // exception, the exception is converted to an empty handle in 304 // exception, the exception is converted to an empty handle in
293 // the handle based operations. In that case, we need to 305 // the handle based operations. In that case, we need to
294 // convert back to an exception. 306 // convert back to an exception.
295 if (result.is_null()) return result; 307 if (result.is_null()) return result;
296 } 308 }
297 309
298 // Transform to fast properties if necessary. For object literals with 310 // Transform to fast properties if necessary. For object literals with
299 // containing function literals we defer this operation until after all 311 // containing function literals we defer this operation until after all
300 // computed properties have been assigned so that we can generate 312 // computed properties have been assigned so that we can generate
301 // constant function properties. 313 // constant function properties.
302 if (should_transform && !has_function_literal) { 314 if (will_be_fast) {
303 JSObject::TransformToFastProperties( 315 JSObject::TransformToFastProperties(
304 boilerplate, boilerplate->map()->unused_property_fields()); 316 boilerplate, boilerplate->map()->unused_property_fields());
305 } 317 }
306 318
307 return boilerplate; 319 return boilerplate;
308 } 320 }
309 321
310 322
311 MaybeObject* TransitionElements(Handle<Object> object, 323 MaybeObject* TransitionElements(Handle<Object> object,
312 ElementsKind to_kind, 324 ElementsKind to_kind,
(...skipping 7163 matching lines...) Expand 10 before | Expand all | Expand 10 after
7476 Execution::New(Handle<JSFunction>::cast(bound_function), 7488 Execution::New(Handle<JSFunction>::cast(bound_function),
7477 total_argc, *param_data, &exception); 7489 total_argc, *param_data, &exception);
7478 if (exception) { 7490 if (exception) {
7479 return Failure::Exception(); 7491 return Failure::Exception();
7480 } 7492 }
7481 ASSERT(!result.is_null()); 7493 ASSERT(!result.is_null());
7482 return *result; 7494 return *result;
7483 } 7495 }
7484 7496
7485 7497
7486 static void TrySettingInlineConstructStub(Isolate* isolate, 7498 // static void TrySettingInlineConstructStub(Isolate* isolate,
7487 Handle<JSFunction> function) { 7499 // Handle<JSFunction> function) {
7488 Handle<Object> prototype = isolate->factory()->null_value(); 7500 // Handle<Object> prototype = isolate->factory()->null_value();
7489 if (function->has_instance_prototype()) { 7501 // if (function->has_instance_prototype()) {
7490 prototype = Handle<Object>(function->instance_prototype(), isolate); 7502 // prototype = Handle<Object>(function->instance_prototype(), isolate);
7491 } 7503 // }
7492 if (function->shared()->CanGenerateInlineConstructor(*prototype)) { 7504 // if (function->shared()->CanGenerateInlineConstructor(*prototype)) {
7493 ConstructStubCompiler compiler(isolate); 7505 // ConstructStubCompiler compiler(isolate);
7494 Handle<Code> code = compiler.CompileConstructStub(function); 7506 // Handle<Code> code = compiler.CompileConstructStub(function);
7495 function->shared()->set_construct_stub(*code); 7507 // function->shared()->set_construct_stub(*code);
7496 } 7508 // }
7497 } 7509 // }
7498 7510
7499 7511
7500 RUNTIME_FUNCTION(MaybeObject*, Runtime_NewObject) { 7512 RUNTIME_FUNCTION(MaybeObject*, Runtime_NewObject) {
7501 HandleScope scope(isolate); 7513 HandleScope scope(isolate);
7502 ASSERT(args.length() == 1); 7514 ASSERT(args.length() == 1);
7503 7515
7504 Handle<Object> constructor = args.at<Object>(0); 7516 Handle<Object> constructor = args.at<Object>(0);
7505 7517
7506 // If the constructor isn't a proper function we throw a type error. 7518 // If the constructor isn't a proper function we throw a type error.
7507 if (!constructor->IsJSFunction()) { 7519 if (!constructor->IsJSFunction()) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
7553 7565
7554 Handle<SharedFunctionInfo> shared(function->shared(), isolate); 7566 Handle<SharedFunctionInfo> shared(function->shared(), isolate);
7555 if (!function->has_initial_map() && 7567 if (!function->has_initial_map() &&
7556 shared->IsInobjectSlackTrackingInProgress()) { 7568 shared->IsInobjectSlackTrackingInProgress()) {
7557 // The tracking is already in progress for another function. We can only 7569 // The tracking is already in progress for another function. We can only
7558 // track one initial_map at a time, so we force the completion before the 7570 // track one initial_map at a time, so we force the completion before the
7559 // function is called as a constructor for the first time. 7571 // function is called as a constructor for the first time.
7560 shared->CompleteInobjectSlackTracking(); 7572 shared->CompleteInobjectSlackTracking();
7561 } 7573 }
7562 7574
7563 bool first_allocation = !shared->live_objects_may_exist(); 7575 // bool first_allocation = !shared->live_objects_may_exist();
7564 Handle<JSObject> result = isolate->factory()->NewJSObject(function); 7576 Handle<JSObject> result = isolate->factory()->NewJSObject(function);
7565 RETURN_IF_EMPTY_HANDLE(isolate, result); 7577 RETURN_IF_EMPTY_HANDLE(isolate, result);
7566 // Delay setting the stub if inobject slack tracking is in progress. 7578 // Delay setting the stub if inobject slack tracking is in progress.
7567 if (first_allocation && !shared->IsInobjectSlackTrackingInProgress()) { 7579 // if (first_allocation && !shared->IsInobjectSlackTrackingInProgress()) {
7568 TrySettingInlineConstructStub(isolate, function); 7580 // TrySettingInlineConstructStub(isolate, function);
7569 } 7581 // }
7570 7582
7571 isolate->counters()->constructed_objects()->Increment(); 7583 isolate->counters()->constructed_objects()->Increment();
7572 isolate->counters()->constructed_objects_runtime()->Increment(); 7584 isolate->counters()->constructed_objects_runtime()->Increment();
7573 7585
7574 return *result; 7586 return *result;
7575 } 7587 }
7576 7588
7577 7589
7578 RUNTIME_FUNCTION(MaybeObject*, Runtime_FinalizeInstanceSize) { 7590 RUNTIME_FUNCTION(MaybeObject*, Runtime_FinalizeInstanceSize) {
7579 HandleScope scope(isolate); 7591 HandleScope scope(isolate);
7580 ASSERT(args.length() == 1); 7592 ASSERT(args.length() == 1);
7581 7593
7582 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); 7594 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
7583 function->shared()->CompleteInobjectSlackTracking(); 7595 function->shared()->CompleteInobjectSlackTracking();
7584 TrySettingInlineConstructStub(isolate, function); 7596 // TrySettingInlineConstructStub(isolate, function);
7585 7597
7586 return isolate->heap()->undefined_value(); 7598 return isolate->heap()->undefined_value();
7587 } 7599 }
7588 7600
7589 7601
7590 RUNTIME_FUNCTION(MaybeObject*, Runtime_LazyCompile) { 7602 RUNTIME_FUNCTION(MaybeObject*, Runtime_LazyCompile) {
7591 HandleScope scope(isolate); 7603 HandleScope scope(isolate);
7592 ASSERT(args.length() == 1); 7604 ASSERT(args.length() == 1);
7593 7605
7594 Handle<JSFunction> function = args.at<JSFunction>(0); 7606 Handle<JSFunction> function = args.at<JSFunction>(0);
(...skipping 5696 matching lines...) Expand 10 before | Expand all | Expand 10 after
13291 // Handle last resort GC and make sure to allow future allocations 13303 // Handle last resort GC and make sure to allow future allocations
13292 // to grow the heap without causing GCs (if possible). 13304 // to grow the heap without causing GCs (if possible).
13293 isolate->counters()->gc_last_resort_from_js()->Increment(); 13305 isolate->counters()->gc_last_resort_from_js()->Increment();
13294 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 13306 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
13295 "Runtime::PerformGC"); 13307 "Runtime::PerformGC");
13296 } 13308 }
13297 } 13309 }
13298 13310
13299 13311
13300 } } // namespace v8::internal 13312 } } // namespace v8::internal
OLDNEW
« src/objects.cc ('K') | « src/property-details.h ('k') | src/stub-cache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698