Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Side by Side Diff: src/global-handles.cc

Issue 6683022: [Isolates] Merge 7111:7152 from bleeding_edge to isolates. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/isolates/
Patch Set: Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/global-handles.h ('k') | src/heap.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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;
50 class_id_ = v8::HeapProfiler::kPersistentHandleNoClassId;
44 state_ = NORMAL; 51 state_ = NORMAL;
45 parameter_or_next_free_.parameter = NULL; 52 parameter_or_next_free_.parameter = NULL;
46 callback_ = NULL; 53 callback_ = NULL;
47 } 54 }
48 55
49 Node() { 56 Node() {
50 state_ = DESTROYED; 57 state_ = DESTROYED;
51 } 58 }
52 59
53 explicit Node(Object* object) { 60 explicit Node(Object* object) {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 138
132 bool IsNearDeath() { 139 bool IsNearDeath() {
133 // Check for PENDING to ensure correct answer when processing callbacks. 140 // Check for PENDING to ensure correct answer when processing callbacks.
134 return state_ == PENDING || state_ == NEAR_DEATH; 141 return state_ == PENDING || state_ == NEAR_DEATH;
135 } 142 }
136 143
137 bool IsWeak() { 144 bool IsWeak() {
138 return state_ == WEAK; 145 return state_ == WEAK;
139 } 146 }
140 147
148 bool CanBeRetainer() {
149 return state_ != DESTROYED && state_ != NEAR_DEATH;
150 }
151
152 void SetWrapperClassId(uint16_t class_id) {
153 class_id_ = class_id;
154 }
155
141 // Returns the id for this weak handle. 156 // Returns the id for this weak handle.
142 void set_parameter(void* parameter) { 157 void set_parameter(void* parameter) {
143 ASSERT(state_ != DESTROYED); 158 ASSERT(state_ != DESTROYED);
144 parameter_or_next_free_.parameter = parameter; 159 parameter_or_next_free_.parameter = parameter;
145 } 160 }
146 void* parameter() { 161 void* parameter() {
147 ASSERT(state_ != DESTROYED); 162 ASSERT(state_ != DESTROYED);
148 return parameter_or_next_free_.parameter; 163 return parameter_or_next_free_.parameter;
149 } 164 }
150 165
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 } 200 }
186 // Absense of explicit cleanup or revival of weak handle 201 // Absense of explicit cleanup or revival of weak handle
187 // in most of the cases would lead to memory leak. 202 // in most of the cases would lead to memory leak.
188 ASSERT(state_ != NEAR_DEATH); 203 ASSERT(state_ != NEAR_DEATH);
189 return true; 204 return true;
190 } 205 }
191 206
192 // Place the handle address first to avoid offset computation. 207 // Place the handle address first to avoid offset computation.
193 Object* object_; // Storage for object pointer. 208 Object* object_; // Storage for object pointer.
194 209
210 uint16_t class_id_;
211
195 // Transition diagram: 212 // Transition diagram:
196 // NORMAL <-> WEAK -> PENDING -> NEAR_DEATH -> { NORMAL, WEAK, DESTROYED } 213 // NORMAL <-> WEAK -> PENDING -> NEAR_DEATH -> { NORMAL, WEAK, DESTROYED }
197 enum State { 214 enum State {
198 NORMAL, // Normal global handle. 215 NORMAL, // Normal global handle.
199 WEAK, // Flagged as weak but not yet finalized. 216 WEAK, // Flagged as weak but not yet finalized.
200 PENDING, // Has been recognized as only reachable by weak handles. 217 PENDING, // Has been recognized as only reachable by weak handles.
201 NEAR_DEATH, // Callback has informed the handle is near death. 218 NEAR_DEATH, // Callback has informed the handle is near death.
202 DESTROYED 219 DESTROYED
203 }; 220 };
204 State state_; 221 State state_ : 4; // Need one more bit for MSVC as it treats enums as signed.
205 222
206 private: 223 private:
207 // Handle specific callback. 224 // Handle specific callback.
208 WeakReferenceCallback callback_; 225 WeakReferenceCallback callback_;
209 // Provided data for callback. In DESTROYED state, this is used for 226 // Provided data for callback. In DESTROYED state, this is used for
210 // the free list link. 227 // the free list link.
211 union { 228 union {
212 void* parameter; 229 void* parameter;
213 Node* next_free; 230 Node* next_free;
214 } parameter_or_next_free_; 231 } parameter_or_next_free_;
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 bool GlobalHandles::IsNearDeath(Object** location) { 365 bool GlobalHandles::IsNearDeath(Object** location) {
349 return Node::FromLocation(location)->IsNearDeath(); 366 return Node::FromLocation(location)->IsNearDeath();
350 } 367 }
351 368
352 369
353 bool GlobalHandles::IsWeak(Object** location) { 370 bool GlobalHandles::IsWeak(Object** location) {
354 return Node::FromLocation(location)->IsWeak(); 371 return Node::FromLocation(location)->IsWeak();
355 } 372 }
356 373
357 374
375 void GlobalHandles::SetWrapperClassId(Object** location, uint16_t class_id) {
376 Node::FromLocation(location)->SetWrapperClassId(class_id);
377 }
378
379
358 void GlobalHandles::IterateWeakRoots(ObjectVisitor* v) { 380 void GlobalHandles::IterateWeakRoots(ObjectVisitor* v) {
359 // Traversal of GC roots in the global handle list that are marked as 381 // Traversal of GC roots in the global handle list that are marked as
360 // WEAK or PENDING. 382 // WEAK or PENDING.
361 for (Node* current = head_; current != NULL; current = current->next()) { 383 for (Node* current = head_; current != NULL; current = current->next()) {
362 if (current->state_ == Node::WEAK 384 if (current->state_ == Node::WEAK
363 || current->state_ == Node::PENDING 385 || current->state_ == Node::PENDING
364 || current->state_ == Node::NEAR_DEATH) { 386 || current->state_ == Node::NEAR_DEATH) {
365 v->VisitPointer(&current->object_); 387 v->VisitPointer(&current->object_);
366 } 388 }
367 } 389 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 466
445 void GlobalHandles::IterateAllRoots(ObjectVisitor* v) { 467 void GlobalHandles::IterateAllRoots(ObjectVisitor* v) {
446 for (Node* current = head_; current != NULL; current = current->next()) { 468 for (Node* current = head_; current != NULL; current = current->next()) {
447 if (current->state_ != Node::DESTROYED) { 469 if (current->state_ != Node::DESTROYED) {
448 v->VisitPointer(&current->object_); 470 v->VisitPointer(&current->object_);
449 } 471 }
450 } 472 }
451 } 473 }
452 474
453 475
476 void GlobalHandles::IterateAllRootsWithClassIds(ObjectVisitor* v) {
477 for (Node* current = head_; current != NULL; current = current->next()) {
478 if (current->class_id_ != v8::HeapProfiler::kPersistentHandleNoClassId &&
479 current->CanBeRetainer()) {
480 v->VisitEmbedderReference(&current->object_, current->class_id_);
481 }
482 }
483 }
484
485
454 void GlobalHandles::TearDown() { 486 void GlobalHandles::TearDown() {
455 // Reset all the lists. 487 // Reset all the lists.
456 set_head(NULL); 488 set_head(NULL);
457 set_first_free(NULL); 489 set_first_free(NULL);
458 set_first_deallocated(NULL); 490 set_first_deallocated(NULL);
459 pool_->Release(); 491 pool_->Release();
460 } 492 }
461 493
462 494
463 void GlobalHandles::RecordStats(HeapStats* stats) { 495 void GlobalHandles::RecordStats(HeapStats* stats) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 PrintF(" handle %p to %p (weak=%d)\n", 544 PrintF(" handle %p to %p (weak=%d)\n",
513 reinterpret_cast<void*>(current->handle().location()), 545 reinterpret_cast<void*>(current->handle().location()),
514 reinterpret_cast<void*>(*current->handle()), 546 reinterpret_cast<void*>(*current->handle()),
515 current->state_ == Node::WEAK); 547 current->state_ == Node::WEAK);
516 } 548 }
517 } 549 }
518 550
519 #endif 551 #endif
520 552
521 553
522 void GlobalHandles::AddGroup(Object*** handles, size_t length) { 554 void GlobalHandles::AddGroup(Object*** handles,
523 ObjectGroup* new_entry = new ObjectGroup(length); 555 size_t length,
556 v8::RetainedObjectInfo* info) {
557 ObjectGroup* new_entry = new ObjectGroup(length, info);
524 for (size_t i = 0; i < length; ++i) 558 for (size_t i = 0; i < length; ++i)
525 new_entry->objects_.Add(handles[i]); 559 new_entry->objects_.Add(handles[i]);
526 object_groups_.Add(new_entry); 560 object_groups_.Add(new_entry);
527 } 561 }
528 562
529 563
530 void GlobalHandles::RemoveObjectGroups() { 564 void GlobalHandles::RemoveObjectGroups() {
531 for (int i = 0; i< object_groups_.length(); i++) { 565 for (int i = 0; i< object_groups_.length(); i++) {
532 delete object_groups_.at(i); 566 delete object_groups_.at(i);
533 } 567 }
534 object_groups_.Clear(); 568 object_groups_.Clear();
535 } 569 }
536 570
537 } } // namespace v8::internal 571 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/global-handles.h ('k') | src/heap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698