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

Unified Diff: src/api.cc

Issue 467037: External string table. (Closed)
Patch Set: Created 11 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/v8.h ('k') | src/global-handles.cc » ('j') | src/heap.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 93807a7c72c1401f7c7b5faa92b560aae07f640b..d793b9f11c8e004060651b7fbfebf05254e6e4ff 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -3082,81 +3082,13 @@ i::Handle<i::String> NewExternalAsciiStringHandle(
}
-static void DisposeExternalString(v8::Persistent<v8::Value> obj,
- void* parameter) {
- ENTER_V8;
- i::ExternalTwoByteString* str =
- i::ExternalTwoByteString::cast(*Utils::OpenHandle(*obj));
-
- // External symbols are deleted when they are pruned out of the symbol
- // table. Generally external symbols are not registered with the weak handle
- // callbacks unless they are upgraded to a symbol after being externalized.
- if (!str->IsSymbol()) {
- v8::String::ExternalStringResource* resource =
- reinterpret_cast<v8::String::ExternalStringResource*>(parameter);
- if (resource != NULL) {
- const int total_size =
- static_cast<int>(resource->length() * sizeof(*resource->data()));
- i::Counters::total_external_string_memory.Decrement(total_size);
-
- // The object will continue to live in the JavaScript heap until the
- // handle is entirely cleaned out by the next GC. For example the
- // destructor for the resource below could bring it back to life again.
- // Which is why we make sure to not have a dangling pointer here.
- str->set_resource(NULL);
- delete resource;
- }
- }
-
- // In any case we do not need this handle any longer.
- obj.Dispose();
-}
-
-
-static void DisposeExternalAsciiString(v8::Persistent<v8::Value> obj,
- void* parameter) {
- ENTER_V8;
- i::ExternalAsciiString* str =
- i::ExternalAsciiString::cast(*Utils::OpenHandle(*obj));
-
- // External symbols are deleted when they are pruned out of the symbol
- // table. Generally external symbols are not registered with the weak handle
- // callbacks unless they are upgraded to a symbol after being externalized.
- if (!str->IsSymbol()) {
- v8::String::ExternalAsciiStringResource* resource =
- reinterpret_cast<v8::String::ExternalAsciiStringResource*>(parameter);
- if (resource != NULL) {
- const int total_size =
- static_cast<int>(resource->length() * sizeof(*resource->data()));
- i::Counters::total_external_string_memory.Decrement(total_size);
-
- // The object will continue to live in the JavaScript heap until the
- // handle is entirely cleaned out by the next GC. For example the
- // destructor for the resource below could bring it back to life again.
- // Which is why we make sure to not have a dangling pointer here.
- str->set_resource(NULL);
- delete resource;
- }
- }
-
- // In any case we do not need this handle any longer.
- obj.Dispose();
-}
-
-
Local<String> v8::String::NewExternal(
v8::String::ExternalStringResource* resource) {
EnsureInitialized("v8::String::NewExternal()");
LOG_API("String::NewExternal");
ENTER_V8;
- const int total_size =
- static_cast<int>(resource->length() * sizeof(*resource->data()));
- i::Counters::total_external_string_memory.Increment(total_size);
i::Handle<i::String> result = NewExternalStringHandle(resource);
- i::Handle<i::Object> handle = i::GlobalHandles::Create(*result);
- i::GlobalHandles::MakeWeak(handle.location(),
- resource,
- &DisposeExternalString);
+ i::ExternalStringTable::AddString(*result);
return Utils::ToLocal(result);
}
@@ -3168,13 +3100,7 @@ bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) {
i::Handle<i::String> obj = Utils::OpenHandle(this);
bool result = obj->MakeExternal(resource);
if (result && !obj->IsSymbol()) {
- // Operation was successful and the string is not a symbol. In this case
- // we need to make sure that the we call the destructor for the external
- // resource when no strong references to the string remain.
- i::Handle<i::Object> handle = i::GlobalHandles::Create(*obj);
- i::GlobalHandles::MakeWeak(handle.location(),
- resource,
- &DisposeExternalString);
+ i::ExternalStringTable::AddString(*obj);
}
return result;
}
@@ -3185,14 +3111,8 @@ Local<String> v8::String::NewExternal(
EnsureInitialized("v8::String::NewExternal()");
LOG_API("String::NewExternal");
ENTER_V8;
- const int total_size =
- static_cast<int>(resource->length() * sizeof(*resource->data()));
- i::Counters::total_external_string_memory.Increment(total_size);
i::Handle<i::String> result = NewExternalAsciiStringHandle(resource);
- i::Handle<i::Object> handle = i::GlobalHandles::Create(*result);
- i::GlobalHandles::MakeWeak(handle.location(),
- resource,
- &DisposeExternalAsciiString);
+ i::ExternalStringTable::AddString(*result);
return Utils::ToLocal(result);
}
@@ -3205,13 +3125,7 @@ bool v8::String::MakeExternal(
i::Handle<i::String> obj = Utils::OpenHandle(this);
bool result = obj->MakeExternal(resource);
if (result && !obj->IsSymbol()) {
- // Operation was successful and the string is not a symbol. In this case
- // we need to make sure that the we call the destructor for the external
- // resource when no strong references to the string remain.
- i::Handle<i::Object> handle = i::GlobalHandles::Create(*obj);
- i::GlobalHandles::MakeWeak(handle.location(),
- resource,
- &DisposeExternalAsciiString);
+ i::ExternalStringTable::AddString(*obj);
}
return result;
}
« no previous file with comments | « include/v8.h ('k') | src/global-handles.cc » ('j') | src/heap.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698