From be6b490fb0e1a65e06c5fb30581bb01b3f7e36f1 Mon Sep 17 00:00:00 2001 From: "iposva@chromium.org" Date: Thu, 12 Feb 2009 16:58:55 +0000 Subject: [PATCH] Remove experimental ExternalSymbolCallback feature. This is not needed since we can now transform String objects to be external when needed. Review URL: http://codereview.chromium.org/21285 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1260 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- include/v8.h | 31 -------------------------- src/api.cc | 5 ----- src/heap-inl.h | 3 --- src/heap.cc | 58 +------------------------------------------------ src/heap.h | 9 -------- test/cctest/test-api.cc | 52 -------------------------------------------- 6 files changed, 1 insertion(+), 157 deletions(-) diff --git a/include/v8.h b/include/v8.h index 5757f2a..a048acd 100644 --- a/include/v8.h +++ b/include/v8.h @@ -1828,23 +1828,6 @@ typedef void (*FailedAccessCheckCallback)(Local target, typedef void (*GCCallback)(); -// --- E x t e r n a l S y m b o l C a l l b a c k --- - -/** - * Callback used to allocate certain V8 symbols as external strings. - * - * The data passed to the callback is utf8 encoded. - * - * Allocations are not allowed in the callback function, you therefore - * cannot manipulate objects (set or delete properties for example) - * since it is possible such operations will result in the allocation - * of objects. - */ -typedef String::ExternalStringResource* (*ExternalSymbolCallback)( - const char* utf8, - size_t length); - - // --- C o n t e x t G e n e r a t o r --- /** @@ -1945,20 +1928,6 @@ class EXPORT V8 { static void SetGlobalGCEpilogueCallback(GCCallback); /** - * Applications can register a callback that will be used when - * allocating most of the V8 symbols. The callback must return an - * external string resource that represents the symbols. - * - * Most often when performing a property lookup the key will be a - * symbol. Allocating symbols as external strings can reduce the - * amount of string conversions needed when using interceptors and - * accessors. - * - * \note This is an experimental feature and it might be removed. - */ - static void SetExternalSymbolCallback(ExternalSymbolCallback); - - /** * Allows the host application to group objects together. If one * object in the group is alive, all objects in the group are alive. * After each garbage collection, object groups are removed. It is diff --git a/src/api.cc b/src/api.cc index 2d64444..c995df5 100644 --- a/src/api.cc +++ b/src/api.cc @@ -2720,11 +2720,6 @@ void V8::SetGlobalGCEpilogueCallback(GCCallback callback) { } -void V8::SetExternalSymbolCallback(ExternalSymbolCallback callback) { - if (IsDeadCheck("v8::V8::SetExternalSymbolCallback()")) return; - i::Heap::SetExternalSymbolCallback(callback); -} - void V8::PauseProfiler() { #ifdef ENABLE_LOGGING_AND_PROFILING i::Logger::PauseProfiler(); diff --git a/src/heap-inl.h b/src/heap-inl.h index 07d92c1..3c9733d 100644 --- a/src/heap-inl.h +++ b/src/heap-inl.h @@ -41,9 +41,6 @@ int Heap::MaxHeapObjectSize() { Object* Heap::AllocateSymbol(Vector str, int chars, uint32_t length_field) { - if (global_external_symbol_callback_) { - return AllocateExternalSymbol(str, chars); - } unibrow::Utf8InputBuffer<> buffer(str.start(), static_cast(str.length())); return AllocateInternalSymbol(&buffer, chars, length_field); diff --git a/src/heap.cc b/src/heap.cc index 869b33c..72f427e 100644 --- a/src/heap.cc +++ b/src/heap.cc @@ -84,8 +84,6 @@ int Heap::initial_semispace_size_ = 256*KB; GCCallback Heap::global_gc_prologue_callback_ = NULL; GCCallback Heap::global_gc_epilogue_callback_ = NULL; -ExternalSymbolCallback Heap::global_external_symbol_callback_ = NULL; - // Variables set based on semispace_size_ and old_generation_size_ in // ConfigureHeap. int Heap::young_generation_size_ = 0; // Will be 2 * semispace_size_. @@ -1533,22 +1531,6 @@ Object* Heap::AllocateExternalStringFromTwoByte( } -Object* Heap::AllocateExternalSymbolFromTwoByte( - ExternalTwoByteString::Resource* resource) { - int length = resource->length(); - - Map* map = ExternalTwoByteString::SymbolMap(length); - Object* result = Allocate(map, OLD_DATA_SPACE); - if (result->IsFailure()) return result; - - ExternalTwoByteString* external_string = ExternalTwoByteString::cast(result); - external_string->set_length(length); - external_string->set_resource(resource); - - return result; -} - - Object* Heap::LookupSingleCharacterStringFromCode(uint16_t code) { if (code <= String::kMaxAsciiCharCode) { Object* value = Heap::single_character_string_cache()->get(code); @@ -2099,7 +2081,7 @@ Object* Heap::AllocateInternalSymbol(unibrow::CharacterStream* buffer, ASSERT(static_cast(chars) == buffer->Length()); // Determine whether the string is ascii. bool is_ascii = true; - while (buffer->has_more()) { + while (buffer->has_more() && is_ascii) { if (buffer->GetNext() > unibrow::Utf8::kMaxOneByteChar) is_ascii = false; } buffer->Rewind(); @@ -2150,44 +2132,6 @@ Object* Heap::AllocateInternalSymbol(unibrow::CharacterStream* buffer, } -// External string resource that only contains a length field. These -// are used temporarily when allocating external symbols. -class DummyExternalStringResource - : public v8::String::ExternalStringResource { - public: - explicit DummyExternalStringResource(size_t length) : length_(length) { } - - virtual const uint16_t* data() const { - UNREACHABLE(); - return NULL; - } - - virtual size_t length() const { return length_; } - private: - size_t length_; -}; - - -Object* Heap::AllocateExternalSymbol(Vector string, int chars) { - // Attempt to allocate the resulting external string first. Use a - // dummy string resource that has the correct length so that we only - // have to patch the external string resource after the callback. - DummyExternalStringResource dummy_resource(chars); - Object* obj = AllocateExternalSymbolFromTwoByte(&dummy_resource); - if (obj->IsFailure()) return obj; - // Perform callback. - v8::String::ExternalStringResource* resource = - global_external_symbol_callback_(string.start(), string.length()); - // Patch the resource pointer of the result. - ExternalTwoByteString* result = ExternalTwoByteString::cast(obj); - result->set_resource(resource); - // Force hash code to be computed. - result->Hash(); - ASSERT(result->IsEqualTo(string)); - return result; -} - - Object* Heap::AllocateRawAsciiString(int length, PretenureFlag pretenure) { AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; int size = SeqAsciiString::SizeFor(length); diff --git a/src/heap.h b/src/heap.h index fd98869..f1cb8ee 100644 --- a/src/heap.h +++ b/src/heap.h @@ -544,8 +544,6 @@ class Heap : public AllStatic { ExternalAsciiString::Resource* resource); static Object* AllocateExternalStringFromTwoByte( ExternalTwoByteString::Resource* resource); - static Object* AllocateExternalSymbolFromTwoByte( - ExternalTwoByteString::Resource* resource); // Allocates an uninitialized object. The memory is non-executable if the // hardware and OS allow. @@ -624,10 +622,6 @@ class Heap : public AllStatic { global_gc_epilogue_callback_ = callback; } - static void SetExternalSymbolCallback(ExternalSymbolCallback callback) { - global_external_symbol_callback_ = callback; - } - // Heap roots #define ROOT_ACCESSOR(type, name) static type* name() { return name##_; } ROOT_LIST(ROOT_ACCESSOR) @@ -887,9 +881,6 @@ class Heap : public AllStatic { static GCCallback global_gc_prologue_callback_; static GCCallback global_gc_epilogue_callback_; - // Callback function used for allocating external symbols. - static ExternalSymbolCallback global_external_symbol_callback_; - // Checks whether a global GC is necessary static GarbageCollector SelectGarbageCollector(AllocationSpace space); diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc index 1638baa..4f2a2b1 100644 --- a/test/cctest/test-api.cc +++ b/test/cctest/test-api.cc @@ -5589,58 +5589,6 @@ THREADED_TEST(AccessControlRepeatedContextCreation) { } -static String::ExternalStringResource* SymbolCallback(const char* chars, - size_t length) { - uint16_t* buffer = i::NewArray(length + 1); - for (size_t i = 0; i < length; i++) { - buffer[i] = chars[i]; - } - buffer[length] = '\0'; - return new TestResource(buffer); -} - - -static v8::Handle ExternalSymbolGetter(Local name, - const AccessorInfo& info) { - ApiTestFuzzer::Fuzz(); - CHECK(!name->Equals(v8_str("externalSymbol722")) || name->IsExternal()); - return v8::True(); -} - - -static void ExternalSymbolSetter(Local name, - Local value, - const AccessorInfo&) { - ApiTestFuzzer::Fuzz(); - CHECK(!name->Equals(v8_str("externalSymbol722")) || name->IsExternal()); -} - - -THREADED_TEST(ExternalSymbols) { - TestResource::dispose_count = 0; - v8::V8::SetExternalSymbolCallback(SymbolCallback); - v8::HandleScope scope; - LocalContext context; - Local templ = ObjectTemplate::New(); - // Use a bizare name so that the name does not clash with names used - // in natives files. If running with snapshots enabled, variable - // names used in the native files will be normal symbols instead of - // external ones. Also, make sure that the bizare name is used from - // JavaScript code before using it from C++ code. - Local value = - CompileRun("var o = { externalSymbol722: 42 }; o.externalSymbol722"); - CHECK_EQ(42, value->Int32Value()); - templ->SetAccessor(v8_str("externalSymbol722"), - ExternalSymbolGetter, - ExternalSymbolSetter); - context->Global()->Set(v8_str("obj"), templ->NewInstance()); - value = CompileRun("obj.externalSymbol722"); - CHECK_EQ(true, value->BooleanValue()); - value = CompileRun("obj.externalSymbol722 = 42"); - v8::V8::SetExternalSymbolCallback(NULL); -} - - // This test verifies that pre-compilation (aka preparsing) can be called // without initializing the whole VM. Thus we cannot run this test in a // multi-threaded setup. -- 2.7.4