OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/port.h" | 5 #include "vm/port.h" |
6 | 6 |
7 #include "platform/utils.h" | 7 #include "platform/utils.h" |
8 #include "vm/dart_api_impl.h" | 8 #include "vm/dart_api_impl.h" |
9 #include "vm/isolate.h" | 9 #include "vm/isolate.h" |
10 #include "vm/message_handler.h" | 10 #include "vm/message_handler.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 return result; | 75 return result; |
76 } | 76 } |
77 | 77 |
78 | 78 |
79 void PortMap::SetLive(Dart_Port port) { | 79 void PortMap::SetLive(Dart_Port port) { |
80 MutexLocker ml(mutex_); | 80 MutexLocker ml(mutex_); |
81 intptr_t index = FindPort(port); | 81 intptr_t index = FindPort(port); |
82 ASSERT(index >= 0); | 82 ASSERT(index >= 0); |
83 map_[index].live = true; | 83 map_[index].live = true; |
84 map_[index].handler->increment_live_ports(); | 84 map_[index].handler->increment_live_ports(); |
85 if (FLAG_trace_isolates) { | |
Ivan Posva
2013/10/27 14:33:17
Added tracing support.
| |
86 OS::Print("[^] Live port: \n" | |
87 "\thandler: %s\n" | |
88 "\tport: %" Pd64 "\n", | |
89 map_[index].handler->name(), port); | |
90 } | |
85 } | 91 } |
86 | 92 |
87 | 93 |
88 void PortMap::MaintainInvariants() { | 94 void PortMap::MaintainInvariants() { |
89 intptr_t empty = capacity_ - used_ - deleted_; | 95 intptr_t empty = capacity_ - used_ - deleted_; |
90 if (used_ > ((capacity_ / 4) * 3)) { | 96 if (used_ > ((capacity_ / 4) * 3)) { |
91 // Grow the port map. | 97 // Grow the port map. |
92 Rehash(capacity_ * 2); | 98 Rehash(capacity_ * 2); |
93 } else if (empty < deleted_) { | 99 } else if (empty < deleted_) { |
94 // Rehash without growing the table to flush the deleted slots out of the | 100 // Rehash without growing the table to flush the deleted slots out of the |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 if (map_[index].handler == deleted_entry_) { | 136 if (map_[index].handler == deleted_entry_) { |
131 // Consuming a deleted entry. | 137 // Consuming a deleted entry. |
132 deleted_--; | 138 deleted_--; |
133 } | 139 } |
134 map_[index] = entry; | 140 map_[index] = entry; |
135 | 141 |
136 // Increment number of used slots and grow if necessary. | 142 // Increment number of used slots and grow if necessary. |
137 used_++; | 143 used_++; |
138 MaintainInvariants(); | 144 MaintainInvariants(); |
139 | 145 |
146 if (FLAG_trace_isolates) { | |
Ivan Posva
2013/10/27 14:33:17
ditto
| |
147 OS::Print("[+] Opening port: \n" | |
148 "\thandler: %s\n" | |
149 "\tport: %" Pd64 "\n", | |
150 handler->name(), entry.port); | |
151 } | |
152 | |
140 return entry.port; | 153 return entry.port; |
141 } | 154 } |
142 | 155 |
143 | 156 |
144 bool PortMap::ClosePort(Dart_Port port) { | 157 bool PortMap::ClosePort(Dart_Port port) { |
145 MessageHandler* handler = NULL; | 158 MessageHandler* handler = NULL; |
146 { | 159 { |
147 MutexLocker ml(mutex_); | 160 MutexLocker ml(mutex_); |
148 intptr_t index = FindPort(port); | 161 intptr_t index = FindPort(port); |
149 if (index < 0) { | 162 if (index < 0) { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 // TODO(iposva): Verify whether we want to keep exponentially growing. | 263 // TODO(iposva): Verify whether we want to keep exponentially growing. |
251 ASSERT(Utils::IsPowerOfTwo(kInitialCapacity)); | 264 ASSERT(Utils::IsPowerOfTwo(kInitialCapacity)); |
252 map_ = new Entry[kInitialCapacity]; | 265 map_ = new Entry[kInitialCapacity]; |
253 memset(map_, 0, kInitialCapacity * sizeof(Entry)); | 266 memset(map_, 0, kInitialCapacity * sizeof(Entry)); |
254 capacity_ = kInitialCapacity; | 267 capacity_ = kInitialCapacity; |
255 used_ = 0; | 268 used_ = 0; |
256 deleted_ = 0; | 269 deleted_ = 0; |
257 } | 270 } |
258 | 271 |
259 } // namespace dart | 272 } // namespace dart |
OLD | NEW |