blob: 471cc842a8e08c86b7b10e94f9976ad6f33ebc73 [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 android.util.Log;
18import android.os.Debug;
19
20/**
21 * Loads a class, runs the garbage collector, and prints showmap output.
22 *
23 * <p>Usage: dalvikvm LoadClass [class name]
24 */
25class LoadClass {
26
27 public static void main(String[] args) {
28 System.loadLibrary("android_runtime");
29
30 if (registerNatives() < 0) {
31 throw new RuntimeException("Error registering natives.");
32 }
33
34 Debug.startAllocCounting();
35
36 if (args.length > 0) {
37 try {
38 Class.forName(args[0]);
39 } catch (ClassNotFoundException e) {
40 Log.w("LoadClass", e);
41 return;
42 }
43 }
44
45 System.gc();
46
47 int allocCount = Debug.getGlobalAllocCount();
48 int allocSize = Debug.getGlobalAllocSize();
49 int freedCount = Debug.getGlobalFreedCount();
50 int freedSize = Debug.getGlobalFreedSize();
51 long nativeHeapSize = Debug.getNativeHeapSize();
52
53 Debug.stopAllocCounting();
54
55 StringBuilder response = new StringBuilder("DECAFBAD");
56
57 int[] pages = new int[6];
58 Debug.MemoryInfo memoryInfo = new Debug.MemoryInfo();
59 Debug.getMemoryInfo(memoryInfo);
60 response.append(',').append(memoryInfo.nativeSharedDirty);
61 response.append(',').append(memoryInfo.dalvikSharedDirty);
62 response.append(',').append(memoryInfo.otherSharedDirty);
63 response.append(',').append(memoryInfo.nativePrivateDirty);
64 response.append(',').append(memoryInfo.dalvikPrivateDirty);
65 response.append(',').append(memoryInfo.otherPrivateDirty);
66
67 response.append(',').append(allocCount);
68 response.append(',').append(allocSize);
69 response.append(',').append(freedCount);
70 response.append(',').append(freedSize);
71 response.append(',').append(nativeHeapSize);
72
73 System.out.println(response.toString());
74 }
75
76 /**
77 * Registers native functions. See AndroidRuntime.cpp.
78 */
79 static native int registerNatives();
80}