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,
// Numeric strings have a different hash algorithm not known by
// LookupTwoCharsStringIfExists, so we skip this step for such strings.
if (!Between(c1, '0', '9') || !Between(c2, '0', '9')) {
String* result;
StringTable* table = isolate->heap()->string_table();
if (table->LookupTwoCharsStringIfExists(c1, c2, &result)) {
return handle(result);
Handle<String> result;
if (StringTable::LookupTwoCharsStringIfExists(isolate, c1, c2).
ToHandle(&result)) {
return result;
}
}
......
......@@ -4656,15 +4656,6 @@ void Heap::Verify() {
#endif
bool Heap::InternalizeStringIfExists(String* string, String** result) {
if (string->IsInternalizedString()) {
*result = string;
return true;
}
return string_table()->LookupStringIfExists(string, result);
}
void Heap::ZapFromSpace() {
NewSpacePageIterator it(new_space_.FromSpaceStart(),
new_space_.FromSpaceEnd());
......@@ -6246,12 +6237,11 @@ void KeyedLookupCache::Update(Handle<Map> map,
int field_offset) {
DisallowHeapAllocation no_gc;
if (!name->IsUniqueName()) {
String* internalized_string;
if (!map->GetIsolate()->heap()->InternalizeStringIfExists(
String::cast(*name), &internalized_string)) {
if (!StringTable::InternalizeStringIfExists(name->GetIsolate(),
Handle<String>::cast(name)).
ToHandle(&name)) {
return;
}
name = handle(internalized_string);
}
// This cache is cleared only between mark compact passes, so we expect the
// cache to only contain old space names.
......
......@@ -730,8 +730,6 @@ class Heap {
// Maintain marking consistency for IncrementalMarking.
void AdjustLiveBytes(Address address, int by, InvocationMode mode);
bool InternalizeStringIfExists(String* str, String** result);
// Converts the given boolean condition to JavaScript boolean value.
inline Object* ToBoolean(bool condition);
......
......@@ -15416,35 +15416,45 @@ class TwoCharHashTableKey : public HashTableKey {
};
bool StringTable::LookupStringIfExists(String* string, String** result) {
SLOW_ASSERT(this == HeapObject::cast(this)->GetHeap()->string_table());
DisallowHeapAllocation no_alloc;
// TODO(ishell): Handlify all the callers and remove this scope.
HandleScope scope(GetIsolate());
InternalizedStringKey key(handle(string));
int entry = FindEntry(&key);
MaybeHandle<String> StringTable::InternalizeStringIfExists(
Isolate* isolate,
Handle<String> string) {
if (string->IsInternalizedString()) {
return string;
}
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) {
return false;
return MaybeHandle<String>();
} else {
*result = String::cast(KeyAt(entry));
Handle<String> result(String::cast(string_table->KeyAt(entry)), isolate);
ASSERT(StringShape(*result).IsInternalized());
return true;
return result;
}
}
bool StringTable::LookupTwoCharsStringIfExists(uint16_t c1,
uint16_t c2,
String** result) {
SLOW_ASSERT(this == HeapObject::cast(this)->GetHeap()->string_table());
TwoCharHashTableKey key(c1, c2, GetHeap()->HashSeed());
int entry = FindEntry(&key);
MaybeHandle<String> StringTable::LookupTwoCharsStringIfExists(
Isolate* isolate,
uint16_t c1,
uint16_t c2) {
Handle<StringTable> string_table = isolate->factory()->string_table();
TwoCharHashTableKey key(c1, c2, isolate->heap()->HashSeed());
int entry = string_table->FindEntry(&key);
if (entry == kNotFound) {
return false;
return MaybeHandle<String>();
} else {
*result = String::cast(KeyAt(entry));
Handle<String> result(String::cast(string_table->KeyAt(entry)), isolate);
ASSERT(StringShape(*result).IsInternalized());
return true;
return result;
}
}
......
......@@ -3741,8 +3741,6 @@ class SeqOneByteString;
//
// No special elements in the prefix and the element size is 1
// 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,
StringTableShape,
HashTableKey*> {
......@@ -3752,11 +3750,21 @@ class StringTable: public HashTable<StringTable,
static Handle<String> LookupString(Isolate* isolate, Handle<String> 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
// true if it is found, assigning the string to the given output
// parameter.
bool LookupStringIfExists(String* str, String** result);
bool LookupTwoCharsStringIfExists(uint16_t c1, uint16_t c2, String** result);
// string handle if it is found, or an empty handle otherwise.
MUST_USE_RESULT static MaybeHandle<String> LookupStringIfExists(
Isolate* isolate,
Handle<String> str);
MUST_USE_RESULT static MaybeHandle<String> LookupTwoCharsStringIfExists(
Isolate* isolate,
uint16_t c1,
uint16_t c2);
// Casting.
static inline StringTable* cast(Object* obj);
......
......@@ -437,14 +437,14 @@ void ContextSlotCache::Update(Handle<Object> data,
InitializationFlag init_flag,
int slot_index) {
DisallowHeapAllocation no_gc;
String* internalized_name;
Handle<String> internalized_name;
ASSERT(slot_index > kNotFound);
if (name->GetIsolate()->heap()->InternalizeStringIfExists(
*name, &internalized_name)) {
int index = Hash(*data, internalized_name);
if (StringTable::InternalizeStringIfExists(name->GetIsolate(), name).
ToHandle(&internalized_name)) {
int index = Hash(*data, *internalized_name);
Key& key = keys_[index];
key.data = *data;
key.name = internalized_name;
key.name = *internalized_name;
// Please note value only takes a uint as index.
values_[index] = Value(mode, init_flag, slot_index - kNotFound).raw();
#ifdef DEBUG
......@@ -467,9 +467,9 @@ void ContextSlotCache::ValidateEntry(Handle<Object> data,
InitializationFlag init_flag,
int slot_index) {
DisallowHeapAllocation no_gc;
String* internalized_name;
if (name->GetIsolate()->heap()->InternalizeStringIfExists(
*name, &internalized_name)) {
Handle<String> internalized_name;
if (StringTable::InternalizeStringIfExists(name->GetIsolate(), name).
ToHandle(&internalized_name)) {
int index = Hash(*data, *name);
Key& key = keys_[index];
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