Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(538)

Unified Diff: runtime/vm/parser.cc

Issue 2902063003: Fix new space allocation in parser which can be triggered on background compiler (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/parser.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/parser.cc
diff --git a/runtime/vm/parser.cc b/runtime/vm/parser.cc
index 95f0e1c290ee2c188f7f05025f11b27c79d3ba45..a26173d50ad5a8c4f09ceddff3c3537758376063 100644
--- a/runtime/vm/parser.cc
+++ b/runtime/vm/parser.cc
@@ -457,6 +457,7 @@ Parser::Parser(const Script& script,
TokenPosition token_pos)
: thread_(Thread::Current()),
isolate_(thread()->isolate()),
+ allocation_space_(thread_->IsMutatorThread() ? Heap::kNew : Heap::kOld),
script_(Script::Handle(zone(), script.raw())),
tokens_iterator_(zone(),
TokenStream::Handle(zone(), script.tokens()),
@@ -489,6 +490,7 @@ Parser::Parser(const Script& script,
TokenPosition token_pos)
: thread_(Thread::Current()),
isolate_(thread()->isolate()),
+ allocation_space_(thread_->IsMutatorThread() ? Heap::kNew : Heap::kOld),
script_(Script::Handle(zone(), script.raw())),
tokens_iterator_(zone(),
TokenStream::Handle(zone(), script.tokens()),
@@ -1951,7 +1953,7 @@ void Parser::SkipToMatching() {
if (!is_match) {
const Error& error = Error::Handle(LanguageError::NewFormatted(
Error::Handle(), script_, opening_pos, Report::AtLocation,
- Report::kWarning, Heap::kNew, "unbalanced '%s' opens here",
+ Report::kWarning, allocation_space_, "unbalanced '%s' opens here",
Token::Str(opening_token)));
ReportErrors(error, script_, token_pos, "unbalanced '%s'",
Token::Str(token));
@@ -5668,7 +5670,7 @@ void Parser::ParseInterfaceList(const Class& cls) {
Array& cls_interfaces = Array::Handle(Z, cls.interfaces());
for (intptr_t i = 0; i < cls_interfaces.Length(); i++) {
interface ^= cls_interfaces.At(i);
- all_interfaces.Add(interface);
+ all_interfaces.Add(interface, Heap::kOld);
}
// Now parse and add the new interfaces.
do {
@@ -5680,7 +5682,7 @@ void Parser::ParseInterfaceList(const Class& cls) {
"type parameter '%s' may not be used in interface list",
String::Handle(Z, interface.UserVisibleName()).ToCString());
}
- all_interfaces.Add(interface);
+ all_interfaces.Add(interface, Heap::kOld);
} while (CurrentToken() == Token::kCOMMA);
cls_interfaces = Array::MakeArray(all_interfaces);
cls.set_interfaces(cls_interfaces);
@@ -5706,7 +5708,7 @@ RawAbstractType* Parser::ParseMixins(const AbstractType& super_type) {
"mixin type '%s' may not be a type parameter",
String::Handle(Z, mixin_type.UserVisibleName()).ToCString());
}
- mixin_types.Add(mixin_type);
+ mixin_types.Add(mixin_type, Heap::kOld);
} while (CurrentToken() == Token::kCOMMA);
return MixinAppType::New(super_type,
Array::Handle(Z, Array::MakeArray(mixin_types)));
@@ -6184,7 +6186,7 @@ void Parser::ParseIdentList(GrowableObjectArray* names) {
ReportError("identifier expected");
}
while (IsIdentifier()) {
- names->Add(*CurrentLiteral());
+ names->Add(*CurrentLiteral(), allocation_space_);
ConsumeToken(); // Identifier.
if (CurrentToken() != Token::kCOMMA) {
return;
@@ -6211,13 +6213,13 @@ void Parser::ParseLibraryImportExport(const Object& tl_owner,
ConsumeToken();
ExpectToken(Token::kLPAREN);
// Parse dotted name.
- const GrowableObjectArray& pieces =
- GrowableObjectArray::Handle(Z, GrowableObjectArray::New());
- pieces.Add(*ExpectIdentifier("identifier expected"));
+ const GrowableObjectArray& pieces = GrowableObjectArray::Handle(
+ Z, GrowableObjectArray::New(allocation_space_));
+ pieces.Add(*ExpectIdentifier("identifier expected"), allocation_space_);
while (CurrentToken() == Token::kPERIOD) {
- pieces.Add(Symbols::Dot());
+ pieces.Add(Symbols::Dot(), allocation_space_);
ConsumeToken();
- pieces.Add(*ExpectIdentifier("identifier expected"));
+ pieces.Add(*ExpectIdentifier("identifier expected"), allocation_space_);
}
AstNode* valueNode = NULL;
if (CurrentToken() == Token::kEQ) {
@@ -6237,8 +6239,8 @@ void Parser::ParseLibraryImportExport(const Object& tl_owner,
continue;
}
// Check if this conditional line overrides the default import.
- const String& key = String::Handle(
- String::ConcatAll(Array::Handle(Array::MakeArray(pieces))));
+ const String& key = String::Handle(String::ConcatAll(
+ Array::Handle(Array::MakeArray(pieces)), allocation_space_));
const String& value =
(valueNode == NULL)
? Symbols::True()
@@ -6276,10 +6278,10 @@ void Parser::ParseLibraryImportExport(const Object& tl_owner,
Array& hide_names = Array::Handle(Z);
if (is_deferred_import || IsSymbol(Symbols::Show()) ||
IsSymbol(Symbols::Hide())) {
- GrowableObjectArray& show_list =
- GrowableObjectArray::Handle(Z, GrowableObjectArray::New());
- GrowableObjectArray& hide_list =
- GrowableObjectArray::Handle(Z, GrowableObjectArray::New());
+ GrowableObjectArray& show_list = GrowableObjectArray::Handle(
+ Z, GrowableObjectArray::New(allocation_space_));
+ GrowableObjectArray& hide_list = GrowableObjectArray::Handle(
+ Z, GrowableObjectArray::New(allocation_space_));
// Libraries imported through deferred import automatically hide
// the name 'loadLibrary'.
if (is_deferred_import) {
@@ -6748,14 +6750,12 @@ SequenceNode* Parser::CloseAsyncGeneratorTryBlock(SequenceNode* body) {
try_stack_->exit_finally();
}
- const GrowableObjectArray& handler_types =
- GrowableObjectArray::Handle(Z, GrowableObjectArray::New(Heap::kOld));
// Catch block handles all exceptions.
- handler_types.Add(Object::dynamic_type());
+ const Array& handler_types = Array::ZoneHandle(Z, Array::New(1, Heap::kOld));
+ handler_types.SetAt(0, Object::dynamic_type());
CatchClauseNode* catch_clause = new (Z) CatchClauseNode(
- TokenPosition::kNoSource, catch_handler_list,
- Array::ZoneHandle(Z, Array::MakeArray(handler_types)), context_var,
+ TokenPosition::kNoSource, catch_handler_list, handler_types, context_var,
exception_var, stack_trace_var, saved_exception_var,
saved_stack_trace_var, AllocateTryIndex(), true);
@@ -6850,17 +6850,14 @@ SequenceNode* Parser::CloseAsyncTryBlock(SequenceNode* try_block,
current_block_->statements->Add(catch_block);
SequenceNode* catch_handler_list = CloseBlock();
- const GrowableObjectArray& handler_types =
- GrowableObjectArray::Handle(Z, GrowableObjectArray::New(Heap::kOld));
- handler_types.SetLength(0);
- handler_types.Add(*exception_param.type);
+ const Array& handler_types = Array::ZoneHandle(Z, Array::New(1, Heap::kOld));
+ handler_types.SetAt(0, *exception_param.type);
TryStack* try_statement = PopTry();
const intptr_t try_index = try_statement->try_index();
CatchClauseNode* catch_clause = new (Z) CatchClauseNode(
- TokenPosition::kNoSource, catch_handler_list,
- Array::ZoneHandle(Z, Array::MakeArray(handler_types)), context_var,
+ TokenPosition::kNoSource, catch_handler_list, handler_types, context_var,
exception_var, stack_trace_var, saved_exception_var,
saved_stack_trace_var, CatchClauseNode::kInvalidTryIndex, true);
AstNode* try_catch_node = new (Z) TryCatchNode(
@@ -10040,7 +10037,7 @@ SequenceNode* Parser::ParseCatchClauses(
// This catch clause will handle all exceptions. We can safely forget
// all previous catch clause types.
handler_types.SetLength(0);
- handler_types.Add(*exception_param.type);
+ handler_types.Add(*exception_param.type, Heap::kOld);
} else {
// Has a type specification that is not malformed or malbounded. Now
// form an 'if type check' to guard the catch handler code.
@@ -10067,7 +10064,7 @@ SequenceNode* Parser::ParseCatchClauses(
// will report the exception as uncaught when in fact it might be
// caught and handled when we unwind the stack.
if (!generic_catch_seen && exception_param.type->IsInstantiated()) {
- handler_types.Add(*exception_param.type);
+ handler_types.Add(*exception_param.type, Heap::kOld);
}
}
@@ -12638,7 +12635,7 @@ void Parser::InsertCachedConstantValue(const Script& script,
ASSERT(!script.InVMHeap());
if (script.compile_time_constants() == Array::null()) {
const Array& array = Array::Handle(
- HashTables::New<ConstantsMap>(kInitialConstMapSize, Heap::kNew));
+ HashTables::New<ConstantsMap>(kInitialConstMapSize, Heap::kOld));
script.set_compile_time_constants(array);
}
ConstantsMap constants(script.compile_time_constants());
@@ -12786,10 +12783,10 @@ RawObject* Parser::EvaluateConstConstructorCall(
const int kNumExtraArgs = 1;
const int num_arguments = arguments->length() + kNumExtraArgs;
const Array& arg_values =
- Array::Handle(Z, Array::New(num_arguments, Heap::kOld));
+ Array::Handle(Z, Array::New(num_arguments, allocation_space_));
Instance& instance = Instance::Handle(Z);
if (!constructor.IsFactory()) {
- instance = Instance::New(type_class, Heap::kOld);
+ instance = Instance::New(type_class, allocation_space_);
if (!type_arguments.IsNull()) {
if (!type_arguments.IsInstantiated()) {
ReportError("type must be constant in const constructor");
@@ -13325,8 +13322,10 @@ RawAbstractType* Parser::ParseType(
ConsumeToken(); // Period token.
ASSERT(IsIdentifier());
String& qualified_name = String::Handle(Z, type_name.raw());
- qualified_name = String::Concat(qualified_name, Symbols::Dot());
- qualified_name = String::Concat(qualified_name, *CurrentLiteral());
+ qualified_name =
+ String::Concat(qualified_name, Symbols::Dot(), allocation_space_);
+ qualified_name =
+ String::Concat(qualified_name, *CurrentLiteral(), allocation_space_);
ConsumeToken();
// The type is malformed. Skip over its type arguments.
ParseTypeArguments(ClassFinalizer::kIgnore);
« no previous file with comments | « runtime/vm/parser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698