From: jochen@chromium.org Date: Mon, 23 Jun 2014 09:46:58 +0000 (+0000) Subject: Add a use counter API X-Git-Tag: upstream/4.7.83~8613 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ce02221828185d864a1b9226478afd8ce50b6661;p=platform%2Fupstream%2Fv8.git Add a use counter API This lets embedders track certain features of v8 and the number of times they are used BUG=none R=svenpanne@chromium.org, marja@chromium.org LOG=y Review URL: https://codereview.chromium.org/346233002 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21925 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/include/v8.h b/include/v8.h index f6c6ac3..bc2ea0b 100644 --- a/include/v8.h +++ b/include/v8.h @@ -4129,6 +4129,19 @@ class V8_EXPORT Isolate { }; /** + * Features reported via the SetUseCounterCallback callback. Do not chang + * assigned numbers of existing items; add new features to the end of this + * list. + */ + enum UseCounterFeature { + kUseAsm = 0 + }; + + typedef void (*UseCounterCallback)(Isolate* isolate, + UseCounterFeature feature); + + + /** * Creates a new isolate. Does not change the currently entered * isolate. * @@ -4397,6 +4410,11 @@ class V8_EXPORT Isolate { */ bool WillAutorunMicrotasks() const; + /** + * Sets a callback for counting the number of times a feature of V8 is used. + */ + void SetUseCounterCallback(UseCounterCallback callback); + private: template friend class PersistentValueMap; diff --git a/src/api.cc b/src/api.cc index 9397c40..f076bdb 100644 --- a/src/api.cc +++ b/src/api.cc @@ -6718,6 +6718,11 @@ bool Isolate::WillAutorunMicrotasks() const { } +void Isolate::SetUseCounterCallback(UseCounterCallback callback) { + reinterpret_cast(this)->SetUseCounterCallback(callback); +} + + String::Utf8Value::Utf8Value(v8::Handle obj) : str_(NULL), length_(0) { i::Isolate* isolate = i::Isolate::Current(); diff --git a/src/isolate.cc b/src/isolate.cc index a4b311f..d4368da 100644 --- a/src/isolate.cc +++ b/src/isolate.cc @@ -2343,6 +2343,19 @@ void Isolate::RunMicrotasks() { } +void Isolate::SetUseCounterCallback(v8::Isolate::UseCounterCallback callback) { + ASSERT(!use_counter_callback_); + use_counter_callback_ = callback; +} + + +void Isolate::CountUsage(v8::Isolate::UseCounterFeature feature) { + if (use_counter_callback_) { + use_counter_callback_(reinterpret_cast(this), feature); + } +} + + bool StackLimitCheck::JsHasOverflowed() const { StackGuard* stack_guard = isolate_->stack_guard(); #ifdef USE_SIMULATOR diff --git a/src/isolate.h b/src/isolate.h index 3cabea9..2a11873 100644 --- a/src/isolate.h +++ b/src/isolate.h @@ -1081,6 +1081,9 @@ class Isolate { void EnqueueMicrotask(Handle microtask); void RunMicrotasks(); + void SetUseCounterCallback(v8::Isolate::UseCounterCallback callback); + void CountUsage(v8::Isolate::UseCounterFeature feature); + private: Isolate(); @@ -1300,6 +1303,8 @@ class Isolate { // List of callbacks when a Call completes. List call_completed_callbacks_; + v8::Isolate::UseCounterCallback use_counter_callback_; + friend class ExecutionAccess; friend class HandleScopeImplementer; friend class IsolateInitializer;