From 58f7dab40db417ab669a0a1e146aa6e3227e3989 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Thu, 13 Oct 2016 15:24:50 +0000 Subject: runtime: copy mstats code from Go 1.7 runtime This replaces mem.go and the C runtime_ReadMemStats function with the Go 1.7 mstats.go. The GCStats code is commented out for now. The corresponding gccgo code is in runtime/mgc0.c. The variables memstats and worldsema are shared between the Go code and the C code, but are not exported. To make this work, add temporary accessor functions acquireWorldsema, releaseWorldsema, getMstats (the latter known as mstats in the C code). Check the preemptoff field of m when allocating and when considering whether to start a GC. This works with the new stopTheWorld and startTheWorld functions in Go, which are essentially the Go 1.7 versions. Change the compiler to stack allocate closures when compiling the runtime package. Within the runtime packages closures do not escape. This is similar to what the gc compiler does, except that the gc compiler, when compiling the runtime package, gives an error if escape analysis shows that a closure does escape. I added this here because the Go version of ReadMemStats calls systemstack with a closure, and having that allocate memory was causing some tests that measure memory allocations to fail. Reviewed-on: https://go-review.googlesource.com/30972 From-SVN: r241124 --- gcc/go/gofrontend/MERGE | 2 +- gcc/go/gofrontend/parse.cc | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'gcc') diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index 08a86e9..0a116a8 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -6c9070324d5b7c8483bc7c17b0a8faaa1fb1ae30 +681580a3afc687ba3ff9ef240c67e8630e4306e6 The first line of this file holds the git revision number of the last merge done from the gofrontend repository. diff --git a/gcc/go/gofrontend/parse.cc b/gcc/go/gofrontend/parse.cc index 81525a7..b7411d1 100644 --- a/gcc/go/gofrontend/parse.cc +++ b/gcc/go/gofrontend/parse.cc @@ -3026,6 +3026,21 @@ Parse::create_closure(Named_object* function, Enclosing_vars* enclosing_vars, Struct_type* st = closure_var->var_value()->type()->deref()->struct_type(); Expression* cv = Expression::make_struct_composite_literal(st, initializer, location); + + // When compiling the runtime, closures do not escape. When escape + // analysis becomes the default, and applies to closures, this + // should be changed to make it an error if a closure escapes. + if (this->gogo_->compiling_runtime() + && this->gogo_->package_name() == "runtime") + { + Temporary_statement* ctemp = Statement::make_temporary(st, cv, location); + this->gogo_->add_statement(ctemp); + Expression* ref = Expression::make_temporary_reference(ctemp, location); + Expression* addr = Expression::make_unary(OPERATOR_AND, ref, location); + addr->unary_expression()->set_does_not_escape(); + return addr; + } + return Expression::make_heap_expression(cv, location); } -- cgit v1.1