diff options
author | Steve Block <steveblock@google.com> | 2011-05-26 01:26:41 +0100 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2011-06-02 15:09:56 +0100 |
commit | 44f0eee88ff00398ff7f715fab053374d808c90d (patch) | |
tree | addd100e906cd43f843f3aaf64b445f17f46fe0f /src/api.h | |
parent | 1b63b9ad386abd62f61af0e29246a687f5311b53 (diff) | |
download | android_external_v8-44f0eee88ff00398ff7f715fab053374d808c90d.tar.gz android_external_v8-44f0eee88ff00398ff7f715fab053374d808c90d.tar.bz2 android_external_v8-44f0eee88ff00398ff7f715fab053374d808c90d.zip |
Update V8 to r7427: Initial merge by git
As required by WebKit r82507
Change-Id: I7ae83ef3f689356043b4929255b7c1dd31d8c5df
Diffstat (limited to 'src/api.h')
-rw-r--r-- | src/api.h | 88 |
1 files changed, 76 insertions, 12 deletions
@@ -122,7 +122,7 @@ template <typename T> static inline T ToCData(v8::internal::Object* obj) { template <typename T> static inline v8::internal::Handle<v8::internal::Object> FromCData(T obj) { STATIC_ASSERT(sizeof(T) == sizeof(v8::internal::Address)); - return v8::internal::Factory::NewProxy( + return FACTORY->NewProxy( reinterpret_cast<v8::internal::Address>(reinterpret_cast<intptr_t>(obj))); } @@ -157,7 +157,6 @@ class RegisteredExtension { RegisteredExtension* next_auto_; ExtensionTraversalState state_; static RegisteredExtension* first_extension_; - static RegisteredExtension* first_auto_extension_; }; @@ -321,16 +320,83 @@ MAKE_OPEN_HANDLE(StackFrame, JSObject) namespace internal { +// Tracks string usage to help make better decisions when +// externalizing strings. +// +// Implementation note: internally this class only tracks fresh +// strings and keeps a single use counter for them. +class StringTracker { + public: + // Records that the given string's characters were copied to some + // external buffer. If this happens often we should honor + // externalization requests for the string. + void RecordWrite(Handle<String> string) { + Address address = reinterpret_cast<Address>(*string); + Address top = isolate_->heap()->NewSpaceTop(); + if (IsFreshString(address, top)) { + IncrementUseCount(top); + } + } + + // Estimates freshness and use frequency of the given string based + // on how close it is to the new space top and the recorded usage + // history. + inline bool IsFreshUnusedString(Handle<String> string) { + Address address = reinterpret_cast<Address>(*string); + Address top = isolate_->heap()->NewSpaceTop(); + return IsFreshString(address, top) && IsUseCountLow(top); + } + + private: + StringTracker() : use_count_(0), last_top_(NULL), isolate_(NULL) { } + + static inline bool IsFreshString(Address string, Address top) { + return top - kFreshnessLimit <= string && string <= top; + } + + inline bool IsUseCountLow(Address top) { + if (last_top_ != top) return true; + return use_count_ < kUseLimit; + } + + inline void IncrementUseCount(Address top) { + if (last_top_ != top) { + use_count_ = 0; + last_top_ = top; + } + ++use_count_; + } + + // Single use counter shared by all fresh strings. + int use_count_; + + // Last new space top when the use count above was valid. + Address last_top_; + + Isolate* isolate_; + + // How close to the new space top a fresh string has to be. + static const int kFreshnessLimit = 1024; + + // The number of uses required to consider a string useful. + static const int kUseLimit = 32; + + friend class Isolate; + + DISALLOW_COPY_AND_ASSIGN(StringTracker); +}; + + // This class is here in order to be able to declare it a friend of // HandleScope. Moving these methods to be members of HandleScope would be -// neat in some ways, but it would expose external implementation details in +// neat in some ways, but it would expose internal implementation details in // our public header file, which is undesirable. // -// There is a singleton instance of this class to hold the per-thread data. -// For multithreaded V8 programs this data is copied in and out of storage +// An isolate has a single instance of this class to hold the current thread's +// data. In multithreaded V8 programs this data is copied in and out of storage // so that the currently executing thread always has its own copy of this // data. -class HandleScopeImplementer { +ISOLATED_CLASS HandleScopeImplementer { public: HandleScopeImplementer() @@ -341,16 +407,14 @@ class HandleScopeImplementer { ignore_out_of_memory_(false), call_depth_(0) { } - static HandleScopeImplementer* instance(); - // Threading support for handle data. static int ArchiveSpacePerThread(); - static char* RestoreThread(char* from); - static char* ArchiveThread(char* to); - static void FreeThreadResources(); + char* RestoreThread(char* from); + char* ArchiveThread(char* to); + void FreeThreadResources(); // Garbage collection support. - static void Iterate(v8::internal::ObjectVisitor* v); + void Iterate(v8::internal::ObjectVisitor* v); static char* Iterate(v8::internal::ObjectVisitor* v, char* data); |