OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 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 26 matching lines...) Expand all Loading... |
37 #include "global-handles.h" | 37 #include "global-handles.h" |
38 #include "natives.h" | 38 #include "natives.h" |
39 #include "runtime.h" | 39 #include "runtime.h" |
40 #include "stub-cache.h" | 40 #include "stub-cache.h" |
41 | 41 |
42 namespace v8 { | 42 namespace v8 { |
43 namespace internal { | 43 namespace internal { |
44 | 44 |
45 | 45 |
46 v8::ImplementationUtilities::HandleScopeData HandleScope::current_ = | 46 v8::ImplementationUtilities::HandleScopeData HandleScope::current_ = |
47 { -1, NULL, NULL }; | 47 { NULL, NULL, 0 }; |
48 | 48 |
49 | 49 |
50 int HandleScope::NumberOfHandles() { | 50 int HandleScope::NumberOfHandles() { |
51 int n = HandleScopeImplementer::instance()->blocks()->length(); | 51 int n = HandleScopeImplementer::instance()->blocks()->length(); |
52 if (n == 0) return 0; | 52 if (n == 0) return 0; |
53 return ((n - 1) * kHandleBlockSize) + static_cast<int>( | 53 return ((n - 1) * kHandleBlockSize) + static_cast<int>( |
54 (current_.next - HandleScopeImplementer::instance()->blocks()->last())); | 54 (current_.next - HandleScopeImplementer::instance()->blocks()->last())); |
55 } | 55 } |
56 | 56 |
57 | 57 |
58 Object** HandleScope::Extend() { | 58 Object** HandleScope::Extend() { |
59 Object** result = current_.next; | 59 Object** result = current_.next; |
60 | 60 |
61 ASSERT(result == current_.limit); | 61 ASSERT(result == current_.limit); |
62 // Make sure there's at least one scope on the stack and that the | 62 // Make sure there's at least one scope on the stack and that the |
63 // top of the scope stack isn't a barrier. | 63 // top of the scope stack isn't a barrier. |
64 if (current_.extensions < 0) { | 64 if (current_.level == 0) { |
65 Utils::ReportApiFailure("v8::HandleScope::CreateHandle()", | 65 Utils::ReportApiFailure("v8::HandleScope::CreateHandle()", |
66 "Cannot create a handle without a HandleScope"); | 66 "Cannot create a handle without a HandleScope"); |
67 return NULL; | 67 return NULL; |
68 } | 68 } |
69 HandleScopeImplementer* impl = HandleScopeImplementer::instance(); | 69 HandleScopeImplementer* impl = HandleScopeImplementer::instance(); |
70 // If there's more room in the last block, we use that. This is used | 70 // If there's more room in the last block, we use that. This is used |
71 // for fast creation of scopes after scope barriers. | 71 // for fast creation of scopes after scope barriers. |
72 if (!impl->blocks()->is_empty()) { | 72 if (!impl->blocks()->is_empty()) { |
73 Object** limit = &impl->blocks()->last()[kHandleBlockSize]; | 73 Object** limit = &impl->blocks()->last()[kHandleBlockSize]; |
74 if (current_.limit != limit) { | 74 if (current_.limit != limit) { |
75 current_.limit = limit; | 75 current_.limit = limit; |
| 76 ASSERT(limit - current_.next < kHandleBlockSize); |
76 } | 77 } |
77 } | 78 } |
78 | 79 |
79 // If we still haven't found a slot for the handle, we extend the | 80 // If we still haven't found a slot for the handle, we extend the |
80 // current handle scope by allocating a new handle block. | 81 // current handle scope by allocating a new handle block. |
81 if (result == current_.limit) { | 82 if (result == current_.limit) { |
82 // If there's a spare block, use it for growing the current scope. | 83 // If there's a spare block, use it for growing the current scope. |
83 result = impl->GetSpareOrNewBlock(); | 84 result = impl->GetSpareOrNewBlock(); |
84 // Add the extension to the global list of blocks, but count the | 85 // Add the extension to the global list of blocks, but count the |
85 // extension as part of the current scope. | 86 // extension as part of the current scope. |
86 impl->blocks()->Add(result); | 87 impl->blocks()->Add(result); |
87 current_.extensions++; | |
88 current_.limit = &result[kHandleBlockSize]; | 88 current_.limit = &result[kHandleBlockSize]; |
89 } | 89 } |
90 | 90 |
91 return result; | 91 return result; |
92 } | 92 } |
93 | 93 |
94 | 94 |
95 void HandleScope::DeleteExtensions() { | 95 void HandleScope::DeleteExtensions() { |
96 ASSERT(current_.extensions != 0); | 96 HandleScopeImplementer::instance()->DeleteExtensions(current_.limit); |
97 HandleScopeImplementer::instance()->DeleteExtensions(current_.extensions); | |
98 } | 97 } |
99 | 98 |
100 | 99 |
101 void HandleScope::ZapRange(Object** start, Object** end) { | 100 void HandleScope::ZapRange(Object** start, Object** end) { |
102 if (start == NULL) return; | 101 ASSERT(end - start <= kHandleBlockSize); |
103 for (Object** p = start; p < end; p++) { | 102 for (Object** p = start; p != end; p++) { |
104 *reinterpret_cast<Address*>(p) = v8::internal::kHandleZapValue; | 103 *reinterpret_cast<Address*>(p) = v8::internal::kHandleZapValue; |
105 } | 104 } |
106 } | 105 } |
107 | 106 |
108 | 107 |
109 Address HandleScope::current_extensions_address() { | 108 Address HandleScope::current_level_address() { |
110 return reinterpret_cast<Address>(¤t_.extensions); | 109 return reinterpret_cast<Address>(¤t_.level); |
111 } | 110 } |
112 | 111 |
113 | 112 |
114 Address HandleScope::current_next_address() { | 113 Address HandleScope::current_next_address() { |
115 return reinterpret_cast<Address>(¤t_.next); | 114 return reinterpret_cast<Address>(¤t_.next); |
116 } | 115 } |
117 | 116 |
118 | 117 |
119 Address HandleScope::current_limit_address() { | 118 Address HandleScope::current_limit_address() { |
120 return reinterpret_cast<Address>(¤t_.limit); | 119 return reinterpret_cast<Address>(¤t_.limit); |
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
865 | 864 |
866 OptimizedObjectForAddingMultipleProperties:: | 865 OptimizedObjectForAddingMultipleProperties:: |
867 ~OptimizedObjectForAddingMultipleProperties() { | 866 ~OptimizedObjectForAddingMultipleProperties() { |
868 // Reoptimize the object to allow fast property access. | 867 // Reoptimize the object to allow fast property access. |
869 if (has_been_transformed_) { | 868 if (has_been_transformed_) { |
870 TransformToFastProperties(object_, unused_property_fields_); | 869 TransformToFastProperties(object_, unused_property_fields_); |
871 } | 870 } |
872 } | 871 } |
873 | 872 |
874 } } // namespace v8::internal | 873 } } // namespace v8::internal |
OLD | NEW |