Commit f7e8255f authored by ishell@chromium.org's avatar ishell@chromium.org

StringTable::Lookup*IfExist() handlified.

R=yangguo@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@21100 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 13b64dfe
...@@ -376,10 +376,10 @@ static inline Handle<String> MakeOrFindTwoCharacterString(Isolate* isolate, ...@@ -376,10 +376,10 @@ static inline Handle<String> MakeOrFindTwoCharacterString(Isolate* isolate,
// Numeric strings have a different hash algorithm not known by // Numeric strings have a different hash algorithm not known by
// LookupTwoCharsStringIfExists, so we skip this step for such strings. // LookupTwoCharsStringIfExists, so we skip this step for such strings.
if (!Between(c1, '0', '9') || !Between(c2, '0', '9')) { if (!Between(c1, '0', '9') || !Between(c2, '0', '9')) {
String* result; Handle<String> result;
StringTable* table = isolate->heap()->string_table(); if (StringTable::LookupTwoCharsStringIfExists(isolate, c1, c2).
if (table->LookupTwoCharsStringIfExists(c1, c2, &result)) { ToHandle(&result)) {
return handle(result); return result;
} }
} }
......
...@@ -4656,15 +4656,6 @@ void Heap::Verify() { ...@@ -4656,15 +4656,6 @@ void Heap::Verify() {
#endif #endif
bool Heap::InternalizeStringIfExists(String* string, String** result) {
if (string->IsInternalizedString()) {
*result = string;
return true;
}
return string_table()->LookupStringIfExists(string, result);
}
void Heap::ZapFromSpace() { void Heap::ZapFromSpace() {
NewSpacePageIterator it(new_space_.FromSpaceStart(), NewSpacePageIterator it(new_space_.FromSpaceStart(),
new_space_.FromSpaceEnd()); new_space_.FromSpaceEnd());
...@@ -6246,12 +6237,11 @@ void KeyedLookupCache::Update(Handle<Map> map, ...@@ -6246,12 +6237,11 @@ void KeyedLookupCache::Update(Handle<Map> map,
int field_offset) { int field_offset) {
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
if (!name->IsUniqueName()) { if (!name->IsUniqueName()) {
String* internalized_string; if (!StringTable::InternalizeStringIfExists(name->GetIsolate(),
if (!map->GetIsolate()->heap()->InternalizeStringIfExists( Handle<String>::cast(name)).
String::cast(*name), &internalized_string)) { ToHandle(&name)) {
return; return;
} }
name = handle(internalized_string);
} }
// This cache is cleared only between mark compact passes, so we expect the // This cache is cleared only between mark compact passes, so we expect the
// cache to only contain old space names. // cache to only contain old space names.
......
...@@ -730,8 +730,6 @@ class Heap { ...@@ -730,8 +730,6 @@ class Heap {
// Maintain marking consistency for IncrementalMarking. // Maintain marking consistency for IncrementalMarking.
void AdjustLiveBytes(Address address, int by, InvocationMode mode); void AdjustLiveBytes(Address address, int by, InvocationMode mode);
bool InternalizeStringIfExists(String* str, String** result);
// Converts the given boolean condition to JavaScript boolean value. // Converts the given boolean condition to JavaScript boolean value.
inline Object* ToBoolean(bool condition); inline Object* ToBoolean(bool condition);
......
...@@ -15416,35 +15416,45 @@ class TwoCharHashTableKey : public HashTableKey { ...@@ -15416,35 +15416,45 @@ class TwoCharHashTableKey : public HashTableKey {
}; };
bool StringTable::LookupStringIfExists(String* string, String** result) { MaybeHandle<String> StringTable::InternalizeStringIfExists(
SLOW_ASSERT(this == HeapObject::cast(this)->GetHeap()->string_table()); Isolate* isolate,
DisallowHeapAllocation no_alloc; Handle<String> string) {
// TODO(ishell): Handlify all the callers and remove this scope. if (string->IsInternalizedString()) {
HandleScope scope(GetIsolate()); return string;
InternalizedStringKey key(handle(string)); }
int entry = FindEntry(&key); return LookupStringIfExists(isolate, string);
}
MaybeHandle<String> StringTable::LookupStringIfExists(
Isolate* isolate,
Handle<String> string) {
Handle<StringTable> string_table = isolate->factory()->string_table();
InternalizedStringKey key(string);
int entry = string_table->FindEntry(&key);
if (entry == kNotFound) { if (entry == kNotFound) {
return false; return MaybeHandle<String>();
} else { } else {
*result = String::cast(KeyAt(entry)); Handle<String> result(String::cast(string_table->KeyAt(entry)), isolate);
ASSERT(StringShape(*result).IsInternalized()); ASSERT(StringShape(*result).IsInternalized());
return true; return result;
} }
} }
bool StringTable::LookupTwoCharsStringIfExists(uint16_t c1, MaybeHandle<String> StringTable::LookupTwoCharsStringIfExists(
uint16_t c2, Isolate* isolate,
String** result) { uint16_t c1,
SLOW_ASSERT(this == HeapObject::cast(this)->GetHeap()->string_table()); uint16_t c2) {
TwoCharHashTableKey key(c1, c2, GetHeap()->HashSeed()); Handle<StringTable> string_table = isolate->factory()->string_table();
int entry = FindEntry(&key); TwoCharHashTableKey key(c1, c2, isolate->heap()->HashSeed());
int entry = string_table->FindEntry(&key);
if (entry == kNotFound) { if (entry == kNotFound) {
return false; return MaybeHandle<String>();
} else { } else {
*result = String::cast(KeyAt(entry)); Handle<String> result(String::cast(string_table->KeyAt(entry)), isolate);
ASSERT(StringShape(*result).IsInternalized()); ASSERT(StringShape(*result).IsInternalized());
return true; return result;
} }
} }
......
...@@ -3741,8 +3741,6 @@ class SeqOneByteString; ...@@ -3741,8 +3741,6 @@ class SeqOneByteString;
// //
// No special elements in the prefix and the element size is 1 // No special elements in the prefix and the element size is 1
// because only the string itself (the key) needs to be stored. // because only the string itself (the key) needs to be stored.
// TODO(ishell): Make StringTable a singleton class and move
// Heap::InternalizeStringXX() methods here.
class StringTable: public HashTable<StringTable, class StringTable: public HashTable<StringTable,
StringTableShape, StringTableShape,
HashTableKey*> { HashTableKey*> {
...@@ -3752,11 +3750,21 @@ class StringTable: public HashTable<StringTable, ...@@ -3752,11 +3750,21 @@ class StringTable: public HashTable<StringTable,
static Handle<String> LookupString(Isolate* isolate, Handle<String> key); static Handle<String> LookupString(Isolate* isolate, Handle<String> key);
static Handle<String> LookupKey(Isolate* isolate, HashTableKey* key); static Handle<String> LookupKey(Isolate* isolate, HashTableKey* key);
// Tries to internalize given string and returns string handle on success
// or an empty handle otherwise.
MUST_USE_RESULT static MaybeHandle<String> InternalizeStringIfExists(
Isolate* isolate,
Handle<String> string);
// Looks up a string that is equal to the given string and returns // Looks up a string that is equal to the given string and returns
// true if it is found, assigning the string to the given output // string handle if it is found, or an empty handle otherwise.
// parameter. MUST_USE_RESULT static MaybeHandle<String> LookupStringIfExists(
bool LookupStringIfExists(String* str, String** result); Isolate* isolate,
bool LookupTwoCharsStringIfExists(uint16_t c1, uint16_t c2, String** result); Handle<String> str);
MUST_USE_RESULT static MaybeHandle<String> LookupTwoCharsStringIfExists(
Isolate* isolate,
uint16_t c1,
uint16_t c2);
// Casting. // Casting.
static inline StringTable* cast(Object* obj); static inline StringTable* cast(Object* obj);
......
...@@ -437,14 +437,14 @@ void ContextSlotCache::Update(Handle<Object> data, ...@@ -437,14 +437,14 @@ void ContextSlotCache::Update(Handle<Object> data,
InitializationFlag init_flag, InitializationFlag init_flag,
int slot_index) { int slot_index) {
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
String* internalized_name; Handle<String> internalized_name;
ASSERT(slot_index > kNotFound); ASSERT(slot_index > kNotFound);
if (name->GetIsolate()->heap()->InternalizeStringIfExists( if (StringTable::InternalizeStringIfExists(name->GetIsolate(), name).
*name, &internalized_name)) { ToHandle(&internalized_name)) {
int index = Hash(*data, internalized_name); int index = Hash(*data, *internalized_name);
Key& key = keys_[index]; Key& key = keys_[index];
key.data = *data; key.data = *data;
key.name = internalized_name; key.name = *internalized_name;
// Please note value only takes a uint as index. // Please note value only takes a uint as index.
values_[index] = Value(mode, init_flag, slot_index - kNotFound).raw(); values_[index] = Value(mode, init_flag, slot_index - kNotFound).raw();
#ifdef DEBUG #ifdef DEBUG
...@@ -467,9 +467,9 @@ void ContextSlotCache::ValidateEntry(Handle<Object> data, ...@@ -467,9 +467,9 @@ void ContextSlotCache::ValidateEntry(Handle<Object> data,
InitializationFlag init_flag, InitializationFlag init_flag,
int slot_index) { int slot_index) {
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
String* internalized_name; Handle<String> internalized_name;
if (name->GetIsolate()->heap()->InternalizeStringIfExists( if (StringTable::InternalizeStringIfExists(name->GetIsolate(), name).
*name, &internalized_name)) { ToHandle(&internalized_name)) {
int index = Hash(*data, *name); int index = Hash(*data, *name);
Key& key = keys_[index]; Key& key = keys_[index];
ASSERT(key.data == *data); ASSERT(key.data == *data);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment