aboutsummaryrefslogtreecommitdiff
path: root/gcc/go/gofrontend/parse.cc
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2016-10-13 15:24:50 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2016-10-13 15:24:50 +0000
commit58f7dab40db417ab669a0a1e146aa6e3227e3989 (patch)
treed5aaac15d5bd0d4b125140016f3ea84a714e3713 /gcc/go/gofrontend/parse.cc
parent5b1548fd79423c451b96f897701dc4aa51131b86 (diff)
downloadgcc-58f7dab40db417ab669a0a1e146aa6e3227e3989.zip
gcc-58f7dab40db417ab669a0a1e146aa6e3227e3989.tar.gz
gcc-58f7dab40db417ab669a0a1e146aa6e3227e3989.tar.bz2
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
Diffstat (limited to 'gcc/go/gofrontend/parse.cc')
-rw-r--r--gcc/go/gofrontend/parse.cc15
1 files changed, 15 insertions, 0 deletions
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);
}