Commit a06df1f2 authored by rmcilroy's avatar rmcilroy Committed by Commit bot

[Parser] Don't internalize on-the-fly.

Avoid internalizing on-the-fly now that scope analysis and natives syntax
runtime calls no longer require internalized AST values. This should be
more efficient by avoiding extra branches on every AST value creation.

BUG=v8:5215, chromium:634953

Review-Url: https://codereview.chromium.org/2328593002
Cr-Commit-Position: refs/heads/master@{#39531}
parent 696dd65b
...@@ -237,12 +237,7 @@ AstRawString* AstValueFactory::GetTwoByteStringInternal( ...@@ -237,12 +237,7 @@ AstRawString* AstValueFactory::GetTwoByteStringInternal(
const AstRawString* AstValueFactory::GetString(Handle<String> literal) { const AstRawString* AstValueFactory::GetString(Handle<String> literal) {
// For the FlatContent to stay valid, we shouldn't do any heap
// allocation. Make sure we won't try to internalize the string in GetString.
AstRawString* result = NULL; AstRawString* result = NULL;
Isolate* saved_isolate = isolate_;
isolate_ = NULL;
{
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
String::FlatContent content = literal->GetFlatContent(); String::FlatContent content = literal->GetFlatContent();
if (content.IsOneByte()) { if (content.IsOneByte()) {
...@@ -251,15 +246,6 @@ const AstRawString* AstValueFactory::GetString(Handle<String> literal) { ...@@ -251,15 +246,6 @@ const AstRawString* AstValueFactory::GetString(Handle<String> literal) {
DCHECK(content.IsTwoByte()); DCHECK(content.IsTwoByte());
result = GetTwoByteStringInternal(content.ToUC16Vector()); result = GetTwoByteStringInternal(content.ToUC16Vector());
} }
}
isolate_ = saved_isolate;
if (strings_ != nullptr && isolate_) {
// Only the string we are creating is uninternalized at this point.
DCHECK_EQ(result, strings_);
DCHECK_NULL(strings_->next());
result->Internalize(isolate_);
ResetStrings();
}
return result; return result;
} }
...@@ -308,13 +294,6 @@ const AstRawString* AstValueFactory::ConcatStrings(const AstRawString* left, ...@@ -308,13 +294,6 @@ const AstRawString* AstValueFactory::ConcatStrings(const AstRawString* left,
} }
void AstValueFactory::Internalize(Isolate* isolate) { void AstValueFactory::Internalize(Isolate* isolate) {
if (isolate_) {
DCHECK_NULL(strings_);
DCHECK_NULL(values_);
// Everything is already internalized.
return;
}
// Strings need to be internalized before values, because values refer to // Strings need to be internalized before values, because values refer to
// strings. // strings.
for (AstString* current = strings_; current != nullptr;) { for (AstString* current = strings_; current != nullptr;) {
...@@ -327,7 +306,6 @@ void AstValueFactory::Internalize(Isolate* isolate) { ...@@ -327,7 +306,6 @@ void AstValueFactory::Internalize(Isolate* isolate) {
current->Internalize(isolate); current->Internalize(isolate);
current = next; current = next;
} }
isolate_ = isolate;
ResetStrings(); ResetStrings();
values_ = nullptr; values_ = nullptr;
} }
......
...@@ -329,7 +329,6 @@ class AstValueFactory { ...@@ -329,7 +329,6 @@ class AstValueFactory {
values_(nullptr), values_(nullptr),
strings_end_(&strings_), strings_end_(&strings_),
zone_(zone), zone_(zone),
isolate_(NULL),
hash_seed_(hash_seed) { hash_seed_(hash_seed) {
ResetStrings(); ResetStrings();
#define F(name, str) name##_string_ = NULL; #define F(name, str) name##_string_ = NULL;
...@@ -359,9 +358,6 @@ class AstValueFactory { ...@@ -359,9 +358,6 @@ class AstValueFactory {
const AstRawString* right); const AstRawString* right);
void Internalize(Isolate* isolate); void Internalize(Isolate* isolate);
bool IsInternalized() {
return isolate_ != NULL;
}
#define F(name, str) \ #define F(name, str) \
const AstRawString* name##_string() { \ const AstRawString* name##_string() { \
...@@ -389,21 +385,13 @@ class AstValueFactory { ...@@ -389,21 +385,13 @@ class AstValueFactory {
private: private:
AstValue* AddValue(AstValue* value) { AstValue* AddValue(AstValue* value) {
if (isolate_) {
value->Internalize(isolate_);
} else {
value->set_next(values_); value->set_next(values_);
values_ = value; values_ = value;
}
return value; return value;
} }
AstString* AddString(AstString* string) { AstString* AddString(AstString* string) {
if (isolate_) {
string->Internalize(isolate_);
} else {
*strings_end_ = string; *strings_end_ = string;
strings_end_ = string->next_location(); strings_end_ = string->next_location();
}
return string; return string;
} }
void ResetStrings() { void ResetStrings() {
...@@ -427,7 +415,6 @@ class AstValueFactory { ...@@ -427,7 +415,6 @@ class AstValueFactory {
AstString* strings_; AstString* strings_;
AstString** strings_end_; AstString** strings_end_;
Zone* zone_; Zone* zone_;
Isolate* isolate_;
uint32_t hash_seed_; uint32_t hash_seed_;
......
...@@ -4167,7 +4167,7 @@ void Parser::HandleSourceURLComments(Isolate* isolate, Handle<Script> script) { ...@@ -4167,7 +4167,7 @@ void Parser::HandleSourceURLComments(Isolate* isolate, Handle<Script> script) {
void Parser::Internalize(Isolate* isolate, Handle<Script> script, bool error) { void Parser::Internalize(Isolate* isolate, Handle<Script> script, bool error) {
// Internalize strings. // Internalize strings and values.
ast_value_factory()->Internalize(isolate); ast_value_factory()->Internalize(isolate);
// Error processing. // Error processing.
...@@ -4234,7 +4234,6 @@ bool Parser::Parse(ParseInfo* info) { ...@@ -4234,7 +4234,6 @@ bool Parser::Parse(ParseInfo* info) {
info->set_literal(result); info->set_literal(result);
Internalize(isolate, info->script(), result == NULL); Internalize(isolate, info->script(), result == NULL);
DCHECK(ast_value_factory()->IsInternalized());
return (result != NULL); return (result != NULL);
} }
...@@ -5827,13 +5826,6 @@ Statement* Parser::FinalizeForOfStatement(ForOfStatement* loop, ...@@ -5827,13 +5826,6 @@ Statement* Parser::FinalizeForOfStatement(ForOfStatement* loop,
return final_loop; return final_loop;
} }
#ifdef DEBUG
void Parser::Print(AstNode* node) {
ast_value_factory()->Internalize(Isolate::Current());
node->Print(Isolate::Current());
}
#endif // DEBUG
#undef CHECK_OK #undef CHECK_OK
#undef CHECK_OK_VOID #undef CHECK_OK_VOID
#undef CHECK_FAILED #undef CHECK_FAILED
......
...@@ -1082,10 +1082,6 @@ class Parser : public ParserBase<Parser> { ...@@ -1082,10 +1082,6 @@ class Parser : public ParserBase<Parser> {
HistogramTimer* pre_parse_timer_; HistogramTimer* pre_parse_timer_;
bool parsing_on_main_thread_; bool parsing_on_main_thread_;
#ifdef DEBUG
void Print(AstNode* node);
#endif // DEBUG
}; };
} // namespace internal } // namespace internal
......
...@@ -347,10 +347,13 @@ bool Rewriter::Rewrite(ParseInfo* info) { ...@@ -347,10 +347,13 @@ bool Rewriter::Rewrite(ParseInfo* info) {
Variable* result = closure_scope->NewTemporary( Variable* result = closure_scope->NewTemporary(
info->ast_value_factory()->dot_result_string()); info->ast_value_factory()->dot_result_string());
// The name string must be internalized at this point. // The name string must be internalized at this point.
info->ast_value_factory()->Internalize(info->isolate());
DCHECK(!result->name().is_null()); DCHECK(!result->name().is_null());
Processor processor(info->isolate(), closure_scope, result, Processor processor(info->isolate(), closure_scope, result,
info->ast_value_factory()); info->ast_value_factory());
processor.Process(body); processor.Process(body);
// Internalize any values created during rewriting.
info->ast_value_factory()->Internalize(info->isolate());
if (processor.HasStackOverflow()) return false; if (processor.HasStackOverflow()) return false;
if (processor.result_assigned()) { if (processor.result_assigned()) {
......
...@@ -276,6 +276,7 @@ class AsmTyperHarnessBuilder { ...@@ -276,6 +276,7 @@ class AsmTyperHarnessBuilder {
private: private:
Variable* DeclareVariable(VariableName var_name) { Variable* DeclareVariable(VariableName var_name) {
auto* name_ast_string = ast_value_factory_.GetOneByteString(var_name.name_); auto* name_ast_string = ast_value_factory_.GetOneByteString(var_name.name_);
ast_value_factory_.Internalize(isolate_);
return var_name.mode_ == DYNAMIC_GLOBAL return var_name.mode_ == DYNAMIC_GLOBAL
? outer_scope_->DeclareDynamicGlobal(name_ast_string, ? outer_scope_->DeclareDynamicGlobal(name_ast_string,
NORMAL_VARIABLE) NORMAL_VARIABLE)
......
...@@ -632,9 +632,10 @@ void TestScanRegExp(const char* re_source, const char* expected) { ...@@ -632,9 +632,10 @@ void TestScanRegExp(const char* re_source, const char* expected) {
i::Zone zone(CcTest::i_isolate()->allocator()); i::Zone zone(CcTest::i_isolate()->allocator());
i::AstValueFactory ast_value_factory(&zone, i::AstValueFactory ast_value_factory(&zone,
CcTest::i_isolate()->heap()->HashSeed()); CcTest::i_isolate()->heap()->HashSeed());
const i::AstRawString* current_symbol =
scanner.CurrentSymbol(&ast_value_factory);
ast_value_factory.Internalize(CcTest::i_isolate()); ast_value_factory.Internalize(CcTest::i_isolate());
i::Handle<i::String> val = i::Handle<i::String> val = current_symbol->string();
scanner.CurrentSymbol(&ast_value_factory)->string();
i::DisallowHeapAllocation no_alloc; i::DisallowHeapAllocation no_alloc;
i::String::FlatContent content = val->GetFlatContent(); i::String::FlatContent content = val->GetFlatContent();
CHECK(content.IsOneByte()); CHECK(content.IsOneByte());
...@@ -3214,8 +3215,8 @@ TEST(SerializationOfMaybeAssignmentFlag) { ...@@ -3214,8 +3215,8 @@ TEST(SerializationOfMaybeAssignmentFlag) {
i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(o); i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(o);
i::Context* context = f->context(); i::Context* context = f->context();
i::AstValueFactory avf(&zone, isolate->heap()->HashSeed()); i::AstValueFactory avf(&zone, isolate->heap()->HashSeed());
avf.Internalize(isolate);
const i::AstRawString* name = avf.GetOneByteString("result"); const i::AstRawString* name = avf.GetOneByteString("result");
avf.Internalize(isolate);
i::Handle<i::String> str = name->string(); i::Handle<i::String> str = name->string();
CHECK(str->IsInternalizedString()); CHECK(str->IsInternalizedString());
i::DeclarationScope* script_scope = i::DeclarationScope* script_scope =
...@@ -3264,6 +3265,7 @@ TEST(IfArgumentsArrayAccessedThenParametersMaybeAssigned) { ...@@ -3264,6 +3265,7 @@ TEST(IfArgumentsArrayAccessedThenParametersMaybeAssigned) {
i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(o); i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(o);
i::Context* context = f->context(); i::Context* context = f->context();
i::AstValueFactory avf(&zone, isolate->heap()->HashSeed()); i::AstValueFactory avf(&zone, isolate->heap()->HashSeed());
const i::AstRawString* name_x = avf.GetOneByteString("x");
avf.Internalize(isolate); avf.Internalize(isolate);
i::DeclarationScope* script_scope = i::DeclarationScope* script_scope =
...@@ -3272,7 +3274,6 @@ TEST(IfArgumentsArrayAccessedThenParametersMaybeAssigned) { ...@@ -3272,7 +3274,6 @@ TEST(IfArgumentsArrayAccessedThenParametersMaybeAssigned) {
isolate, &zone, context->scope_info(), script_scope, &avf, isolate, &zone, context->scope_info(), script_scope, &avf,
i::Scope::DeserializationMode::kIncludingVariables); i::Scope::DeserializationMode::kIncludingVariables);
CHECK(s != script_scope); CHECK(s != script_scope);
const i::AstRawString* name_x = avf.GetOneByteString("x");
// Get result from f's function context (that is g's outer context) // Get result from f's function context (that is g's outer context)
i::Variable* var_x = s->Lookup(name_x); i::Variable* var_x = s->Lookup(name_x);
......
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