Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4d2eeed0 authored by Ulya Trafimovich's avatar Ulya Trafimovich Committed by Ulyana Trafimovich
Browse files

Use boot image extension for framework libraries.

This patch splits the system boot image in two parts:

  - The ART boot image. This is the primary boot image that is
    included in the ART apex and contains dexpreopted Core Libraries.

  - The framweork boot image extension. It depends on the ART boot
    image and contains framework libraries.

The third "apex" boot image (used in the JIT-zygote experiment)
remains unchanged; it is a monolithic primary boot image that
contains both libcore and framework libraries.

Dexpreopting of APKs now uses the framework boot image extension
(which in turn pulls in the ART boot image as a dependency).

Test: m
Test: phone boots:
    lunch aosp_walleye-userdebug && m \
        && adb reboot bootloader && fastboot flashall -w

Bug: b/119800099

Exempt-From-Owner-Approval: rebased after getting approval.

Change-Id: Ida40dfae8c83bf7c2e737d5c7ea418e1197ad826
parent 3ae3b170
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -247,6 +247,33 @@ func PathsForModuleSrcExcludes(ctx ModuleContext, paths, excludes []string) Path
	return ret
}

// OutputPaths is a slice of OutputPath objects, with helpers to operate on the collection.
type OutputPaths []OutputPath

// Paths returns the OutputPaths as a Paths
func (p OutputPaths) Paths() Paths {
	if p == nil {
		return nil
	}
	ret := make(Paths, len(p))
	for i, path := range p {
		ret[i] = path
	}
	return ret
}

// Strings returns the string forms of the writable paths.
func (p OutputPaths) Strings() []string {
	if p == nil {
		return nil
	}
	ret := make([]string, len(p))
	for i, path := range p {
		ret[i] = path.String()
	}
	return ret
}

