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

Side by Side Diff: src/handles.cc

Issue 49001: Inline the fast path for handle creation.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 9 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/handles.h ('k') | src/stub-cache.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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 45
46 46
47 int HandleScope::NumberOfHandles() { 47 int HandleScope::NumberOfHandles() {
48 int n = HandleScopeImplementer::instance()->Blocks()->length(); 48 int n = HandleScopeImplementer::instance()->Blocks()->length();
49 if (n == 0) return 0; 49 if (n == 0) return 0;
50 return ((n - 1) * kHandleBlockSize) + 50 return ((n - 1) * kHandleBlockSize) +
51 (current_.next - HandleScopeImplementer::instance()->Blocks()->last()); 51 (current_.next - HandleScopeImplementer::instance()->Blocks()->last());
52 } 52 }
53 53
54 54
55 void** HandleScope::CreateHandle(void* value) { 55 void** HandleScope::Extend() {
56 void** result = current_.next; 56 void** result = current_.next;
57 if (result == current_.limit) {
58 // Make sure there's at least one scope on the stack and that the
59 // top of the scope stack isn't a barrier.
60 if (current_.extensions < 0) {
61 Utils::ReportApiFailure("v8::HandleScope::CreateHandle()",
62 "Cannot create a handle without a HandleScope");
63 return NULL;
64 }
65 HandleScopeImplementer* impl = HandleScopeImplementer::instance();
66 // If there's more room in the last block, we use that. This is used
67 // for fast creation of scopes after scope barriers.
68 if (!impl->Blocks()->is_empty()) {
69 void** limit = &impl->Blocks()->last()[kHandleBlockSize];
70 if (current_.limit != limit) {
71 current_.limit = limit;
72 }
73 }
74 57
75 // If we still haven't found a slot for the handle, we extend the 58 ASSERT(result == current_.limit);
76 // current handle scope by allocating a new handle block. 59 // Make sure there's at least one scope on the stack and that the
77 if (result == current_.limit) { 60 // top of the scope stack isn't a barrier.
78 // If there's a spare block, use it for growing the current scope. 61 if (current_.extensions < 0) {
79 result = impl->GetSpareOrNewBlock(); 62 Utils::ReportApiFailure("v8::HandleScope::CreateHandle()",
80 // Add the extension to the global list of blocks, but count the 63 "Cannot create a handle without a HandleScope");
81 // extension as part of the current scope. 64 return NULL;
82 impl->Blocks()->Add(result); 65 }
83 current_.extensions++; 66 HandleScopeImplementer* impl = HandleScopeImplementer::instance();
84 current_.limit = &result[kHandleBlockSize]; 67 // If there's more room in the last block, we use that. This is used
68 // for fast creation of scopes after scope barriers.
69 if (!impl->Blocks()->is_empty()) {
70 void** limit = &impl->Blocks()->last()[kHandleBlockSize];
71 if (current_.limit != limit) {
72 current_.limit = limit;
85 } 73 }
86 } 74 }
75
76 // If we still haven't found a slot for the handle, we extend the
77 // current handle scope by allocating a new handle block.
78 if (result == current_.limit) {
79 // If there's a spare block, use it for growing the current scope.
80 result = impl->GetSpareOrNewBlock();
81 // Add the extension to the global list of blocks, but count the
82 // extension as part of the current scope.
83 impl->Blocks()->Add(result);
84 current_.extensions++;
85 current_.limit = &result[kHandleBlockSize];
86 }
87 87
88 // Update the current next field, set the value in the created
89 // handle, and return the result.
90 ASSERT(result < current_.limit);
91 current_.next = result + 1;
92 *result = value;
93 return result; 88 return result;
94 } 89 }
95 90
96 91
97 void HandleScope::DeleteExtensions() { 92 void HandleScope::DeleteExtensions() {
98 ASSERT(current_.extensions != 0); 93 ASSERT(current_.extensions != 0);
99 HandleScopeImplementer::instance()->DeleteExtensions(current_.extensions); 94 HandleScopeImplementer::instance()->DeleteExtensions(current_.extensions);
100 } 95 }
101 96
102 97
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 Handle<Context> compile_context, 668 Handle<Context> compile_context,
674 Handle<Context> function_context) { 669 Handle<Context> function_context) {
675 Handle<FixedArray> arr = Factory::NewFixedArray(3); 670 Handle<FixedArray> arr = Factory::NewFixedArray(3);
676 arr->set(0, Smi::FromInt(index)); 671 arr->set(0, Smi::FromInt(index));
677 arr->set(1, *compile_context); // Compile in this context 672 arr->set(1, *compile_context); // Compile in this context
678 arr->set(2, *function_context); // Set function context to this 673 arr->set(2, *function_context); // Set function context to this
679 fun->shared()->set_lazy_load_data(*arr); 674 fun->shared()->set_lazy_load_data(*arr);
680 } 675 }
681 676
682 } } // namespace v8::internal 677 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/handles.h ('k') | src/stub-cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698