Merge "Improve java_sdk_library handling of test_current"
diff --git a/cc/ccdeps.go b/cc/ccdeps.go
index 4e23a7b..225405c 100644
--- a/cc/ccdeps.go
+++ b/cc/ccdeps.go
@@ -17,7 +17,6 @@
 import (
 	"encoding/json"
 	"fmt"
-	"os"
 	"path"
 	"sort"
 	"strings"
@@ -106,7 +105,7 @@
 
 	moduleDeps.Modules = moduleInfos
 
-	ccfpath := android.PathForOutput(ctx, ccdepsJsonFileName).String()
+	ccfpath := android.PathForOutput(ctx, ccdepsJsonFileName)
 	err := createJsonFile(moduleDeps, ccfpath)
 	if err != nil {
 		ctx.Errorf(err.Error())
@@ -236,17 +235,14 @@
 	return m
 }
 
-func createJsonFile(moduleDeps ccDeps, ccfpath string) error {
-	file, err := os.Create(ccfpath)
-	if err != nil {
-		return fmt.Errorf("Failed to create file: %s, relative: %v", ccdepsJsonFileName, err)
-	}
-	defer file.Close()
-	moduleDeps.Modules = sortMap(moduleDeps.Modules)
+func createJsonFile(moduleDeps ccDeps, ccfpath android.WritablePath) error {
 	buf, err := json.MarshalIndent(moduleDeps, "", "\t")
 	if err != nil {
-		return fmt.Errorf("Write file failed: %s, relative: %v", ccdepsJsonFileName, err)
+		return fmt.Errorf("JSON marshal of cc deps failed: %s", err)
 	}
-	fmt.Fprintf(file, string(buf))
+	err = android.WriteFileToOutputDir(ccfpath, buf, 0666)
+	if err != nil {
+		return fmt.Errorf("Writing cc deps to %s failed: %s", ccfpath.String(), err)
+	}
 	return nil
 }
diff --git a/cc/config/global.go b/cc/config/global.go
index 44de4d5..ec09d22 100644
--- a/cc/config/global.go
+++ b/cc/config/global.go
@@ -168,6 +168,9 @@
 			flags = append(flags, "-ftrivial-auto-var-init=pattern")
 		} else if ctx.Config().IsEnvTrue("AUTO_UNINITIALIZE") {
 			flags = append(flags, "-ftrivial-auto-var-init=uninitialized")
+		} else {
+			// Default to pattern initialization.
+			flags = append(flags, "-ftrivial-auto-var-init=pattern")
 		}
 
 		return strings.Join(flags, " ")
diff --git a/cc/pgo.go b/cc/pgo.go
index 6c39d83..8eb3400 100644
--- a/cc/pgo.go
+++ b/cc/pgo.go
@@ -43,7 +43,7 @@
 const profileInstrumentFlag = "-fprofile-generate=/data/local/tmp"
 const profileSamplingFlag = "-gmlt -fdebug-info-for-profiling"
 const profileUseInstrumentFormat = "-fprofile-use=%s"
-const profileUseSamplingFormat = "-fprofile-sample-use=%s"
+const profileUseSamplingFormat = "-fprofile-sample-accurate -fprofile-sample-use=%s"
 
 func getPgoProfileProjects(config android.DeviceConfig) []string {
 	return config.OnceStringSlice(pgoProfileProjectsConfigKey, func() []string {