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

Side by Side Diff: src/objects.cc

Issue 10103035: Share optimized code for closures. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 8 years, 6 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
« no previous file with comments | « src/objects.h ('k') | src/objects-debug.cc » ('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 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 7453 matching lines...) Expand 10 before | Expand all | Expand 10 after
7464 } 7464 }
7465 7465
7466 7466
7467 bool SharedFunctionInfo::CompileLazy(Handle<SharedFunctionInfo> shared, 7467 bool SharedFunctionInfo::CompileLazy(Handle<SharedFunctionInfo> shared,
7468 ClearExceptionFlag flag) { 7468 ClearExceptionFlag flag) {
7469 CompilationInfo info(shared); 7469 CompilationInfo info(shared);
7470 return CompileLazyHelper(&info, flag); 7470 return CompileLazyHelper(&info, flag);
7471 } 7471 }
7472 7472
7473 7473
7474 void SharedFunctionInfo::ClearOptimizedCodeMap() {
7475 set_optimized_code_map(Smi::FromInt(0));
7476 }
7477
7478
7479 void SharedFunctionInfo::AddToOptimizedCodeMap(
7480 Handle<SharedFunctionInfo> shared,
7481 Handle<Context> global_context,
7482 Handle<Code> code,
7483 Handle<FixedArray> literals) {
7484 ASSERT(code->kind() == Code::OPTIMIZED_FUNCTION);
7485 ASSERT(global_context->IsGlobalContext());
7486 STATIC_ASSERT(kEntryLength == 3);
7487 Object* value = shared->optimized_code_map();
7488 Handle<FixedArray> new_code_map;
7489 if (value->IsSmi()) {
7490 // No optimized code map.
7491 ASSERT_EQ(0, Smi::cast(value)->value());
7492 // Crate 3 entries per context {context, code, literals}.
7493 new_code_map = FACTORY->NewFixedArray(kEntryLength);
7494 new_code_map->set(0, *global_context);
7495 new_code_map->set(1, *code);
7496 new_code_map->set(2, *literals);
7497 } else {
7498 // Copy old map and append one new entry.
7499 Handle<FixedArray> old_code_map(FixedArray::cast(value));
7500 ASSERT_EQ(-1, shared->SearchOptimizedCodeMap(*global_context));
7501 int old_length = old_code_map->length();
7502 int new_length = old_length + kEntryLength;
7503 new_code_map = FACTORY->NewFixedArray(new_length);
7504 old_code_map->CopyTo(0, *new_code_map, 0, old_length);
7505 new_code_map->set(old_length, *global_context);
7506 new_code_map->set(old_length + 1, *code);
7507 new_code_map->set(old_length + 2, *literals);
7508 }
7509 #ifdef DEBUG
7510 for (int i = 0; i < new_code_map->length(); i += kEntryLength) {
7511 ASSERT(new_code_map->get(i)->IsGlobalContext());
7512 ASSERT(new_code_map->get(i + 1)->IsCode());
7513 ASSERT(Code::cast(new_code_map->get(i + 1))->kind() ==
7514 Code::OPTIMIZED_FUNCTION);
7515 ASSERT(new_code_map->get(i + 2)->IsFixedArray());
7516 }
7517 #endif
7518 shared->set_optimized_code_map(*new_code_map);
7519 }
7520
7521
7474 bool JSFunction::CompileLazy(Handle<JSFunction> function, 7522 bool JSFunction::CompileLazy(Handle<JSFunction> function,
7475 ClearExceptionFlag flag) { 7523 ClearExceptionFlag flag) {
7476 bool result = true; 7524 bool result = true;
7477 if (function->shared()->is_compiled()) { 7525 if (function->shared()->is_compiled()) {
7478 function->ReplaceCode(function->shared()->code()); 7526 function->ReplaceCode(function->shared()->code());
7479 function->shared()->set_code_age(0); 7527 function->shared()->set_code_age(0);
7480 } else { 7528 } else {
7481 CompilationInfo info(function); 7529 CompilationInfo info(function);
7482 result = CompileLazyHelper(&info, flag); 7530 result = CompileLazyHelper(&info, flag);
7483 ASSERT(!result || function->is_compiled()); 7531 ASSERT(!result || function->is_compiled());
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
8033 // Resize the initial map and all maps in its transition tree. 8081 // Resize the initial map and all maps in its transition tree.
8034 map->TraverseTransitionTree(&ShrinkInstanceSize, &slack); 8082 map->TraverseTransitionTree(&ShrinkInstanceSize, &slack);
8035 8083
8036 // Give the correct expected_nof_properties to initial maps created later. 8084 // Give the correct expected_nof_properties to initial maps created later.
8037 ASSERT(expected_nof_properties() >= slack); 8085 ASSERT(expected_nof_properties() >= slack);
8038 set_expected_nof_properties(expected_nof_properties() - slack); 8086 set_expected_nof_properties(expected_nof_properties() - slack);
8039 } 8087 }
8040 } 8088 }
8041 8089
8042 8090
8091 int SharedFunctionInfo::SearchOptimizedCodeMap(Context* global_context) {
8092 ASSERT(global_context->IsGlobalContext());
8093 Object* value = optimized_code_map();
8094 if (!value->IsSmi()) {
8095 FixedArray* optimized_code_map = FixedArray::cast(value);
8096 int length = optimized_code_map->length();
8097 for (int i = 0; i < length; i += 3) {
8098 if (optimized_code_map->get(i) == global_context) {
8099 return i + 1;
8100 }
8101 }
8102 }
8103 return -1;
8104 }
8105
8106
8043 void SharedFunctionInfo::SharedFunctionInfoIterateBody(ObjectVisitor* v) { 8107 void SharedFunctionInfo::SharedFunctionInfoIterateBody(ObjectVisitor* v) {
8044 v->VisitSharedFunctionInfo(this); 8108 v->VisitSharedFunctionInfo(this);
8045 SharedFunctionInfo::BodyDescriptor::IterateBody(this, v); 8109 SharedFunctionInfo::BodyDescriptor::IterateBody(this, v);
8046 } 8110 }
8047 8111
8048 8112
8049 #define DECLARE_TAG(ignore1, name, ignore2) name, 8113 #define DECLARE_TAG(ignore1, name, ignore2) name,
8050 const char* const VisitorSynchronization::kTags[ 8114 const char* const VisitorSynchronization::kTags[
8051 VisitorSynchronization::kNumberOfSyncTags] = { 8115 VisitorSynchronization::kNumberOfSyncTags] = {
8052 VISITOR_SYNCHRONIZATION_TAGS_LIST(DECLARE_TAG) 8116 VISITOR_SYNCHRONIZATION_TAGS_LIST(DECLARE_TAG)
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
8323 PrintF(out, "%24s %s ", "", Translation::StringFor(opcode)); 8387 PrintF(out, "%24s %s ", "", Translation::StringFor(opcode));
8324 8388
8325 switch (opcode) { 8389 switch (opcode) {
8326 case Translation::BEGIN: 8390 case Translation::BEGIN:
8327 UNREACHABLE(); 8391 UNREACHABLE();
8328 break; 8392 break;
8329 8393
8330 case Translation::JS_FRAME: { 8394 case Translation::JS_FRAME: {
8331 int ast_id = iterator.Next(); 8395 int ast_id = iterator.Next();
8332 int function_id = iterator.Next(); 8396 int function_id = iterator.Next();
8333 JSFunction* function =
8334 JSFunction::cast(LiteralArray()->get(function_id));
8335 unsigned height = iterator.Next(); 8397 unsigned height = iterator.Next();
8336 PrintF(out, "{ast_id=%d, function=", ast_id); 8398 PrintF(out, "{ast_id=%d, function=", ast_id);
8337 function->PrintName(out); 8399 if (function_id != Translation::kSelfLiteralId) {
8400 Object* function = LiteralArray()->get(function_id);
8401 JSFunction::cast(function)->PrintName(out);
8402 } else {
8403 PrintF(out, "<self>");
8404 }
8338 PrintF(out, ", height=%u}", height); 8405 PrintF(out, ", height=%u}", height);
8339 break; 8406 break;
8340 } 8407 }
8341 8408
8342 case Translation::ARGUMENTS_ADAPTOR_FRAME: 8409 case Translation::ARGUMENTS_ADAPTOR_FRAME:
8343 case Translation::CONSTRUCT_STUB_FRAME: { 8410 case Translation::CONSTRUCT_STUB_FRAME: {
8344 int function_id = iterator.Next(); 8411 int function_id = iterator.Next();
8345 JSFunction* function = 8412 JSFunction* function =
8346 JSFunction::cast(LiteralArray()->get(function_id)); 8413 JSFunction::cast(LiteralArray()->get(function_id));
8347 unsigned height = iterator.Next(); 8414 unsigned height = iterator.Next();
(...skipping 4857 matching lines...) Expand 10 before | Expand all | Expand 10 after
13205 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); 13272 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER);
13206 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); 13273 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER);
13207 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); 13274 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER);
13208 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); 13275 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER);
13209 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); 13276 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER);
13210 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); 13277 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER);
13211 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); 13278 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER);
13212 } 13279 }
13213 13280
13214 } } // namespace v8::internal 13281 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/objects-debug.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698