| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_API_H_ | 5 #ifndef V8_API_H_ |
| 6 #define V8_API_H_ | 6 #define V8_API_H_ |
| 7 | 7 |
| 8 #include "src/v8.h" | 8 #include "src/v8.h" |
| 9 | 9 |
| 10 #include "include/v8-testing.h" | 10 #include "include/v8-testing.h" |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 } | 399 } |
| 400 | 400 |
| 401 OPEN_HANDLE_LIST(MAKE_OPEN_HANDLE) | 401 OPEN_HANDLE_LIST(MAKE_OPEN_HANDLE) |
| 402 | 402 |
| 403 #undef MAKE_OPEN_HANDLE | 403 #undef MAKE_OPEN_HANDLE |
| 404 #undef OPEN_HANDLE_LIST | 404 #undef OPEN_HANDLE_LIST |
| 405 | 405 |
| 406 | 406 |
| 407 namespace internal { | 407 namespace internal { |
| 408 | 408 |
| 409 // Tracks string usage to help make better decisions when | |
| 410 // externalizing strings. | |
| 411 // | |
| 412 // Implementation note: internally this class only tracks fresh | |
| 413 // strings and keeps a single use counter for them. | |
| 414 class StringTracker { | |
| 415 public: | |
| 416 // Records that the given string's characters were copied to some | |
| 417 // external buffer. If this happens often we should honor | |
| 418 // externalization requests for the string. | |
| 419 void RecordWrite(Handle<String> string) { | |
| 420 Address address = reinterpret_cast<Address>(*string); | |
| 421 Address top = isolate_->heap()->NewSpaceTop(); | |
| 422 if (IsFreshString(address, top)) { | |
| 423 IncrementUseCount(top); | |
| 424 } | |
| 425 } | |
| 426 | |
| 427 // Estimates freshness and use frequency of the given string based | |
| 428 // on how close it is to the new space top and the recorded usage | |
| 429 // history. | |
| 430 inline bool IsFreshUnusedString(Handle<String> string) { | |
| 431 Address address = reinterpret_cast<Address>(*string); | |
| 432 Address top = isolate_->heap()->NewSpaceTop(); | |
| 433 return IsFreshString(address, top) && IsUseCountLow(top); | |
| 434 } | |
| 435 | |
| 436 private: | |
| 437 StringTracker() : use_count_(0), last_top_(NULL), isolate_(NULL) { } | |
| 438 | |
| 439 static inline bool IsFreshString(Address string, Address top) { | |
| 440 return top - kFreshnessLimit <= string && string <= top; | |
| 441 } | |
| 442 | |
| 443 inline bool IsUseCountLow(Address top) { | |
| 444 if (last_top_ != top) return true; | |
| 445 return use_count_ < kUseLimit; | |
| 446 } | |
| 447 | |
| 448 inline void IncrementUseCount(Address top) { | |
| 449 if (last_top_ != top) { | |
| 450 use_count_ = 0; | |
| 451 last_top_ = top; | |
| 452 } | |
| 453 ++use_count_; | |
| 454 } | |
| 455 | |
| 456 // Single use counter shared by all fresh strings. | |
| 457 int use_count_; | |
| 458 | |
| 459 // Last new space top when the use count above was valid. | |
| 460 Address last_top_; | |
| 461 | |
| 462 Isolate* isolate_; | |
| 463 | |
| 464 // How close to the new space top a fresh string has to be. | |
| 465 static const int kFreshnessLimit = 1024; | |
| 466 | |
| 467 // The number of uses required to consider a string useful. | |
| 468 static const int kUseLimit = 32; | |
| 469 | |
| 470 friend class Isolate; | |
| 471 | |
| 472 DISALLOW_COPY_AND_ASSIGN(StringTracker); | |
| 473 }; | |
| 474 | |
| 475 | 409 |
| 476 class DeferredHandles { | 410 class DeferredHandles { |
| 477 public: | 411 public: |
| 478 ~DeferredHandles(); | 412 ~DeferredHandles(); |
| 479 | 413 |
| 480 private: | 414 private: |
| 481 DeferredHandles(Object** first_block_limit, Isolate* isolate) | 415 DeferredHandles(Object** first_block_limit, Isolate* isolate) |
| 482 : next_(NULL), | 416 : next_(NULL), |
| 483 previous_(NULL), | 417 previous_(NULL), |
| 484 first_block_limit_(first_block_limit), | 418 first_block_limit_(first_block_limit), |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 stress_type_ = stress_type; | 639 stress_type_ = stress_type; |
| 706 } | 640 } |
| 707 | 641 |
| 708 private: | 642 private: |
| 709 static v8::Testing::StressType stress_type_; | 643 static v8::Testing::StressType stress_type_; |
| 710 }; | 644 }; |
| 711 | 645 |
| 712 } } // namespace v8::internal | 646 } } // namespace v8::internal |
| 713 | 647 |
| 714 #endif // V8_API_H_ | 648 #endif // V8_API_H_ |
| OLD | NEW |