OLD | NEW |
---|---|
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 13 matching lines...) Expand all Loading... | |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #include "v8.h" | 28 #include "v8.h" |
29 | 29 |
30 #include "scopes.h" | 30 #include "scopes.h" |
31 | 31 |
32 #include "bootstrapper.h" | 32 #include "bootstrapper.h" |
33 #include "compiler.h" | 33 #include "compiler.h" |
34 #include "lazy-instance.h" | |
34 #include "messages.h" | 35 #include "messages.h" |
35 #include "scopeinfo.h" | 36 #include "scopeinfo.h" |
36 | 37 |
37 #include "allocation-inl.h" | 38 #include "allocation-inl.h" |
38 | 39 |
39 namespace v8 { | 40 namespace v8 { |
40 namespace internal { | 41 namespace internal { |
41 | 42 |
42 // ---------------------------------------------------------------------------- | 43 // ---------------------------------------------------------------------------- |
43 // A Zone allocator for use with LocalsMap. | 44 // A Zone allocator for use with LocalsMap. |
44 | 45 |
45 // TODO(isolates): It is probably worth it to change the Allocator class to | 46 // TODO(isolates): It is probably worth it to change the Allocator class to |
46 // take a pointer to an isolate. | 47 // take a pointer to an isolate. |
47 class ZoneAllocator: public Allocator { | 48 class ZoneAllocator: public Allocator { |
48 public: | 49 public: |
49 /* nothing to do */ | 50 /* nothing to do */ |
50 virtual ~ZoneAllocator() {} | 51 virtual ~ZoneAllocator() {} |
51 | 52 |
52 virtual void* New(size_t size) { return ZONE->New(static_cast<int>(size)); } | 53 virtual void* New(size_t size) { return ZONE->New(static_cast<int>(size)); } |
53 | 54 |
54 /* ignored - Zone is freed in one fell swoop */ | 55 /* ignored - Zone is freed in one fell swoop */ |
55 virtual void Delete(void* p) {} | 56 virtual void Delete(void* p) {} |
56 }; | 57 }; |
57 | 58 |
58 | 59 |
59 static ZoneAllocator* LocalsMapAllocator = ::new ZoneAllocator(); | 60 struct CreateZoneAllocator { |
61 static ZoneAllocator* Create() { | |
62 return ::new ZoneAllocator(); | |
63 } | |
64 }; | |
65 | |
66 static LazyDynamicInstance<ZoneAllocator, CreateZoneAllocator>::type | |
67 LocalsMapAllocator = LAZY_DYNAMIC_INSTANCE_INITIALIZER; | |
60 | 68 |
61 | 69 |
62 // ---------------------------------------------------------------------------- | 70 // ---------------------------------------------------------------------------- |
63 // Implementation of LocalsMap | 71 // Implementation of LocalsMap |
64 // | 72 // |
65 // Note: We are storing the handle locations as key values in the hash map. | 73 // Note: We are storing the handle locations as key values in the hash map. |
66 // When inserting a new variable via Declare(), we rely on the fact that | 74 // When inserting a new variable via Declare(), we rely on the fact that |
67 // the handle location remains alive for the duration of that variable | 75 // the handle location remains alive for the duration of that variable |
68 // use. Because a Variable holding a handle with the same location exists | 76 // use. Because a Variable holding a handle with the same location exists |
69 // this is ensured. | 77 // this is ensured. |
70 | 78 |
71 static bool Match(void* key1, void* key2) { | 79 static bool Match(void* key1, void* key2) { |
72 String* name1 = *reinterpret_cast<String**>(key1); | 80 String* name1 = *reinterpret_cast<String**>(key1); |
73 String* name2 = *reinterpret_cast<String**>(key2); | 81 String* name2 = *reinterpret_cast<String**>(key2); |
74 ASSERT(name1->IsSymbol()); | 82 ASSERT(name1->IsSymbol()); |
75 ASSERT(name2->IsSymbol()); | 83 ASSERT(name2->IsSymbol()); |
76 return name1 == name2; | 84 return name1 == name2; |
77 } | 85 } |
78 | 86 |
79 | 87 |
80 VariableMap::VariableMap() : HashMap(Match, LocalsMapAllocator, 8) {} | 88 VariableMap::VariableMap() : HashMap(Match, LocalsMapAllocator.Pointer(), 8) {} |
fschneider
2012/02/28 16:54:48
Not needed anymore because HashMap is already refa
| |
81 VariableMap::~VariableMap() {} | 89 VariableMap::~VariableMap() {} |
82 | 90 |
83 | 91 |
84 Variable* VariableMap::Declare( | 92 Variable* VariableMap::Declare( |
85 Scope* scope, | 93 Scope* scope, |
86 Handle<String> name, | 94 Handle<String> name, |
87 VariableMode mode, | 95 VariableMode mode, |
88 bool is_valid_lhs, | 96 bool is_valid_lhs, |
89 Variable::Kind kind, | 97 Variable::Kind kind, |
90 InitializationFlag initialization_flag) { | 98 InitializationFlag initialization_flag) { |
(...skipping 1126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1217 } | 1225 } |
1218 | 1226 |
1219 | 1227 |
1220 int Scope::ContextLocalCount() const { | 1228 int Scope::ContextLocalCount() const { |
1221 if (num_heap_slots() == 0) return 0; | 1229 if (num_heap_slots() == 0) return 0; |
1222 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1230 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
1223 (function_ != NULL && function_->var()->IsContextSlot() ? 1 : 0); | 1231 (function_ != NULL && function_->var()->IsContextSlot() ? 1 : 0); |
1224 } | 1232 } |
1225 | 1233 |
1226 } } // namespace v8::internal | 1234 } } // namespace v8::internal |
OLD | NEW |