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

Unified Diff: runtime/vm/parser.cc

Issue 2901103004: Experimental code to detect transitive closure of parser code which causes new-space allocations
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') | runtime/vm/thread.h » ('j') | 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 a26173d50ad5a8c4f09ceddff3c3537758376063..5f9f494f42b364d3c3142b725c4953cef81c4137 100644
--- a/runtime/vm/parser.cc
+++ b/runtime/vm/parser.cc
@@ -132,6 +132,25 @@ class TraceParser : public ValueObject {
#define TRACE_PARSER(s)
#endif // DEBUG
+EnterParserScope::EnterParserScope(Thread* thread)
+ : StackResource(thread), old_(thread->inside_parser_) {
+ thread->inside_parser_ = true;
+}
+EnterParserScope::~EnterParserScope() {
+ RELEASE_ASSERT(thread()->inside_parser_);
+ thread()->inside_parser_ = old_;
+}
+
+
+LeaveParserScope::LeaveParserScope(Thread* thread)
+ : StackResource(thread), old_(thread->inside_parser_) {
+ thread->inside_parser_ = false;
+}
+LeaveParserScope::~LeaveParserScope() {
+ RELEASE_ASSERT(!thread()->inside_parser_);
+ thread()->inside_parser_ = old_;
+}
+
class BoolScope : public ValueObject {
public:
@@ -457,7 +476,8 @@ Parser::Parser(const Script& script,
TokenPosition token_pos)
: thread_(Thread::Current()),
isolate_(thread()->isolate()),
- allocation_space_(thread_->IsMutatorThread() ? Heap::kNew : Heap::kOld),
+ enter_parser_scope_(thread_),
+ allocation_space_(Heap::kOld),
script_(Script::Handle(zone(), script.raw())),
tokens_iterator_(zone(),
TokenStream::Handle(zone(), script.tokens()),
@@ -490,7 +510,8 @@ Parser::Parser(const Script& script,
TokenPosition token_pos)
: thread_(Thread::Current()),
isolate_(thread()->isolate()),
- allocation_space_(thread_->IsMutatorThread() ? Heap::kNew : Heap::kOld),
+ enter_parser_scope_(thread_),
+ allocation_space_(Heap::kOld),
script_(Script::Handle(zone(), script.raw())),
tokens_iterator_(zone(),
TokenStream::Handle(zone(), script.tokens()),
@@ -6140,6 +6161,7 @@ RawObject* Parser::CallLibraryTagHandler(Dart_LibraryTag tag,
I->BlockClassFinalization();
Object& result = Object::Handle(Z);
{
+ LeaveParserScope _(thread_);
TransitionVMToNative transition(T);
Api::Scope api_scope(T);
Dart_Handle retval = handler(tag, Api::NewHandle(T, library_.raw()),
@@ -6246,8 +6268,11 @@ void Parser::ParseLibraryImportExport(const Object& tl_owner,
? Symbols::True()
: String::Cast(valueNode->AsLiteralNode()->literal());
// Call the embedder to supply us with the environment.
- const String& env_value =
- String::Handle(Api::GetEnvironmentValue(T, key));
+ String& env_value = String::Handle();
+ {
+ LeaveParserScope _(thread_);
+ env_value = Api::GetEnvironmentValue(T, key);
+ }
if (!env_value.IsNull() && env_value.Equals(value)) {
condition_triggered = true;
url_literal = conditional_url_literal;
@@ -12729,7 +12754,10 @@ StaticGetterNode* Parser::RunStaticFieldInitializer(
ASSERT(!func.IsNull());
ASSERT(func.kind() == RawFunction::kImplicitStaticFinalGetter);
Object& const_value = Object::Handle(Z);
- const_value = DartEntry::InvokeFunction(func, Object::empty_array());
+ {
+ LeaveParserScope _(thread_);
+ const_value = DartEntry::InvokeFunction(func, Object::empty_array());
+ }
if (const_value.IsError()) {
const Error& error = Error::Cast(const_value);
if (error.IsUnhandledException()) {
@@ -12809,8 +12837,14 @@ RawObject* Parser::EvaluateConstConstructorCall(
const Array& args_descriptor =
Array::Handle(Z, ArgumentsDescriptor::New(kTypeArgsLen, num_arguments,
arguments->names()));
- const Object& result = Object::Handle(
- Z, DartEntry::InvokeFunction(constructor, arg_values, args_descriptor));
+
+ Object& result = Object::Handle(Z);
+ {
+ LeaveParserScope _(thread_);
+ result =
+ DartEntry::InvokeFunction(constructor, arg_values, args_descriptor);
+ }
+
if (result.IsError()) {
// An exception may not occur in every parse attempt, i.e., the
// generated AST is not deterministic. Therefore mark the function as
@@ -14412,7 +14446,10 @@ String& Parser::Interpolate(const GrowableArray<AstNode*>& values) {
// Call interpolation function.
Object& result = Object::Handle(Z);
- result = DartEntry::InvokeFunction(func, interpolate_arg);
+ {
+ LeaveParserScope _(thread_);
+ result = DartEntry::InvokeFunction(func, interpolate_arg);
+ }
if (result.IsUnhandledException()) {
ReportError("%s", Error::Cast(result).ToErrorCString());
}
@@ -14779,7 +14816,11 @@ const Instance& Parser::EvaluateConstExpr(TokenPosition expr_pos,
seq->Add(ret);
INC_STAT(thread_, num_execute_const, 1);
- Object& result = Object::Handle(Z, Compiler::ExecuteOnce(seq));
+ Object& result = Object::Handle(Z);
+ {
+ LeaveParserScope _(thread_);
+ result = Compiler::ExecuteOnce(seq);
+ }
if (result.IsError()) {
ReportErrors(Error::Cast(result), script_, expr_pos,
"error evaluating constant expression");
« no previous file with comments | « runtime/vm/parser.h ('k') | runtime/vm/thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698