| 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 17 matching lines...) Expand all Loading... |
| 28 #include "v8.h" | 28 #include "v8.h" |
| 29 | 29 |
| 30 #include "api.h" | 30 #include "api.h" |
| 31 #include "global-handles.h" | 31 #include "global-handles.h" |
| 32 | 32 |
| 33 #include "vm-state-inl.h" | 33 #include "vm-state-inl.h" |
| 34 | 34 |
| 35 namespace v8 { | 35 namespace v8 { |
| 36 namespace internal { | 36 namespace internal { |
| 37 | 37 |
| 38 |
| 39 ObjectGroup::~ObjectGroup() { |
| 40 if (info_ != NULL) info_->Dispose(); |
| 41 } |
| 42 |
| 43 |
| 38 class GlobalHandles::Node : public Malloced { | 44 class GlobalHandles::Node : public Malloced { |
| 39 public: | 45 public: |
| 40 | 46 |
| 41 void Initialize(Object* object) { | 47 void Initialize(Object* object) { |
| 42 // Set the initial value of the handle. | 48 // Set the initial value of the handle. |
| 43 object_ = object; | 49 object_ = object; |
| 44 class_id_ = v8::HeapProfiler::kPersistentHandleNoClassId; | 50 class_id_ = v8::HeapProfiler::kPersistentHandleNoClassId; |
| 45 state_ = NORMAL; | 51 state_ = NORMAL; |
| 46 parameter_or_next_free_.parameter = NULL; | 52 parameter_or_next_free_.parameter = NULL; |
| 47 callback_ = NULL; | 53 callback_ = NULL; |
| 48 } | 54 } |
| 49 | 55 |
| 50 Node() { | 56 Node() { |
| 51 state_ = DESTROYED; | 57 state_ = DESTROYED; |
| 52 } | 58 } |
| 53 | 59 |
| 54 explicit Node(Object* object) { | 60 explicit Node(Object* object) { |
| 55 Initialize(object); | 61 Initialize(object); |
| 56 // Initialize link structure. | 62 // Initialize link structure. |
| 57 next_ = NULL; | 63 next_ = NULL; |
| 58 } | 64 } |
| 59 | 65 |
| 60 ~Node() { | 66 ~Node() { |
| 61 if (state_ != DESTROYED) Destroy(); | 67 if (state_ != DESTROYED) Destroy(Isolate::Current()->global_handles()); |
| 62 #ifdef DEBUG | 68 #ifdef DEBUG |
| 63 // Zap the values for eager trapping. | 69 // Zap the values for eager trapping. |
| 64 object_ = NULL; | 70 object_ = NULL; |
| 65 next_ = NULL; | 71 next_ = NULL; |
| 66 parameter_or_next_free_.next_free = NULL; | 72 parameter_or_next_free_.next_free = NULL; |
| 67 #endif | 73 #endif |
| 68 } | 74 } |
| 69 | 75 |
| 70 void Destroy() { | 76 void Destroy(GlobalHandles* global_handles) { |
| 71 if (state_ == WEAK || IsNearDeath()) { | 77 if (state_ == WEAK || IsNearDeath()) { |
| 72 GlobalHandles::number_of_weak_handles_--; | 78 global_handles->number_of_weak_handles_--; |
| 73 if (object_->IsJSGlobalObject()) { | 79 if (object_->IsJSGlobalObject()) { |
| 74 GlobalHandles::number_of_global_object_weak_handles_--; | 80 global_handles->number_of_global_object_weak_handles_--; |
| 75 } | 81 } |
| 76 } | 82 } |
| 77 state_ = DESTROYED; | 83 state_ = DESTROYED; |
| 78 } | 84 } |
| 79 | 85 |
| 80 // Accessors for next_. | 86 // Accessors for next_. |
| 81 Node* next() { return next_; } | 87 Node* next() { return next_; } |
| 82 void set_next(Node* value) { next_ = value; } | 88 void set_next(Node* value) { next_ = value; } |
| 83 Node** next_addr() { return &next_; } | 89 Node** next_addr() { return &next_; } |
| 84 | 90 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 95 // Returns a link from the handle. | 101 // Returns a link from the handle. |
| 96 static Node* FromLocation(Object** location) { | 102 static Node* FromLocation(Object** location) { |
| 97 ASSERT(OFFSET_OF(Node, object_) == 0); | 103 ASSERT(OFFSET_OF(Node, object_) == 0); |
| 98 return reinterpret_cast<Node*>(location); | 104 return reinterpret_cast<Node*>(location); |
| 99 } | 105 } |
| 100 | 106 |
| 101 // Returns the handle. | 107 // Returns the handle. |
| 102 Handle<Object> handle() { return Handle<Object>(&object_); } | 108 Handle<Object> handle() { return Handle<Object>(&object_); } |
| 103 | 109 |
| 104 // Make this handle weak. | 110 // Make this handle weak. |
| 105 void MakeWeak(void* parameter, WeakReferenceCallback callback) { | 111 void MakeWeak(GlobalHandles* global_handles, void* parameter, |
| 106 LOG(HandleEvent("GlobalHandle::MakeWeak", handle().location())); | 112 WeakReferenceCallback callback) { |
| 113 LOG(global_handles->isolate(), |
| 114 HandleEvent("GlobalHandle::MakeWeak", handle().location())); |
| 107 ASSERT(state_ != DESTROYED); | 115 ASSERT(state_ != DESTROYED); |
| 108 if (state_ != WEAK && !IsNearDeath()) { | 116 if (state_ != WEAK && !IsNearDeath()) { |
| 109 GlobalHandles::number_of_weak_handles_++; | 117 global_handles->number_of_weak_handles_++; |
| 110 if (object_->IsJSGlobalObject()) { | 118 if (object_->IsJSGlobalObject()) { |
| 111 GlobalHandles::number_of_global_object_weak_handles_++; | 119 global_handles->number_of_global_object_weak_handles_++; |
| 112 } | 120 } |
| 113 } | 121 } |
| 114 state_ = WEAK; | 122 state_ = WEAK; |
| 115 set_parameter(parameter); | 123 set_parameter(parameter); |
| 116 callback_ = callback; | 124 callback_ = callback; |
| 117 } | 125 } |
| 118 | 126 |
| 119 void ClearWeakness() { | 127 void ClearWeakness(GlobalHandles* global_handles) { |
| 120 LOG(HandleEvent("GlobalHandle::ClearWeakness", handle().location())); | 128 LOG(global_handles->isolate(), |
| 129 HandleEvent("GlobalHandle::ClearWeakness", handle().location())); |
| 121 ASSERT(state_ != DESTROYED); | 130 ASSERT(state_ != DESTROYED); |
| 122 if (state_ == WEAK || IsNearDeath()) { | 131 if (state_ == WEAK || IsNearDeath()) { |
| 123 GlobalHandles::number_of_weak_handles_--; | 132 global_handles->number_of_weak_handles_--; |
| 124 if (object_->IsJSGlobalObject()) { | 133 if (object_->IsJSGlobalObject()) { |
| 125 GlobalHandles::number_of_global_object_weak_handles_--; | 134 global_handles->number_of_global_object_weak_handles_--; |
| 126 } | 135 } |
| 127 } | 136 } |
| 128 state_ = NORMAL; | 137 state_ = NORMAL; |
| 129 set_parameter(NULL); | 138 set_parameter(NULL); |
| 130 } | 139 } |
| 131 | 140 |
| 132 bool IsNearDeath() { | 141 bool IsNearDeath() { |
| 133 // Check for PENDING to ensure correct answer when processing callbacks. | 142 // Check for PENDING to ensure correct answer when processing callbacks. |
| 134 return state_ == PENDING || state_ == NEAR_DEATH; | 143 return state_ == PENDING || state_ == NEAR_DEATH; |
| 135 } | 144 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 152 parameter_or_next_free_.parameter = parameter; | 161 parameter_or_next_free_.parameter = parameter; |
| 153 } | 162 } |
| 154 void* parameter() { | 163 void* parameter() { |
| 155 ASSERT(state_ != DESTROYED); | 164 ASSERT(state_ != DESTROYED); |
| 156 return parameter_or_next_free_.parameter; | 165 return parameter_or_next_free_.parameter; |
| 157 } | 166 } |
| 158 | 167 |
| 159 // Returns the callback for this weak handle. | 168 // Returns the callback for this weak handle. |
| 160 WeakReferenceCallback callback() { return callback_; } | 169 WeakReferenceCallback callback() { return callback_; } |
| 161 | 170 |
| 162 bool PostGarbageCollectionProcessing() { | 171 bool PostGarbageCollectionProcessing(Isolate* isolate, |
| 172 GlobalHandles* global_handles) { |
| 163 if (state_ != Node::PENDING) return false; | 173 if (state_ != Node::PENDING) return false; |
| 164 LOG(HandleEvent("GlobalHandle::Processing", handle().location())); | 174 LOG(isolate, HandleEvent("GlobalHandle::Processing", handle().location())); |
| 165 WeakReferenceCallback func = callback(); | 175 WeakReferenceCallback func = callback(); |
| 166 if (func == NULL) { | 176 if (func == NULL) { |
| 167 Destroy(); | 177 Destroy(global_handles); |
| 168 return false; | 178 return false; |
| 169 } | 179 } |
| 170 void* par = parameter(); | 180 void* par = parameter(); |
| 171 state_ = NEAR_DEATH; | 181 state_ = NEAR_DEATH; |
| 172 set_parameter(NULL); | 182 set_parameter(NULL); |
| 173 | 183 |
| 174 v8::Persistent<v8::Object> object = ToApi<v8::Object>(handle()); | 184 v8::Persistent<v8::Object> object = ToApi<v8::Object>(handle()); |
| 175 { | 185 { |
| 176 // Forbid reuse of destroyed nodes as they might be already deallocated. | 186 // Forbid reuse of destroyed nodes as they might be already deallocated. |
| 177 // It's fine though to reuse nodes that were destroyed in weak callback | 187 // It's fine though to reuse nodes that were destroyed in weak callback |
| 178 // as those cannot be deallocated until we are back from the callback. | 188 // as those cannot be deallocated until we are back from the callback. |
| 179 set_first_free(NULL); | 189 global_handles->set_first_free(NULL); |
| 180 if (first_deallocated()) { | 190 if (global_handles->first_deallocated()) { |
| 181 first_deallocated()->set_next(head()); | 191 global_handles->first_deallocated()->set_next(global_handles->head()); |
| 182 } | 192 } |
| 183 // Check that we are not passing a finalized external string to | 193 // Check that we are not passing a finalized external string to |
| 184 // the callback. | 194 // the callback. |
| 185 ASSERT(!object_->IsExternalAsciiString() || | 195 ASSERT(!object_->IsExternalAsciiString() || |
| 186 ExternalAsciiString::cast(object_)->resource() != NULL); | 196 ExternalAsciiString::cast(object_)->resource() != NULL); |
| 187 ASSERT(!object_->IsExternalTwoByteString() || | 197 ASSERT(!object_->IsExternalTwoByteString() || |
| 188 ExternalTwoByteString::cast(object_)->resource() != NULL); | 198 ExternalTwoByteString::cast(object_)->resource() != NULL); |
| 189 // Leaving V8. | 199 // Leaving V8. |
| 190 VMState state(EXTERNAL); | 200 VMState state(isolate, EXTERNAL); |
| 191 func(object, par); | 201 func(object, par); |
| 192 } | 202 } |
| 193 // Absense of explicit cleanup or revival of weak handle | 203 // Absense of explicit cleanup or revival of weak handle |
| 194 // in most of the cases would lead to memory leak. | 204 // in most of the cases would lead to memory leak. |
| 195 ASSERT(state_ != NEAR_DEATH); | 205 ASSERT(state_ != NEAR_DEATH); |
| 196 return true; | 206 return true; |
| 197 } | 207 } |
| 198 | 208 |
| 199 // Place the handle address first to avoid offset computation. | 209 // Place the handle address first to avoid offset computation. |
| 200 Object* object_; // Storage for object pointer. | 210 Object* object_; // Storage for object pointer. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 223 } parameter_or_next_free_; | 233 } parameter_or_next_free_; |
| 224 | 234 |
| 225 // Linkage for the list. | 235 // Linkage for the list. |
| 226 Node* next_; | 236 Node* next_; |
| 227 | 237 |
| 228 public: | 238 public: |
| 229 TRACK_MEMORY("GlobalHandles::Node") | 239 TRACK_MEMORY("GlobalHandles::Node") |
| 230 }; | 240 }; |
| 231 | 241 |
| 232 | 242 |
| 233 class GlobalHandles::Pool BASE_EMBEDDED { | 243 class GlobalHandles::Pool { |
| 234 public: | 244 public: |
| 235 Pool() { | 245 Pool() { |
| 236 current_ = new Chunk(); | 246 current_ = new Chunk(); |
| 237 current_->previous = NULL; | 247 current_->previous = NULL; |
| 238 next_ = current_->nodes; | 248 next_ = current_->nodes; |
| 239 limit_ = current_->nodes + kNodesPerChunk; | 249 limit_ = current_->nodes + kNodesPerChunk; |
| 240 } | 250 } |
| 241 | 251 |
| 242 ~Pool() { | 252 ~Pool() { |
| 243 if (current_ != NULL) { | 253 if (current_ != NULL) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 limit_ = new_nodes + kNodesPerChunk; | 291 limit_ = new_nodes + kNodesPerChunk; |
| 282 return new_nodes; | 292 return new_nodes; |
| 283 } | 293 } |
| 284 | 294 |
| 285 Chunk* current_; | 295 Chunk* current_; |
| 286 Node* next_; | 296 Node* next_; |
| 287 Node* limit_; | 297 Node* limit_; |
| 288 }; | 298 }; |
| 289 | 299 |
| 290 | 300 |
| 291 static GlobalHandles::Pool pool_; | 301 GlobalHandles::GlobalHandles(Isolate* isolate) |
| 302 : isolate_(isolate), |
| 303 number_of_weak_handles_(0), |
| 304 number_of_global_object_weak_handles_(0), |
| 305 head_(NULL), |
| 306 first_free_(NULL), |
| 307 first_deallocated_(NULL), |
| 308 pool_(new Pool()), |
| 309 post_gc_processing_count_(0), |
| 310 object_groups_(4) { |
| 311 } |
| 312 |
| 313 |
| 314 GlobalHandles::~GlobalHandles() { |
| 315 delete pool_; |
| 316 pool_ = 0; |
| 317 } |
| 292 | 318 |
| 293 | 319 |
| 294 Handle<Object> GlobalHandles::Create(Object* value) { | 320 Handle<Object> GlobalHandles::Create(Object* value) { |
| 295 Counters::global_handles.Increment(); | 321 isolate_->counters()->global_handles()->Increment(); |
| 296 Node* result; | 322 Node* result; |
| 297 if (first_free()) { | 323 if (first_free()) { |
| 298 // Take the first node in the free list. | 324 // Take the first node in the free list. |
| 299 result = first_free(); | 325 result = first_free(); |
| 300 set_first_free(result->next_free()); | 326 set_first_free(result->next_free()); |
| 301 } else if (first_deallocated()) { | 327 } else if (first_deallocated()) { |
| 302 // Next try deallocated list | 328 // Next try deallocated list |
| 303 result = first_deallocated(); | 329 result = first_deallocated(); |
| 304 set_first_deallocated(result->next_free()); | 330 set_first_deallocated(result->next_free()); |
| 305 ASSERT(result->next() == head()); | 331 ASSERT(result->next() == head()); |
| 306 set_head(result); | 332 set_head(result); |
| 307 } else { | 333 } else { |
| 308 // Allocate a new node. | 334 // Allocate a new node. |
| 309 result = pool_.Allocate(); | 335 result = pool_->Allocate(); |
| 310 result->set_next(head()); | 336 result->set_next(head()); |
| 311 set_head(result); | 337 set_head(result); |
| 312 } | 338 } |
| 313 result->Initialize(value); | 339 result->Initialize(value); |
| 314 return result->handle(); | 340 return result->handle(); |
| 315 } | 341 } |
| 316 | 342 |
| 317 | 343 |
| 318 void GlobalHandles::Destroy(Object** location) { | 344 void GlobalHandles::Destroy(Object** location) { |
| 319 Counters::global_handles.Decrement(); | 345 isolate_->counters()->global_handles()->Decrement(); |
| 320 if (location == NULL) return; | 346 if (location == NULL) return; |
| 321 Node* node = Node::FromLocation(location); | 347 Node* node = Node::FromLocation(location); |
| 322 node->Destroy(); | 348 node->Destroy(this); |
| 323 // Link the destroyed. | 349 // Link the destroyed. |
| 324 node->set_next_free(first_free()); | 350 node->set_next_free(first_free()); |
| 325 set_first_free(node); | 351 set_first_free(node); |
| 326 } | 352 } |
| 327 | 353 |
| 328 | 354 |
| 329 void GlobalHandles::MakeWeak(Object** location, void* parameter, | 355 void GlobalHandles::MakeWeak(Object** location, void* parameter, |
| 330 WeakReferenceCallback callback) { | 356 WeakReferenceCallback callback) { |
| 331 ASSERT(callback != NULL); | 357 ASSERT(callback != NULL); |
| 332 Node::FromLocation(location)->MakeWeak(parameter, callback); | 358 Node::FromLocation(location)->MakeWeak(this, parameter, callback); |
| 333 } | 359 } |
| 334 | 360 |
| 335 | 361 |
| 336 void GlobalHandles::ClearWeakness(Object** location) { | 362 void GlobalHandles::ClearWeakness(Object** location) { |
| 337 Node::FromLocation(location)->ClearWeakness(); | 363 Node::FromLocation(location)->ClearWeakness(this); |
| 338 } | 364 } |
| 339 | 365 |
| 340 | 366 |
| 341 bool GlobalHandles::IsNearDeath(Object** location) { | 367 bool GlobalHandles::IsNearDeath(Object** location) { |
| 342 return Node::FromLocation(location)->IsNearDeath(); | 368 return Node::FromLocation(location)->IsNearDeath(); |
| 343 } | 369 } |
| 344 | 370 |
| 345 | 371 |
| 346 bool GlobalHandles::IsWeak(Object** location) { | 372 bool GlobalHandles::IsWeak(Object** location) { |
| 347 return Node::FromLocation(location)->IsWeak(); | 373 return Node::FromLocation(location)->IsWeak(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 374 } | 400 } |
| 375 } | 401 } |
| 376 } | 402 } |
| 377 | 403 |
| 378 | 404 |
| 379 void GlobalHandles::IdentifyWeakHandles(WeakSlotCallback f) { | 405 void GlobalHandles::IdentifyWeakHandles(WeakSlotCallback f) { |
| 380 for (Node* current = head_; current != NULL; current = current->next()) { | 406 for (Node* current = head_; current != NULL; current = current->next()) { |
| 381 if (current->state_ == Node::WEAK) { | 407 if (current->state_ == Node::WEAK) { |
| 382 if (f(¤t->object_)) { | 408 if (f(¤t->object_)) { |
| 383 current->state_ = Node::PENDING; | 409 current->state_ = Node::PENDING; |
| 384 LOG(HandleEvent("GlobalHandle::Pending", current->handle().location())); | 410 LOG(isolate_, |
| 411 HandleEvent("GlobalHandle::Pending", current->handle().location())); |
| 385 } | 412 } |
| 386 } | 413 } |
| 387 } | 414 } |
| 388 } | 415 } |
| 389 | 416 |
| 390 | 417 |
| 391 int post_gc_processing_count = 0; | |
| 392 | |
| 393 bool GlobalHandles::PostGarbageCollectionProcessing() { | 418 bool GlobalHandles::PostGarbageCollectionProcessing() { |
| 394 // Process weak global handle callbacks. This must be done after the | 419 // Process weak global handle callbacks. This must be done after the |
| 395 // GC is completely done, because the callbacks may invoke arbitrary | 420 // GC is completely done, because the callbacks may invoke arbitrary |
| 396 // API functions. | 421 // API functions. |
| 397 // At the same time deallocate all DESTROYED nodes. | 422 // At the same time deallocate all DESTROYED nodes. |
| 398 ASSERT(Heap::gc_state() == Heap::NOT_IN_GC); | 423 ASSERT(isolate_->heap()->gc_state() == Heap::NOT_IN_GC); |
| 399 const int initial_post_gc_processing_count = ++post_gc_processing_count; | 424 const int initial_post_gc_processing_count = ++post_gc_processing_count_; |
| 400 bool next_gc_likely_to_collect_more = false; | 425 bool next_gc_likely_to_collect_more = false; |
| 401 Node** p = &head_; | 426 Node** p = &head_; |
| 402 while (*p != NULL) { | 427 while (*p != NULL) { |
| 403 if ((*p)->PostGarbageCollectionProcessing()) { | 428 if ((*p)->PostGarbageCollectionProcessing(isolate_, this)) { |
| 404 if (initial_post_gc_processing_count != post_gc_processing_count) { | 429 if (initial_post_gc_processing_count != post_gc_processing_count_) { |
| 405 // Weak callback triggered another GC and another round of | 430 // Weak callback triggered another GC and another round of |
| 406 // PostGarbageCollection processing. The current node might | 431 // PostGarbageCollection processing. The current node might |
| 407 // have been deleted in that round, so we need to bail out (or | 432 // have been deleted in that round, so we need to bail out (or |
| 408 // restart the processing). | 433 // restart the processing). |
| 409 break; | 434 break; |
| 410 } | 435 } |
| 411 } | 436 } |
| 412 if ((*p)->state_ == Node::DESTROYED) { | 437 if ((*p)->state_ == Node::DESTROYED) { |
| 413 // Delete the link. | 438 // Delete the link. |
| 414 Node* node = *p; | 439 Node* node = *p; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 } | 484 } |
| 460 } | 485 } |
| 461 } | 486 } |
| 462 | 487 |
| 463 | 488 |
| 464 void GlobalHandles::TearDown() { | 489 void GlobalHandles::TearDown() { |
| 465 // Reset all the lists. | 490 // Reset all the lists. |
| 466 set_head(NULL); | 491 set_head(NULL); |
| 467 set_first_free(NULL); | 492 set_first_free(NULL); |
| 468 set_first_deallocated(NULL); | 493 set_first_deallocated(NULL); |
| 469 pool_.Release(); | 494 pool_->Release(); |
| 470 } | 495 } |
| 471 | 496 |
| 472 | 497 |
| 473 int GlobalHandles::number_of_weak_handles_ = 0; | |
| 474 int GlobalHandles::number_of_global_object_weak_handles_ = 0; | |
| 475 | |
| 476 GlobalHandles::Node* GlobalHandles::head_ = NULL; | |
| 477 GlobalHandles::Node* GlobalHandles::first_free_ = NULL; | |
| 478 GlobalHandles::Node* GlobalHandles::first_deallocated_ = NULL; | |
| 479 | |
| 480 void GlobalHandles::RecordStats(HeapStats* stats) { | 498 void GlobalHandles::RecordStats(HeapStats* stats) { |
| 481 *stats->global_handle_count = 0; | 499 *stats->global_handle_count = 0; |
| 482 *stats->weak_global_handle_count = 0; | 500 *stats->weak_global_handle_count = 0; |
| 483 *stats->pending_global_handle_count = 0; | 501 *stats->pending_global_handle_count = 0; |
| 484 *stats->near_death_global_handle_count = 0; | 502 *stats->near_death_global_handle_count = 0; |
| 485 *stats->destroyed_global_handle_count = 0; | 503 *stats->destroyed_global_handle_count = 0; |
| 486 for (Node* current = head_; current != NULL; current = current->next()) { | 504 for (Node* current = head_; current != NULL; current = current->next()) { |
| 487 *stats->global_handle_count += 1; | 505 *stats->global_handle_count += 1; |
| 488 if (current->state_ == Node::WEAK) { | 506 if (current->state_ == Node::WEAK) { |
| 489 *stats->weak_global_handle_count += 1; | 507 *stats->weak_global_handle_count += 1; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 for (Node* current = head_; current != NULL; current = current->next()) { | 546 for (Node* current = head_; current != NULL; current = current->next()) { |
| 529 PrintF(" handle %p to %p (weak=%d)\n", | 547 PrintF(" handle %p to %p (weak=%d)\n", |
| 530 reinterpret_cast<void*>(current->handle().location()), | 548 reinterpret_cast<void*>(current->handle().location()), |
| 531 reinterpret_cast<void*>(*current->handle()), | 549 reinterpret_cast<void*>(*current->handle()), |
| 532 current->state_ == Node::WEAK); | 550 current->state_ == Node::WEAK); |
| 533 } | 551 } |
| 534 } | 552 } |
| 535 | 553 |
| 536 #endif | 554 #endif |
| 537 | 555 |
| 538 List<ObjectGroup*>* GlobalHandles::ObjectGroups() { | |
| 539 // Lazily initialize the list to avoid startup time static constructors. | |
| 540 static List<ObjectGroup*> groups(4); | |
| 541 return &groups; | |
| 542 } | |
| 543 | 556 |
| 544 | 557 |
| 545 void GlobalHandles::AddObjectGroup(Object*** handles, | 558 void GlobalHandles::AddObjectGroup(Object*** handles, |
| 546 size_t length, | 559 size_t length, |
| 547 v8::RetainedObjectInfo* info) { | 560 v8::RetainedObjectInfo* info) { |
| 548 ObjectGroup* new_entry = new ObjectGroup(length, info); | 561 ObjectGroup* new_entry = new ObjectGroup(length, info); |
| 549 for (size_t i = 0; i < length; ++i) { | 562 for (size_t i = 0; i < length; ++i) { |
| 550 new_entry->objects_.Add(handles[i]); | 563 new_entry->objects_.Add(handles[i]); |
| 551 } | 564 } |
| 552 ObjectGroups()->Add(new_entry); | 565 object_groups_.Add(new_entry); |
| 553 } | |
| 554 | |
| 555 | |
| 556 List<ImplicitRefGroup*>* GlobalHandles::ImplicitRefGroups() { | |
| 557 // Lazily initialize the list to avoid startup time static constructors. | |
| 558 static List<ImplicitRefGroup*> groups(4); | |
| 559 return &groups; | |
| 560 } | 566 } |
| 561 | 567 |
| 562 | 568 |
| 563 void GlobalHandles::AddImplicitReferences(HeapObject* parent, | 569 void GlobalHandles::AddImplicitReferences(HeapObject* parent, |
| 564 Object*** children, | 570 Object*** children, |
| 565 size_t length) { | 571 size_t length) { |
| 566 ImplicitRefGroup* new_entry = new ImplicitRefGroup(parent, length); | 572 ImplicitRefGroup* new_entry = new ImplicitRefGroup(parent, length); |
| 567 for (size_t i = 0; i < length; ++i) { | 573 for (size_t i = 0; i < length; ++i) { |
| 568 new_entry->children_.Add(children[i]); | 574 new_entry->children_.Add(children[i]); |
| 569 } | 575 } |
| 570 ImplicitRefGroups()->Add(new_entry); | 576 implicit_ref_groups_.Add(new_entry); |
| 571 } | 577 } |
| 572 | 578 |
| 573 | 579 |
| 574 void GlobalHandles::RemoveObjectGroups() { | 580 void GlobalHandles::RemoveObjectGroups() { |
| 575 List<ObjectGroup*>* object_groups = ObjectGroups(); | 581 for (int i = 0; i < object_groups_.length(); i++) { |
| 576 for (int i = 0; i< object_groups->length(); i++) { | 582 delete object_groups_.at(i); |
| 577 delete object_groups->at(i); | |
| 578 } | 583 } |
| 579 object_groups->Clear(); | 584 object_groups_.Clear(); |
| 580 } | 585 } |
| 581 | 586 |
| 582 | 587 |
| 583 void GlobalHandles::RemoveImplicitRefGroups() { | 588 void GlobalHandles::RemoveImplicitRefGroups() { |
| 584 List<ImplicitRefGroup*>* ref_groups = ImplicitRefGroups(); | 589 for (int i = 0; i < implicit_ref_groups_.length(); i++) { |
| 585 for (int i = 0; i< ref_groups->length(); i++) { | 590 delete implicit_ref_groups_.at(i); |
| 586 delete ref_groups->at(i); | |
| 587 } | 591 } |
| 588 ref_groups->Clear(); | 592 implicit_ref_groups_.Clear(); |
| 589 } | 593 } |
| 590 | 594 |
| 591 | 595 |
| 592 } } // namespace v8::internal | 596 } } // namespace v8::internal |
| OLD | NEW |