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

Commit 6ba69734 authored by Android (Google) Code Review's avatar Android (Google) Code Review
Browse files

Merge change 21178 into donut

* changes:
  Simplified algorithm used to generate the preloaded-classes list. Generated a new preloaded-classes file.
parents d9d25760 9d2d6e14
Loading
Loading
Loading
Loading
+204 −1319

File changed.

Preview size limit exceeded, changes collapsed.

+190 KiB (15.2 MiB)

File changed.

No diff preview for this file type.

+1 −1
Original line number Diff line number Diff line
@@ -3,13 +3,13 @@ LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_SRC_FILES := \
	ClassRank.java \
	Compile.java  \
	LoadedClass.java \
	MemoryUsage.java \
	Operation.java \
	Policy.java \
	PrintCsv.java \
	PrintHtmlDiff.java \
	PrintPsTree.java \
	Proc.java \
	Record.java \

tools/preload/ClassRank.java

deleted100644 → 0
+0 −53
Original line number Diff line number Diff line
/*
 * Copyright (C) 2008 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.Comparator;

/**
 * Ranks classes for preloading based on how long their operations took
 * and how early the operations happened. Higher ranked classes come first.
 */
class ClassRank implements Comparator<Operation> {

    /**
     * Increase this number to add more weight to classes which were loaded
     * earlier.
     */
    static final int SEQUENCE_WEIGHT = 500; // 0.5ms

    static final int BUCKET_SIZE = 5;

    public int compare(Operation a, Operation b) {
        // Higher ranked operations should come first.
        int result = rankOf(b) - rankOf(a);
        if (result != 0) {
            return result;
        }

        // Make sure we don't drop one of two classes w/ the same rank.
        // If a load and an initialization have the same rank, it's OK
        // to treat the operations equally.
        return a.loadedClass.name.compareTo(b.loadedClass.name);
    }

    /** Ranks the given operation. */
    private static int rankOf(Operation o) {
        return o.medianExclusiveTimeMicros()
                + SEQUENCE_WEIGHT / (o.index / BUCKET_SIZE + 1);
    }
}

+14 −37
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ class LoadedClass implements Serializable, Comparable<LoadedClass> {
    }

    void measureMemoryUsage() {
//        this.memoryUsage = MemoryUsage.forClass(name);
        this.memoryUsage = MemoryUsage.forClass(name);
    }

    int mlt = -1;
@@ -76,6 +76,10 @@ class LoadedClass implements Serializable, Comparable<LoadedClass> {
        return mit = calculateMedian(initializations);
    }

    int medianTimeMicros() {
        return medianInitTimeMicros() + medianLoadTimeMicros();
    }

    /** Calculates the median duration for a list of operations. */
    private static int calculateMedian(List<Operation> operations) {
        int size = operations.size();
@@ -99,18 +103,18 @@ class LoadedClass implements Serializable, Comparable<LoadedClass> {
        }
    }

    /** Returns names of apps that loaded this class. */
    Set<String> applicationNames() {
        Set<String> appNames = new HashSet<String>();
        addProcessNames(loads, appNames);
        addProcessNames(initializations, appNames);
        return appNames;
    /** Returns names of processes that loaded this class. */
    Set<String> processNames() {
        Set<String> names = new HashSet<String>();
        addProcessNames(loads, names);
        addProcessNames(initializations, names);
        return names;
    }

    private void addProcessNames(List<Operation> ops, Set<String> appNames) {
    private void addProcessNames(List<Operation> ops, Set<String> names) {
        for (Operation operation : ops) {
            if (operation.process.isApplication()) {
                appNames.add(operation.process.name);
            if (operation.process.fromZygote()) {
                names.add(operation.process.name);
            }
        }
    }
@@ -123,31 +127,4 @@ class LoadedClass implements Serializable, Comparable<LoadedClass> {
    public String toString() {
        return name;
    }

    /**
     * Returns true if this class's initialization causes the given class to
     * initialize.
     */
    public boolean initializes(LoadedClass clazz, Set<LoadedClass> visited) {
        // Avoid infinite recursion.
        if (!visited.add(this)) {
            return false;
        }

        if (clazz == this) {
            return true;
        }

        for (Operation initialization : initializations) {
            if (initialization.loadedClass.initializes(clazz, visited)) {
                return true;
            }
        }

        return false;
    }

    public boolean isPreloadable() {
        return systemClass && Policy.isPreloadableClass(name);
    }
}
Loading