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 22 matching lines...) Expand all Loading... |
33 #include "compiler.h" | 33 #include "compiler.h" |
34 #include "messages.h" | 34 #include "messages.h" |
35 #include "scopeinfo.h" | 35 #include "scopeinfo.h" |
36 | 36 |
37 #include "allocation-inl.h" | 37 #include "allocation-inl.h" |
38 | 38 |
39 namespace v8 { | 39 namespace v8 { |
40 namespace internal { | 40 namespace internal { |
41 | 41 |
42 // ---------------------------------------------------------------------------- | 42 // ---------------------------------------------------------------------------- |
43 // A Zone allocator for use with LocalsMap. | |
44 | |
45 // TODO(isolates): It is probably worth it to change the Allocator class to | |
46 // take a pointer to an isolate. | |
47 class ZoneAllocator: public Allocator { | |
48 public: | |
49 /* nothing to do */ | |
50 virtual ~ZoneAllocator() {} | |
51 | |
52 virtual void* New(size_t size) { return ZONE->New(static_cast<int>(size)); } | |
53 | |
54 /* ignored - Zone is freed in one fell swoop */ | |
55 virtual void Delete(void* p) {} | |
56 }; | |
57 | |
58 | |
59 static ZoneAllocator* LocalsMapAllocator = ::new ZoneAllocator(); | |
60 | |
61 | |
62 // ---------------------------------------------------------------------------- | |
63 // Implementation of LocalsMap | 43 // Implementation of LocalsMap |
64 // | 44 // |
65 // Note: We are storing the handle locations as key values in the hash map. | 45 // 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 | 46 // 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 | 47 // the handle location remains alive for the duration of that variable |
68 // use. Because a Variable holding a handle with the same location exists | 48 // use. Because a Variable holding a handle with the same location exists |
69 // this is ensured. | 49 // this is ensured. |
70 | 50 |
71 static bool Match(void* key1, void* key2) { | 51 static bool Match(void* key1, void* key2) { |
72 String* name1 = *reinterpret_cast<String**>(key1); | 52 String* name1 = *reinterpret_cast<String**>(key1); |
73 String* name2 = *reinterpret_cast<String**>(key2); | 53 String* name2 = *reinterpret_cast<String**>(key2); |
74 ASSERT(name1->IsSymbol()); | 54 ASSERT(name1->IsSymbol()); |
75 ASSERT(name2->IsSymbol()); | 55 ASSERT(name2->IsSymbol()); |
76 return name1 == name2; | 56 return name1 == name2; |
77 } | 57 } |
78 | 58 |
79 | 59 |
80 VariableMap::VariableMap() : HashMap(Match, LocalsMapAllocator, 8) {} | 60 VariableMap::VariableMap() : ZoneHashMap(Match, 8) {} |
81 VariableMap::~VariableMap() {} | 61 VariableMap::~VariableMap() {} |
82 | 62 |
83 | 63 |
84 Variable* VariableMap::Declare( | 64 Variable* VariableMap::Declare( |
85 Scope* scope, | 65 Scope* scope, |
86 Handle<String> name, | 66 Handle<String> name, |
87 VariableMode mode, | 67 VariableMode mode, |
88 bool is_valid_lhs, | 68 bool is_valid_lhs, |
89 Variable::Kind kind, | 69 Variable::Kind kind, |
90 InitializationFlag initialization_flag) { | 70 InitializationFlag initialization_flag) { |
91 HashMap::Entry* p = HashMap::Lookup(name.location(), name->Hash(), true); | 71 Entry* p = ZoneHashMap::Lookup(name.location(), name->Hash(), true); |
92 if (p->value == NULL) { | 72 if (p->value == NULL) { |
93 // The variable has not been declared yet -> insert it. | 73 // The variable has not been declared yet -> insert it. |
94 ASSERT(p->key == name.location()); | 74 ASSERT(p->key == name.location()); |
95 p->value = new Variable(scope, | 75 p->value = new Variable(scope, |
96 name, | 76 name, |
97 mode, | 77 mode, |
98 is_valid_lhs, | 78 is_valid_lhs, |
99 kind, | 79 kind, |
100 initialization_flag); | 80 initialization_flag); |
101 } | 81 } |
102 return reinterpret_cast<Variable*>(p->value); | 82 return reinterpret_cast<Variable*>(p->value); |
103 } | 83 } |
104 | 84 |
105 | 85 |
106 Variable* VariableMap::Lookup(Handle<String> name) { | 86 Variable* VariableMap::Lookup(Handle<String> name) { |
107 HashMap::Entry* p = HashMap::Lookup(name.location(), name->Hash(), false); | 87 Entry* p = ZoneHashMap::Lookup(name.location(), name->Hash(), false); |
108 if (p != NULL) { | 88 if (p != NULL) { |
109 ASSERT(*reinterpret_cast<String**>(p->key) == *name); | 89 ASSERT(*reinterpret_cast<String**>(p->key) == *name); |
110 ASSERT(p->value != NULL); | 90 ASSERT(p->value != NULL); |
111 return reinterpret_cast<Variable*>(p->value); | 91 return reinterpret_cast<Variable*>(p->value); |
112 } | 92 } |
113 return NULL; | 93 return NULL; |
114 } | 94 } |
115 | 95 |
116 | 96 |
117 // ---------------------------------------------------------------------------- | 97 // ---------------------------------------------------------------------------- |
(...skipping 1099 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1217 } | 1197 } |
1218 | 1198 |
1219 | 1199 |
1220 int Scope::ContextLocalCount() const { | 1200 int Scope::ContextLocalCount() const { |
1221 if (num_heap_slots() == 0) return 0; | 1201 if (num_heap_slots() == 0) return 0; |
1222 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1202 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
1223 (function_ != NULL && function_->var()->IsContextSlot() ? 1 : 0); | 1203 (function_ != NULL && function_->var()->IsContextSlot() ? 1 : 0); |
1224 } | 1204 } |
1225 | 1205 |
1226 } } // namespace v8::internal | 1206 } } // namespace v8::internal |
OLD | NEW |