// PathsAndMissingDepsForModuleSrcExcludes returns Paths rooted from the module's local source directory, excluding
// paths listed in the excludes arguments, and a list of missing dependencies.  It expands globs, references to
// SourceFileProducer modules using the ":name" syntax, and references to OutputFileProducer modules using the
+8 −5
Original line number Diff line number Diff line
@@ -119,7 +119,8 @@ type ModuleConfig struct {

	Archs                   []android.ArchType
	DexPreoptImages         []android.Path
	DexPreoptImagesDeps []android.Paths
	DexPreoptImagesDeps     []android.OutputPaths
	DexPreoptImageLocations []string

	PreoptBootClassPathDexFiles     android.Paths // file paths of boot class path files
	PreoptBootClassPathDexLocations []string      // virtual locations of boot class path files
@@ -225,6 +226,7 @@ func LoadModuleConfig(ctx android.PathContext, path string) (ModuleConfig, error
		ProfileClassListing         string
		LibraryPaths                map[string]string
		DexPreoptImages             []string
		DexPreoptImageLocations     []string
		PreoptBootClassPathDexFiles []string
	}

@@ -242,10 +244,11 @@ func LoadModuleConfig(ctx android.PathContext, path string) (ModuleConfig, error
	config.ModuleConfig.ProfileClassListing = android.OptionalPathForPath(constructPath(ctx, config.ProfileClassListing))
	config.ModuleConfig.LibraryPaths = constructPathMap(ctx, config.LibraryPaths)
	config.ModuleConfig.DexPreoptImages = constructPaths(ctx, config.DexPreoptImages)
	config.ModuleConfig.DexPreoptImageLocations = config.DexPreoptImageLocations
	config.ModuleConfig.PreoptBootClassPathDexFiles = constructPaths(ctx, config.PreoptBootClassPathDexFiles)

	// This needs to exist, but dependencies are already handled in Make, so we don't need to pass them through JSON.
	config.ModuleConfig.DexPreoptImagesDeps = make([]android.Paths, len(config.ModuleConfig.DexPreoptImages))
	config.ModuleConfig.DexPreoptImagesDeps = make([]android.OutputPaths, len(config.ModuleConfig.DexPreoptImages))

	return config.ModuleConfig, nil
}
+8 −15
Original line number Diff line number Diff line
@@ -86,10 +86,8 @@ func GenerateDexpreoptRule(ctx android.PathContext,

			generateDM := shouldGenerateDM(module, global)

			for i, arch := range module.Archs {
				image := module.DexPreoptImages[i]
				imageDeps := module.DexPreoptImagesDeps[i]
				dexpreoptCommand(ctx, global, module, rule, arch, profile, image, imageDeps, appImage, generateDM)
			for archIdx, _ := range module.Archs {
				dexpreoptCommand(ctx, global, module, rule, archIdx, profile, appImage, generateDM)
			}
		}
	}
@@ -193,7 +191,9 @@ func bootProfileCommand(ctx android.PathContext, global GlobalConfig, module Mod
}

func dexpreoptCommand(ctx android.PathContext, global GlobalConfig, module ModuleConfig, rule *android.RuleBuilder,
	arch android.ArchType, profile, bootImage android.Path, bootImageDeps android.Paths, appImage, generateDM bool) {
	archIdx int, profile android.WritablePath, appImage bool, generateDM bool) {

	arch := module.Archs[archIdx]

	// HACK: make soname in Soong-generated .odex files match Make.
	base := filepath.Base(module.DexLocation)
@@ -222,13 +222,6 @@ func dexpreoptCommand(ctx android.PathContext, global GlobalConfig, module Modul

	invocationPath := odexPath.ReplaceExtension(ctx, "invocation")

	// bootImage is .../dex_bootjars/system/framework/arm64/boot.art, but dex2oat wants
	// .../dex_bootjars/system/framework/boot.art on the command line
	var bootImageLocation string
	if bootImage != nil {
		bootImageLocation = PathToLocation(bootImage, arch)
	}

	// The class loader context using paths in the build
	var classLoaderContextHost android.Paths

@@ -356,7 +349,7 @@ func dexpreoptCommand(ctx android.PathContext, global GlobalConfig, module Modul
		Flag("--runtime-arg").FlagWithList("-Xbootclasspath-locations:", module.PreoptBootClassPathDexLocations, ":").
		Flag("${class_loader_context_arg}").
		Flag("${stored_class_loader_context_arg}").
		FlagWithArg("--boot-image=", bootImageLocation).Implicits(bootImageDeps).
		FlagWithArg("--boot-image=", strings.Join(module.DexPreoptImageLocations, ":")).Implicits(module.DexPreoptImagesDeps[archIdx].Paths()).
		FlagWithInput("--dex-file=", module.DexPath).
		FlagWithArg("--dex-location=", dexLocationArg).
		FlagWithOutput("--oat-file=", odexPath).ImplicitOutput(vdexPath).
@@ -555,7 +548,7 @@ func SplitApexJarPair(apexJarValue string) (string, string) {
}

// Expected format for apexJarValue = <apex name>:<jar name>
func GetJarLocationFromApexJarPair(apexJarValue string) (string) {
func GetJarLocationFromApexJarPair(apexJarValue string) string {
	apex, jar := SplitApexJarPair(apexJarValue)
	return filepath.Join("/apex", apex, "javalib", jar+".jar")
}
+2 −1
Original line number Diff line number Diff line
@@ -49,7 +49,8 @@ func testModuleConfig(ctx android.PathContext, name, partition string) ModuleCon
		LibraryPaths:                    nil,
		Archs:                           []android.ArchType{android.Arm},
		DexPreoptImages:                 android.Paths{android.PathForTesting("system/framework/arm/boot.art")},
		DexPreoptImagesDeps:             []android.Paths{android.Paths{}},
		DexPreoptImagesDeps:             []android.OutputPaths{android.OutputPaths{}},
		DexPreoptImageLocations:         []string{},
		PreoptBootClassPathDexFiles:     nil,
		PreoptBootClassPathDexLocations: nil,
		PreoptExtractedApk:              false,
+7 −6
Original line number Diff line number Diff line
@@ -124,7 +124,7 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Mo
	}

	var images android.Paths
	var imagesDeps []android.Paths
	var imagesDeps []android.OutputPaths
	for _, arch := range archs {
		images = append(images, bootImage.images[arch])
		imagesDeps = append(imagesDeps, bootImage.imagesDeps[arch])
@@ -172,12 +172,13 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Mo
		Archs:                   archs,
		DexPreoptImages:         images,
		DexPreoptImagesDeps:     imagesDeps,
		DexPreoptImageLocations: bootImage.imageLocations,

		// We use the dex paths and dex locations of the default boot image, as it
		// contains the full dexpreopt boot classpath. Other images may just contain a subset of
		// the dexpreopt boot classpath.
		PreoptBootClassPathDexFiles:     defaultBootImage.dexPaths.Paths(),
		PreoptBootClassPathDexLocations: defaultBootImage.dexLocations,
		PreoptBootClassPathDexFiles:     defaultBootImage.dexPathsDeps.Paths(),
		PreoptBootClassPathDexLocations: defaultBootImage.dexLocationsDeps,

		PreoptExtractedApk: false,

Loading