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 "vm/dart_entry.h" | 7 #include "vm/dart_entry.h" |
8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
9 #include "vm/dart_api_impl.h" | 9 #include "vm/dart_api_impl.h" |
10 #include "vm/isolate.h" | 10 #include "vm/isolate.h" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 MutexLocker ml(mutex_); | 105 MutexLocker ml(mutex_); |
106 intptr_t index = FindPort(port); | 106 intptr_t index = FindPort(port); |
107 ASSERT(index >= 0); | 107 ASSERT(index >= 0); |
108 PortState old_state = map_[index].state; | 108 PortState old_state = map_[index].state; |
109 ASSERT(old_state == kNewPort); | 109 ASSERT(old_state == kNewPort); |
110 map_[index].state = state; | 110 map_[index].state = state; |
111 if (state == kLivePort) { | 111 if (state == kLivePort) { |
112 map_[index].handler->increment_live_ports(); | 112 map_[index].handler->increment_live_ports(); |
113 } | 113 } |
114 if (FLAG_trace_isolates) { | 114 if (FLAG_trace_isolates) { |
115 OS::Print("[^] Port (%s) -> (%s): \n" | 115 OS::Print( |
116 "\thandler: %s\n" | 116 "[^] Port (%s) -> (%s): \n" |
117 "\tport: %" Pd64 "\n", | 117 "\thandler: %s\n" |
118 PortStateString(old_state), PortStateString(state), | 118 "\tport: %" Pd64 "\n", |
119 map_[index].handler->name(), port); | 119 PortStateString(old_state), PortStateString(state), |
| 120 map_[index].handler->name(), port); |
120 } | 121 } |
121 } | 122 } |
122 | 123 |
123 | 124 |
124 void PortMap::MaintainInvariants() { | 125 void PortMap::MaintainInvariants() { |
125 intptr_t empty = capacity_ - used_ - deleted_; | 126 intptr_t empty = capacity_ - used_ - deleted_; |
126 if (used_ > ((capacity_ / 4) * 3)) { | 127 if (used_ > ((capacity_ / 4) * 3)) { |
127 // Grow the port map. | 128 // Grow the port map. |
128 Rehash(capacity_ * 2); | 129 Rehash(capacity_ * 2); |
129 } else if (empty < deleted_) { | 130 } else if (empty < deleted_) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 // Consuming a deleted entry. | 168 // Consuming a deleted entry. |
168 deleted_--; | 169 deleted_--; |
169 } | 170 } |
170 map_[index] = entry; | 171 map_[index] = entry; |
171 | 172 |
172 // Increment number of used slots and grow if necessary. | 173 // Increment number of used slots and grow if necessary. |
173 used_++; | 174 used_++; |
174 MaintainInvariants(); | 175 MaintainInvariants(); |
175 | 176 |
176 if (FLAG_trace_isolates) { | 177 if (FLAG_trace_isolates) { |
177 OS::Print("[+] Opening port: \n" | 178 OS::Print( |
178 "\thandler: %s\n" | 179 "[+] Opening port: \n" |
179 "\tport: %" Pd64 "\n", | 180 "\thandler: %s\n" |
180 handler->name(), entry.port); | 181 "\tport: %" Pd64 "\n", |
| 182 handler->name(), entry.port); |
181 } | 183 } |
182 | 184 |
183 return entry.port; | 185 return entry.port; |
184 } | 186 } |
185 | 187 |
186 | 188 |
187 bool PortMap::ClosePort(Dart_Port port) { | 189 bool PortMap::ClosePort(Dart_Port port) { |
188 MessageHandler* handler = NULL; | 190 MessageHandler* handler = NULL; |
189 { | 191 { |
190 MutexLocker ml(mutex_); | 192 MutexLocker ml(mutex_); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 OS::Print("Live Port = %" Pd64 "\n", map_[i].port); | 341 OS::Print("Live Port = %" Pd64 "\n", map_[i].port); |
340 msg_handler = DartLibraryCalls::LookupHandler(map_[i].port); | 342 msg_handler = DartLibraryCalls::LookupHandler(map_[i].port); |
341 OS::Print("Handler = %s\n", msg_handler.ToCString()); | 343 OS::Print("Handler = %s\n", msg_handler.ToCString()); |
342 } | 344 } |
343 } | 345 } |
344 } | 346 } |
345 } | 347 } |
346 | 348 |
347 | 349 |
348 } // namespace dart | 350 } // namespace dart |
OLD | NEW |