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

Side by Side Diff: src/api.h

Issue 251014: * Fix memory leaks caused by thread local data being lost.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 2 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 | « no previous file | src/api.cc » ('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 2008 the V8 project authors. All rights reserved. 1 // Copyright 2008 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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 // our public header file, which is undesirable. 304 // our public header file, which is undesirable.
305 // 305 //
306 // There is a singleton instance of this class to hold the per-thread data. 306 // There is a singleton instance of this class to hold the per-thread data.
307 // For multithreaded V8 programs this data is copied in and out of storage 307 // For multithreaded V8 programs this data is copied in and out of storage
308 // so that the currently executing thread always has its own copy of this 308 // so that the currently executing thread always has its own copy of this
309 // data. 309 // data.
310 class HandleScopeImplementer { 310 class HandleScopeImplementer {
311 public: 311 public:
312 312
313 HandleScopeImplementer() 313 HandleScopeImplementer()
314 : blocks(0), 314 : blocks_(0),
315 entered_contexts_(0), 315 entered_contexts_(0),
316 saved_contexts_(0) { 316 saved_contexts_(0) {
317 Initialize(); 317 Initialize();
318 } 318 }
319 319
320 void Initialize() {
321 blocks.Initialize(0);
322 entered_contexts_.Initialize(0);
323 saved_contexts_.Initialize(0);
324 spare = NULL;
325 ignore_out_of_memory = false;
326 call_depth = 0;
327 }
328
329 static HandleScopeImplementer* instance(); 320 static HandleScopeImplementer* instance();
330 321
331 // Threading support for handle data. 322 // Threading support for handle data.
332 static int ArchiveSpacePerThread(); 323 static int ArchiveSpacePerThread();
333 static char* RestoreThread(char* from); 324 static char* RestoreThread(char* from);
334 static char* ArchiveThread(char* to); 325 static char* ArchiveThread(char* to);
326 static void FreeThreadResources();
335 327
336 // Garbage collection support. 328 // Garbage collection support.
337 static void Iterate(v8::internal::ObjectVisitor* v); 329 static void Iterate(v8::internal::ObjectVisitor* v);
338 static char* Iterate(v8::internal::ObjectVisitor* v, char* data); 330 static char* Iterate(v8::internal::ObjectVisitor* v, char* data);
339 331
340 332
341 inline internal::Object** GetSpareOrNewBlock(); 333 inline internal::Object** GetSpareOrNewBlock();
342 inline void DeleteExtensions(int extensions); 334 inline void DeleteExtensions(int extensions);
343 335
344 inline void IncrementCallDepth() {call_depth++;} 336 inline void IncrementCallDepth() {call_depth_++;}
345 inline void DecrementCallDepth() {call_depth--;} 337 inline void DecrementCallDepth() {call_depth_--;}
346 inline bool CallDepthIsZero() { return call_depth == 0; } 338 inline bool CallDepthIsZero() { return call_depth_ == 0; }
347 339
348 inline void EnterContext(Handle<Object> context); 340 inline void EnterContext(Handle<Object> context);
349 inline bool LeaveLastContext(); 341 inline bool LeaveLastContext();
350 342
351 // Returns the last entered context or an empty handle if no 343 // Returns the last entered context or an empty handle if no
352 // contexts have been entered. 344 // contexts have been entered.
353 inline Handle<Object> LastEnteredContext(); 345 inline Handle<Object> LastEnteredContext();
354 346
355 inline void SaveContext(Context* context); 347 inline void SaveContext(Context* context);
356 inline Context* RestoreContext(); 348 inline Context* RestoreContext();
357 inline bool HasSavedContexts(); 349 inline bool HasSavedContexts();
358 350
359 inline List<internal::Object**>* Blocks() { return &blocks; } 351 inline List<internal::Object**>* blocks() { return &blocks_; }
360 352 inline bool ignore_out_of_memory() { return ignore_out_of_memory_; }
361 inline bool IgnoreOutOfMemory() { return ignore_out_of_memory; } 353 inline void set_ignore_out_of_memory(bool value) {
362 inline void SetIgnoreOutOfMemory(bool value) { ignore_out_of_memory = value; } 354 ignore_out_of_memory_ = value;
355 }
363 356
364 private: 357 private:
365 List<internal::Object**> blocks; 358 void Initialize() {
366 Object** spare; 359 blocks_.Initialize(0);
367 int call_depth; 360 entered_contexts_.Initialize(0);
361 saved_contexts_.Initialize(0);
362 spare_ = NULL;
363 ignore_out_of_memory_ = false;
364 call_depth_ = 0;
365 }
366
367 void Free() {
368 ASSERT(blocks_.length() == 0);
369 ASSERT(entered_contexts_.length() == 0);
370 ASSERT(saved_contexts_.length() == 0);
371 if (spare_ != NULL) {
372 DeleteArray(spare_);
373 spare_ = NULL;
374 }
375 ASSERT(call_depth_ == 0);
376 }
377
378 List<internal::Object**> blocks_;
379 Object** spare_;
380 int call_depth_;
368 // Used as a stack to keep track of entered contexts. 381 // Used as a stack to keep track of entered contexts.
369 List<Handle<Object> > entered_contexts_; 382 List<Handle<Object> > entered_contexts_;
370 // Used as a stack to keep track of saved contexts. 383 // Used as a stack to keep track of saved contexts.
371 List<Context*> saved_contexts_; 384 List<Context*> saved_contexts_;
372 bool ignore_out_of_memory; 385 bool ignore_out_of_memory_;
373 // This is only used for threading support. 386 // This is only used for threading support.
374 v8::ImplementationUtilities::HandleScopeData handle_scope_data_; 387 v8::ImplementationUtilities::HandleScopeData handle_scope_data_;
375 388
376 void IterateThis(ObjectVisitor* v); 389 void IterateThis(ObjectVisitor* v);
377 char* RestoreThreadHelper(char* from); 390 char* RestoreThreadHelper(char* from);
378 char* ArchiveThreadHelper(char* to); 391 char* ArchiveThreadHelper(char* to);
379 392
380 DISALLOW_COPY_AND_ASSIGN(HandleScopeImplementer); 393 DISALLOW_COPY_AND_ASSIGN(HandleScopeImplementer);
381 }; 394 };
382 395
(...skipping 29 matching lines...) Expand all
412 425
413 426
414 Handle<Object> HandleScopeImplementer::LastEnteredContext() { 427 Handle<Object> HandleScopeImplementer::LastEnteredContext() {
415 if (entered_contexts_.is_empty()) return Handle<Object>::null(); 428 if (entered_contexts_.is_empty()) return Handle<Object>::null();
416 return entered_contexts_.last(); 429 return entered_contexts_.last();
417 } 430 }
418 431
419 432
420 // If there's a spare block, use it for growing the current scope. 433 // If there's a spare block, use it for growing the current scope.
421 internal::Object** HandleScopeImplementer::GetSpareOrNewBlock() { 434 internal::Object** HandleScopeImplementer::GetSpareOrNewBlock() {
422 internal::Object** block = (spare != NULL) ? 435 internal::Object** block = (spare_ != NULL) ?
423 spare : 436 spare_ :
424 NewArray<internal::Object*>(kHandleBlockSize); 437 NewArray<internal::Object*>(kHandleBlockSize);
425 spare = NULL; 438 spare_ = NULL;
426 return block; 439 return block;
427 } 440 }
428 441
429 442
430 void HandleScopeImplementer::DeleteExtensions(int extensions) { 443 void HandleScopeImplementer::DeleteExtensions(int extensions) {
431 if (spare != NULL) { 444 if (spare_ != NULL) {
432 DeleteArray(spare); 445 DeleteArray(spare_);
433 spare = NULL; 446 spare_ = NULL;
434 } 447 }
435 for (int i = extensions; i > 1; --i) { 448 for (int i = extensions; i > 1; --i) {
436 internal::Object** block = blocks.RemoveLast(); 449 internal::Object** block = blocks_.RemoveLast();
437 #ifdef DEBUG 450 #ifdef DEBUG
438 v8::ImplementationUtilities::ZapHandleRange(block, 451 v8::ImplementationUtilities::ZapHandleRange(block,
439 &block[kHandleBlockSize]); 452 &block[kHandleBlockSize]);
440 #endif 453 #endif
441 DeleteArray(block); 454 DeleteArray(block);
442 } 455 }
443 spare = blocks.RemoveLast(); 456 spare_ = blocks_.RemoveLast();
444 #ifdef DEBUG 457 #ifdef DEBUG
445 v8::ImplementationUtilities::ZapHandleRange( 458 v8::ImplementationUtilities::ZapHandleRange(
446 spare, 459 spare_,
447 &spare[kHandleBlockSize]); 460 &spare_[kHandleBlockSize]);
448 #endif 461 #endif
449 } 462 }
450 463
451 } } // namespace v8::internal 464 } } // namespace v8::internal
452 465
453 #endif // V8_API_H_ 466 #endif // V8_API_H_
OLDNEW
« no previous file with comments | « no previous file | src/api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698