Revert "Handlifying clients of StringTable, step 1."

This reverts commit r20772.

TBR=jarin@chromium.org

Review URL: https://codereview.chromium.org/239273002

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20775 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
ishell@chromium.org 2014-04-15 15:17:04 +00:00
parent 4cbbf0ae83
commit cc5c454573
7 changed files with 174 additions and 135 deletions

View File

@ -37,16 +37,6 @@ Handle<Box> Factory::NewBox(Handle<Object> value) {
} }
Handle<Oddball> Factory::NewOddball(Handle<Map> map,
const char* to_string,
Handle<Object> to_number,
byte kind) {
Handle<Oddball> oddball = New<Oddball>(map, OLD_POINTER_SPACE);
Oddball::Initialize(isolate(), oddball, to_string, to_number, kind);
return oddball;
}
Handle<FixedArray> Factory::NewFixedArray(int size, PretenureFlag pretenure) { Handle<FixedArray> Factory::NewFixedArray(int size, PretenureFlag pretenure) {
ASSERT(0 <= size); ASSERT(0 <= size);
CALL_HEAP_FUNCTION( CALL_HEAP_FUNCTION(

View File

@ -14,11 +14,6 @@ namespace internal {
class Factory V8_FINAL { class Factory V8_FINAL {
public: public:
Handle<Oddball> NewOddball(Handle<Map> map,
const char* to_string,
Handle<Object> to_number,
byte kind);
// Allocates a fixed array initialized with undefined values. // Allocates a fixed array initialized with undefined values.
Handle<FixedArray> NewFixedArray( Handle<FixedArray> NewFixedArray(
int size, int size,

View File

@ -2759,6 +2759,18 @@ MaybeObject* Heap::AllocateAllocationSite() {
} }
MaybeObject* Heap::CreateOddball(Map* map,
const char* to_string,
Object* to_number,
byte kind) {
Object* result;
{ MaybeObject* maybe_result = Allocate(map, OLD_POINTER_SPACE);
if (!maybe_result->ToObject(&result)) return maybe_result;
}
return Oddball::cast(result)->Initialize(this, to_string, to_number, kind);
}
bool Heap::CreateApiObjects() { bool Heap::CreateApiObjects() {
Object* obj; Object* obj;
@ -2831,82 +2843,115 @@ void Heap::CreateFixedStubs() {
bool Heap::CreateInitialObjects() { bool Heap::CreateInitialObjects() {
HandleScope scope(isolate()); Object* obj;
Factory* factory = isolate()->factory();
// The -0 value must be set before NumberFromDouble works. // The -0 value must be set before NumberFromDouble works.
set_minus_zero_value(*factory->NewHeapNumber(-0.0, TENURED)); { MaybeObject* maybe_obj = AllocateHeapNumber(-0.0, TENURED);
if (!maybe_obj->ToObject(&obj)) return false;
}
set_minus_zero_value(HeapNumber::cast(obj));
ASSERT(std::signbit(minus_zero_value()->Number()) != 0); ASSERT(std::signbit(minus_zero_value()->Number()) != 0);
set_nan_value(*factory->NewHeapNumber(OS::nan_value(), TENURED)); { MaybeObject* maybe_obj = AllocateHeapNumber(OS::nan_value(), TENURED);
set_infinity_value(*factory->NewHeapNumber(V8_INFINITY, TENURED)); if (!maybe_obj->ToObject(&obj)) return false;
}
set_nan_value(HeapNumber::cast(obj));
{ MaybeObject* maybe_obj = AllocateHeapNumber(V8_INFINITY, TENURED);
if (!maybe_obj->ToObject(&obj)) return false;
}
set_infinity_value(HeapNumber::cast(obj));
// The hole has not been created yet, but we want to put something // The hole has not been created yet, but we want to put something
// predictable in the gaps in the string table, so lets make that Smi zero. // predictable in the gaps in the string table, so lets make that Smi zero.
set_the_hole_value(reinterpret_cast<Oddball*>(Smi::FromInt(0))); set_the_hole_value(reinterpret_cast<Oddball*>(Smi::FromInt(0)));
// Allocate initial string table. // Allocate initial string table.
set_string_table(*StringTable::New(isolate(), kInitialStringTableSize)); { MaybeObject* maybe_obj =
StringTable::Allocate(this, kInitialStringTableSize);
if (!maybe_obj->ToObject(&obj)) return false;
}
// Don't use set_string_table() due to asserts.
roots_[kStringTableRootIndex] = obj;
// Finish initializing oddballs after creating the string table. // Finish initializing oddballs after creating the string table.
Oddball::Initialize(isolate(), { MaybeObject* maybe_obj =
factory->undefined_value(), undefined_value()->Initialize(this,
"undefined", "undefined",
factory->nan_value(), nan_value(),
Oddball::kUndefined); Oddball::kUndefined);
if (!maybe_obj->ToObject(&obj)) return false;
// Initialize the null_value.
Oddball::Initialize(isolate(),
factory->null_value(),
"null",
handle(Smi::FromInt(0), isolate()),
Oddball::kNull);
set_true_value(*factory->NewOddball(factory->boolean_map(),
"true",
handle(Smi::FromInt(1), isolate()),
Oddball::kTrue));
set_false_value(*factory->NewOddball(factory->boolean_map(),
"false",
handle(Smi::FromInt(0), isolate()),
Oddball::kFalse));
set_the_hole_value(*factory->NewOddball(factory->the_hole_map(),
"hole",
handle(Smi::FromInt(-1), isolate()),
Oddball::kTheHole));
set_uninitialized_value(
*factory->NewOddball(factory->uninitialized_map(),
"uninitialized",
handle(Smi::FromInt(-1), isolate()),
Oddball::kUninitialized));
set_arguments_marker(*factory->NewOddball(factory->arguments_marker_map(),
"arguments_marker",
handle(Smi::FromInt(-4), isolate()),
Oddball::kArgumentMarker));
set_no_interceptor_result_sentinel(
*factory->NewOddball(factory->no_interceptor_result_sentinel_map(),
"no_interceptor_result_sentinel",
handle(Smi::FromInt(-2), isolate()),
Oddball::kOther));
set_termination_exception(
*factory->NewOddball(factory->termination_exception_map(),
"termination_exception",
handle(Smi::FromInt(-3), isolate()),
Oddball::kOther));
for (unsigned i = 0; i < ARRAY_SIZE(constant_string_table); i++) {
Handle<String> str =
factory->InternalizeUtf8String(constant_string_table[i].contents);
roots_[constant_string_table[i].index] = *str;
} }
Object* obj; // Initialize the null_value.
{ MaybeObject* maybe_obj = null_value()->Initialize(
this, "null", Smi::FromInt(0), Oddball::kNull);
if (!maybe_obj->ToObject(&obj)) return false;
}
{ MaybeObject* maybe_obj = CreateOddball(boolean_map(),
"true",
Smi::FromInt(1),
Oddball::kTrue);
if (!maybe_obj->ToObject(&obj)) return false;
}
set_true_value(Oddball::cast(obj));
{ MaybeObject* maybe_obj = CreateOddball(boolean_map(),
"false",
Smi::FromInt(0),
Oddball::kFalse);
if (!maybe_obj->ToObject(&obj)) return false;
}
set_false_value(Oddball::cast(obj));
{ MaybeObject* maybe_obj = CreateOddball(the_hole_map(),
"hole",
Smi::FromInt(-1),
Oddball::kTheHole);
if (!maybe_obj->ToObject(&obj)) return false;
}
set_the_hole_value(Oddball::cast(obj));
{ MaybeObject* maybe_obj = CreateOddball(uninitialized_map(),
"uninitialized",
Smi::FromInt(-1),
Oddball::kUninitialized);
if (!maybe_obj->ToObject(&obj)) return false;
}
set_uninitialized_value(Oddball::cast(obj));
{ MaybeObject* maybe_obj = CreateOddball(arguments_marker_map(),
"arguments_marker",
Smi::FromInt(-4),
Oddball::kArgumentMarker);
if (!maybe_obj->ToObject(&obj)) return false;
}
set_arguments_marker(Oddball::cast(obj));
{ MaybeObject* maybe_obj = CreateOddball(no_interceptor_result_sentinel_map(),
"no_interceptor_result_sentinel",
Smi::FromInt(-2),
Oddball::kOther);
if (!maybe_obj->ToObject(&obj)) return false;
}
set_no_interceptor_result_sentinel(Oddball::cast(obj));
{ MaybeObject* maybe_obj = CreateOddball(termination_exception_map(),
"termination_exception",
Smi::FromInt(-3),
Oddball::kOther);
if (!maybe_obj->ToObject(&obj)) return false;
}
set_termination_exception(Oddball::cast(obj));
for (unsigned i = 0; i < ARRAY_SIZE(constant_string_table); i++) {
{ MaybeObject* maybe_obj =
InternalizeUtf8String(constant_string_table[i].contents);
if (!maybe_obj->ToObject(&obj)) return false;
}
roots_[constant_string_table[i].index] = String::cast(obj);
}
// Allocate the hidden string which is used to identify the hidden properties // Allocate the hidden string which is used to identify the hidden properties
// in JSObjects. The hash code has a special value so that it will not match // in JSObjects. The hash code has a special value so that it will not match
@ -2947,12 +2992,11 @@ bool Heap::CreateInitialObjects() {
CreateFixedStubs(); CreateFixedStubs();
// Allocate the dictionary of intrinsic function names. // Allocate the dictionary of intrinsic function names.
{ { MaybeObject* maybe_obj =
Handle<NameDictionary> function_names = NameDictionary::Allocate(this, Runtime::kNumFunctions);
NameDictionary::New(isolate(), Runtime::kNumFunctions); if (!maybe_obj->ToObject(&obj)) return false;
Runtime::InitializeIntrinsicFunctionNames(isolate(), function_names);
set_intrinsic_function_names(*function_names);
} }
set_intrinsic_function_names(NameDictionary::cast(obj));
{ MaybeObject* maybe_obj = AllocateInitialNumberStringCache(); { MaybeObject* maybe_obj = AllocateInitialNumberStringCache();
if (!maybe_obj->ToObject(&obj)) return false; if (!maybe_obj->ToObject(&obj)) return false;
@ -3151,58 +3195,60 @@ Object* RegExpResultsCache::Lookup(Heap* heap,
} }
void RegExpResultsCache::Enter(Isolate* isolate, void RegExpResultsCache::Enter(Heap* heap,
Handle<String> key_string, String* key_string,
Handle<Object> key_pattern, Object* key_pattern,
Handle<FixedArray> value_array, FixedArray* value_array,
ResultsCacheType type) { ResultsCacheType type) {
Factory* factory = isolate->factory(); FixedArray* cache;
Handle<FixedArray> cache;
if (!key_string->IsInternalizedString()) return; if (!key_string->IsInternalizedString()) return;
if (type == STRING_SPLIT_SUBSTRINGS) { if (type == STRING_SPLIT_SUBSTRINGS) {
ASSERT(key_pattern->IsString()); ASSERT(key_pattern->IsString());
if (!key_pattern->IsInternalizedString()) return; if (!key_pattern->IsInternalizedString()) return;
cache = factory->string_split_cache(); cache = heap->string_split_cache();
} else { } else {
ASSERT(type == REGEXP_MULTIPLE_INDICES); ASSERT(type == REGEXP_MULTIPLE_INDICES);
ASSERT(key_pattern->IsFixedArray()); ASSERT(key_pattern->IsFixedArray());
cache = factory->regexp_multiple_cache(); cache = heap->regexp_multiple_cache();
} }
uint32_t hash = key_string->Hash(); uint32_t hash = key_string->Hash();
uint32_t index = ((hash & (kRegExpResultsCacheSize - 1)) & uint32_t index = ((hash & (kRegExpResultsCacheSize - 1)) &
~(kArrayEntriesPerCacheEntry - 1)); ~(kArrayEntriesPerCacheEntry - 1));
if (cache->get(index + kStringOffset) == Smi::FromInt(0)) { if (cache->get(index + kStringOffset) == Smi::FromInt(0)) {
cache->set(index + kStringOffset, *key_string); cache->set(index + kStringOffset, key_string);
cache->set(index + kPatternOffset, *key_pattern); cache->set(index + kPatternOffset, key_pattern);
cache->set(index + kArrayOffset, *value_array); cache->set(index + kArrayOffset, value_array);
} else { } else {
uint32_t index2 = uint32_t index2 =
((index + kArrayEntriesPerCacheEntry) & (kRegExpResultsCacheSize - 1)); ((index + kArrayEntriesPerCacheEntry) & (kRegExpResultsCacheSize - 1));
if (cache->get(index2 + kStringOffset) == Smi::FromInt(0)) { if (cache->get(index2 + kStringOffset) == Smi::FromInt(0)) {
cache->set(index2 + kStringOffset, *key_string); cache->set(index2 + kStringOffset, key_string);
cache->set(index2 + kPatternOffset, *key_pattern); cache->set(index2 + kPatternOffset, key_pattern);
cache->set(index2 + kArrayOffset, *value_array); cache->set(index2 + kArrayOffset, value_array);
} else { } else {
cache->set(index2 + kStringOffset, Smi::FromInt(0)); cache->set(index2 + kStringOffset, Smi::FromInt(0));
cache->set(index2 + kPatternOffset, Smi::FromInt(0)); cache->set(index2 + kPatternOffset, Smi::FromInt(0));
cache->set(index2 + kArrayOffset, Smi::FromInt(0)); cache->set(index2 + kArrayOffset, Smi::FromInt(0));
cache->set(index + kStringOffset, *key_string); cache->set(index + kStringOffset, key_string);
cache->set(index + kPatternOffset, *key_pattern); cache->set(index + kPatternOffset, key_pattern);
cache->set(index + kArrayOffset, *value_array); cache->set(index + kArrayOffset, value_array);
} }
} }
// If the array is a reasonably short list of substrings, convert it into a // If the array is a reasonably short list of substrings, convert it into a
// list of internalized strings. // list of internalized strings.
if (type == STRING_SPLIT_SUBSTRINGS && value_array->length() < 100) { if (type == STRING_SPLIT_SUBSTRINGS && value_array->length() < 100) {
for (int i = 0; i < value_array->length(); i++) { for (int i = 0; i < value_array->length(); i++) {
Handle<String> str(String::cast(value_array->get(i)), isolate); String* str = String::cast(value_array->get(i));
Handle<String> internalized_str = factory->InternalizeString(str); Object* internalized_str;
value_array->set(i, *internalized_str); MaybeObject* maybe_string = heap->InternalizeString(str);
if (maybe_string->ToObject(&internalized_str)) {
value_array->set(i, internalized_str);
}
} }
} }
// Convert backing store to a copy-on-write array. // Convert backing store to a copy-on-write array.
value_array->set_map_no_write_barrier(*factory->fixed_cow_array_map()); value_array->set_map_no_write_barrier(heap->fixed_cow_array_map());
} }
@ -5926,12 +5972,16 @@ bool Heap::CreateHeapObjects() {
// Create initial objects // Create initial objects
if (!CreateInitialObjects()) return false; if (!CreateInitialObjects()) return false;
CHECK_EQ(0, gc_count_);
native_contexts_list_ = undefined_value(); native_contexts_list_ = undefined_value();
array_buffers_list_ = undefined_value(); array_buffers_list_ = undefined_value();
allocation_sites_list_ = undefined_value(); allocation_sites_list_ = undefined_value();
weak_object_to_code_table_ = undefined_value(); weak_object_to_code_table_ = undefined_value();
HandleScope scope(isolate());
Runtime::InitializeIntrinsicFunctionNames(
isolate(), handle(intrinsic_function_names(), isolate()));
return true; return true;
} }

View File

@ -2094,6 +2094,11 @@ class Heap {
void CreateFixedStubs(); void CreateFixedStubs();
MUST_USE_RESULT MaybeObject* CreateOddball(Map* map,
const char* to_string,
Object* to_number,
byte kind);
// Allocate empty fixed array. // Allocate empty fixed array.
MUST_USE_RESULT MaybeObject* AllocateEmptyFixedArray(); MUST_USE_RESULT MaybeObject* AllocateEmptyFixedArray();
@ -2870,10 +2875,10 @@ class RegExpResultsCache {
ResultsCacheType type); ResultsCacheType type);
// Attempt to add value_array to the cache specified by type. On success, // Attempt to add value_array to the cache specified by type. On success,
// value_array is turned into a COW-array. // value_array is turned into a COW-array.
static void Enter(Isolate* isolate, static void Enter(Heap* heap,
Handle<String> key_string, String* key_string,
Handle<Object> key_pattern, Object* key_pattern,
Handle<FixedArray> value_array, FixedArray* value_array,
ResultsCacheType type); ResultsCacheType type);
static void Clear(FixedArray* cache); static void Clear(FixedArray* cache);
static const int kRegExpResultsCacheSize = 0x100; static const int kRegExpResultsCacheSize = 0x100;

View File

@ -10096,16 +10096,20 @@ bool JSFunction::PassesFilter(const char* raw_filter) {
} }
void Oddball::Initialize(Isolate* isolate, MaybeObject* Oddball::Initialize(Heap* heap,
Handle<Oddball> oddball, const char* to_string,
const char* to_string, Object* to_number,
Handle<Object> to_number, byte kind) {
byte kind) { String* internalized_to_string;
Handle<String> internalized_to_string = { MaybeObject* maybe_string =
isolate->factory()->InternalizeUtf8String(CStrVector(to_string)); heap->InternalizeUtf8String(
oddball->set_to_string(*internalized_to_string); CStrVector(to_string));
oddball->set_to_number(*to_number); if (!maybe_string->To(&internalized_to_string)) return maybe_string;
oddball->set_kind(kind); }
set_to_string(internalized_to_string);
set_to_number(to_number);
set_kind(kind);
return this;
} }
@ -14421,10 +14425,6 @@ Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>::
int, int,
JSObject::DeleteMode); JSObject::DeleteMode);
template Handle<NameDictionary>
HashTable<NameDictionary, NameDictionaryShape, Name*>::
New(Isolate*, int, MinimumCapacity, PretenureFlag);
template Handle<NameDictionary> template Handle<NameDictionary>
HashTable<NameDictionary, NameDictionaryShape, Name*>:: HashTable<NameDictionary, NameDictionaryShape, Name*>::
Shrink(Handle<NameDictionary>, Name* n); Shrink(Handle<NameDictionary>, Name* n);

View File

@ -9723,11 +9723,10 @@ class Oddball: public HeapObject {
DECLARE_VERIFIER(Oddball) DECLARE_VERIFIER(Oddball)
// Initialize the fields. // Initialize the fields.
static void Initialize(Isolate* isolate, MUST_USE_RESULT MaybeObject* Initialize(Heap* heap,
Handle<Oddball> oddball, const char* to_string,
const char* to_string, Object* to_number,
Handle<Object> to_number, byte kind);
byte kind);
// Layout description. // Layout description.
static const int kToStringOffset = HeapObject::kHeaderSize; static const int kToStringOffset = HeapObject::kHeaderSize;

View File

@ -4730,10 +4730,10 @@ static MaybeObject* SearchRegExpMultiple(
fixed_array->set(fixed_array->length() - 1, fixed_array->set(fixed_array->length() - 1,
Smi::FromInt(builder.length())); Smi::FromInt(builder.length()));
// Cache the result and turn the FixedArray into a COW array. // Cache the result and turn the FixedArray into a COW array.
RegExpResultsCache::Enter(isolate, RegExpResultsCache::Enter(isolate->heap(),
subject, *subject,
handle(regexp->data(), isolate), regexp->data(),
fixed_array, *fixed_array,
RegExpResultsCache::REGEXP_MULTIPLE_INDICES); RegExpResultsCache::REGEXP_MULTIPLE_INDICES);
} }
return *builder.ToJSArray(result_array); return *builder.ToJSArray(result_array);
@ -6750,10 +6750,10 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_StringSplit) {
if (limit == 0xffffffffu) { if (limit == 0xffffffffu) {
if (result->HasFastObjectElements()) { if (result->HasFastObjectElements()) {
RegExpResultsCache::Enter(isolate, RegExpResultsCache::Enter(isolate->heap(),
subject, *subject,
pattern, *pattern,
elements, *elements,
RegExpResultsCache::STRING_SPLIT_SUBSTRINGS); RegExpResultsCache::STRING_SPLIT_SUBSTRINGS);
} }
} }