Revision: 11062
Author: [email protected]
Date: Thu Mar 15 10:09:01 2012
Log: Merged r10400, r10499 into 3.7 branch.
Provide a way for iterating through all external strings referenced from
the JS heap Review URL: http://codereview.chromium.org/9139018
Provide access to function inferred name in v8 public API Review URL:
https://chromiumcodereview.appspot.com/9146039
[email protected]
Review URL: https://chromiumcodereview.appspot.com/9703070
http://code.google.com/p/v8/source/detail?r=11062
Modified:
/branches/3.7/include/v8.h
/branches/3.7/src/api.cc
/branches/3.7/src/heap.cc
/branches/3.7/src/heap.h
/branches/3.7/src/version.cc
/branches/3.7/test/cctest/test-api.cc
=======================================
--- /branches/3.7/include/v8.h Mon Dec 5 09:22:52 2011
+++ /branches/3.7/include/v8.h Thu Mar 15 10:09:01 2012
@@ -1731,6 +1731,14 @@
V8EXPORT void SetName(Handle<String> name);
V8EXPORT Handle<Value> GetName() const;
+ /**
+ * Name inferred from variable or property assignment of this function.
+ * Used to facilitate debugging and profiling of JavaScript code written
+ * in an OO style, where many functions are anonymous but are assigned
+ * to object properties.
+ */
+ V8EXPORT Handle<Value> GetInferredName() const;
+
/**
* Returns zero based line number of function body and
* kLineOffsetNotFound if no information available.
@@ -2845,6 +2853,17 @@
*/
typedef bool (*EntropySource)(unsigned char* buffer, size_t length);
+
+/**
+ * Interface for iterating though all external resources in the heap.
+ */
+class V8EXPORT ExternalResourceVisitor { // NOLINT
+ public:
+ virtual ~ExternalResourceVisitor() {}
+ virtual void VisitExternalString(Handle<String> string) {}
+};
+
+
/**
* Container class for static utility functions.
*/
@@ -3187,6 +3206,13 @@
*/
static void GetHeapStatistics(HeapStatistics* heap_statistics);
+ /**
+ * Iterates through all external resources referenced from current
isolate
+ * heap. This method is not expected to be used except for debugging
purposes
+ * and may be quite slow.
+ */
+ static void VisitExternalResources(ExternalResourceVisitor* visitor);
+
/**
* Optional notification that the embedder is idle.
* V8 uses the notification to reduce memory footprint.
=======================================
--- /branches/3.7/src/api.cc Fri Dec 9 04:01:59 2011
+++ /branches/3.7/src/api.cc Thu Mar 15 10:09:01 2012
@@ -3597,6 +3597,12 @@
i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
return Utils::ToLocal(i::Handle<i::Object>(func->shared()->name()));
}
+
+
+Handle<Value> Function::GetInferredName() const {
+ i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
+ return
Utils::ToLocal(i::Handle<i::Object>(func->shared()->inferred_name()));
+}
ScriptOrigin Function::GetScriptOrigin() const {
@@ -4025,6 +4031,13 @@
heap_statistics->set_used_heap_size(heap->SizeOfObjects());
heap_statistics->set_heap_size_limit(heap->MaxReserved());
}
+
+
+void v8::V8::VisitExternalResources(ExternalResourceVisitor* visitor) {
+ i::Isolate* isolate = i::Isolate::Current();
+ IsDeadCheck(isolate, "v8::V8::VisitExternalResources");
+ isolate->heap()->VisitExternalResources(visitor);
+}
bool v8::V8::IdleNotification() {
=======================================
--- /branches/3.7/src/heap.cc Tue Mar 6 02:14:35 2012
+++ /branches/3.7/src/heap.cc Thu Mar 15 10:09:01 2012
@@ -1351,6 +1351,28 @@
// Update the head of the list of contexts.
global_contexts_list_ = head;
}
+
+
+void Heap::VisitExternalResources(v8::ExternalResourceVisitor* visitor) {
+ AssertNoAllocation no_allocation;
+
+ class VisitorAdapter : public ObjectVisitor {
+ public:
+ explicit VisitorAdapter(v8::ExternalResourceVisitor* visitor)
+ : visitor_(visitor) {}
+ virtual void VisitPointers(Object** start, Object** end) {
+ for (Object** p = start; p < end; p++) {
+ if ((*p)->IsExternalString()) {
+ visitor_->VisitExternalString(Utils::ToLocal(
+ Handle<String>(String::cast(*p))));
+ }
+ }
+ }
+ private:
+ v8::ExternalResourceVisitor* visitor_;
+ } visitor_adapter(visitor);
+ external_string_table_.Iterate(&visitor_adapter);
+}
class NewSpaceScavenger : public StaticNewSpaceVisitor<NewSpaceScavenger> {
=======================================
--- /branches/3.7/src/heap.h Wed Feb 29 08:32:56 2012
+++ /branches/3.7/src/heap.h Thu Mar 15 10:09:01 2012
@@ -1405,6 +1405,8 @@
void ProcessWeakReferences(WeakObjectRetainer* retainer);
+ void VisitExternalResources(v8::ExternalResourceVisitor* visitor);
+
// Helper function that governs the promotion policy from new space to
// old. If the object's old address lies below the new space's age
// mark or if we've already filled the bottom 1/16th of the to space,
=======================================
--- /branches/3.7/src/version.cc Tue Mar 13 08:13:23 2012
+++ /branches/3.7/src/version.cc Thu Mar 15 10:09:01 2012
@@ -35,7 +35,7 @@
#define MAJOR_VERSION 3
#define MINOR_VERSION 7
#define BUILD_NUMBER 12
-#define PATCH_LEVEL 30
+#define PATCH_LEVEL 31
// Use 1 for candidates and 0 otherwise.
// (Boolean macro values are not supported by all preprocessors.)
#define IS_CANDIDATE_VERSION 0
=======================================
--- /branches/3.7/test/cctest/test-api.cc Mon Dec 5 09:22:52 2011
+++ /branches/3.7/test/cctest/test-api.cc Thu Mar 15 10:09:01 2012
@@ -13534,6 +13534,59 @@
CHECK_NE(static_cast<int>(heap_statistics.total_heap_size()), 0);
CHECK_NE(static_cast<int>(heap_statistics.used_heap_size()), 0);
}
+
+
+class VisitorImpl : public v8::ExternalResourceVisitor {
+ public:
+ VisitorImpl(TestResource* r1, TestResource* r2)
+ : resource1_(r1),
+ resource2_(r2),
+ found_resource1_(false),
+ found_resource2_(false) {}
+ virtual ~VisitorImpl() {}
+ virtual void VisitExternalString(v8::Handle<v8::String> string) {
+ if (!string->IsExternal()) {
+ CHECK(string->IsExternalAscii());
+ return;
+ }
+ v8::String::ExternalStringResource* resource =
+ string->GetExternalStringResource();
+ CHECK(resource);
+ if (resource1_ == resource) {
+ CHECK(!found_resource1_);
+ found_resource1_ = true;
+ }
+ if (resource2_ == resource) {
+ CHECK(!found_resource2_);
+ found_resource2_ = true;
+ }
+ }
+ void CheckVisitedResources() {
+ CHECK(found_resource1_);
+ CHECK(found_resource2_);
+ }
+
+ private:
+ v8::String::ExternalStringResource* resource1_;
+ v8::String::ExternalStringResource* resource2_;
+ bool found_resource1_;
+ bool found_resource2_;
+};
+
+TEST(VisitExternalStrings) {
+ v8::HandleScope scope;
+ LocalContext env;
+ const char* string = "Some string";
+ uint16_t* two_byte_string = AsciiToTwoByteString(string);
+ TestResource* resource1 = new TestResource(two_byte_string);
+ v8::Local<v8::String> string1 = v8::String::NewExternal(resource1);
+ TestResource* resource2 = new TestResource(two_byte_string);
+ v8::Local<v8::String> string2 = v8::String::NewExternal(resource2);
+
+ VisitorImpl visitor(resource1, resource2);
+ v8::V8::VisitExternalResources(&visitor);
+ visitor.CheckVisitedResources();
+}
static double DoubleFromBits(uint64_t value) {
@@ -13797,6 +13850,17 @@
CHECK_EQ(0, script_origin_g.ResourceLineOffset()->Int32Value());
}
+THREADED_TEST(FunctionGetInferredName) {
+ v8::HandleScope scope;
+ LocalContext env;
+ v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test"));
+ v8::Handle<v8::String> script = v8::String::New(
+ "var foo = { bar : { baz : function() {}}}; var f = foo.bar.baz;");
+ v8::Script::Compile(script, &origin)->Run();
+ v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast(
+ env->Global()->Get(v8::String::New("f")));
+ CHECK_EQ("foo.bar.baz", *v8::String::AsciiValue(f->GetInferredName()));
+}
THREADED_TEST(ScriptLineNumber) {
v8::HandleScope scope;
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev