blob: 5596a624ec09336464a6bd6ab870d6cb6e161ae5 [file] [log] [blame]
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17import java.io.IOException;
18import java.io.Writer;
19import java.io.BufferedWriter;
20import java.io.OutputStreamWriter;
21import java.io.FileOutputStream;
22import java.nio.charset.Charset;
23import java.util.Set;
24import java.util.TreeSet;
25import java.util.List;
26
27/**
28 * Writes /java/android/preloaded-classes. Also updates LoadedClass.preloaded
29 * fields and writes over compiled log file.
30 */
31public class WritePreloadedClassFile {
32
33 private static final String PRELOADED_CLASS_FILE
34 = "java/android/preloaded-classes";
35
36 public static void main(String[] args)
37 throws IOException, ClassNotFoundException {
38 if (args.length != 1) {
39 System.err.println(
40 "Usage: WritePreloadedClassFile [compiled log file]");
41 System.exit(0);
42 }
43
44 Root root = Root.fromFile(args[0]);
45
46 for (LoadedClass loadedClass : root.loadedClasses.values()) {
47 loadedClass.preloaded = false;
48 }
49
50 Writer out = new BufferedWriter(new OutputStreamWriter(
51 new FileOutputStream(PRELOADED_CLASS_FILE),
52 Charset.forName("US-ASCII")));
53
54 out.write("# Classes which are preloaded by " +
55 "com.android.internal.os.ZygoteInit.\n");
56 out.write("# Automatically generated by /tools/preload.\n");
57 out.write("# percent=" + Proc.PERCENTAGE_TO_PRELOAD + ", weight="
58 + ClassRank.SEQUENCE_WEIGHT
59 + ", bucket_size=" + ClassRank.BUCKET_SIZE
60 + "\n");
61
62 Set<LoadedClass> highestRanked = new TreeSet<LoadedClass>();
63 for (Proc proc : root.processes.values()) {
64 List<LoadedClass> highestForProc = proc.highestRankedClasses();
65
66 System.out.println(proc.name + ": " + highestForProc.size());
67
68 for (LoadedClass loadedClass : highestForProc) {
69 loadedClass.preloaded = true;
70 }
71 highestRanked.addAll(highestForProc);
72 }
73
74 for (LoadedClass loadedClass : highestRanked) {
75 out.write(loadedClass.name);
76 out.write('\n');
77 }
78
79 out.close();
80
81 System.out.println(highestRanked.size()
82 + " classes will be preloaded.");
83
84 // Update data to reflect LoadedClass.preloaded changes.
85 root.toFile(args[0]);
86 }
87}