• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007 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 
17 package android.ddm;
18 
19 import android.util.Log;
20 
21 import org.apache.harmony.dalvik.ddmc.Chunk;
22 import org.apache.harmony.dalvik.ddmc.ChunkHandler;
23 import org.apache.harmony.dalvik.ddmc.DdmServer;
24 
25 /**
26  * Handle native and virtual heap requests.
27  */
28 public class DdmHandleHeap extends DdmHandle {
29 
30     public static final int CHUNK_HPGC = ChunkHandler.type("HPGC");
31 
32     private static DdmHandleHeap mInstance = new DdmHandleHeap();
33 
34 
35     /* singleton, do not instantiate */
DdmHandleHeap()36     private DdmHandleHeap() {}
37 
38     /**
39      * Register for the messages we're interested in.
40      */
register()41     public static void register() {
42         DdmServer.registerHandler(CHUNK_HPGC, mInstance);
43     }
44 
45     /**
46      * Called when the DDM server connects.  The handler is allowed to
47      * send messages to the server.
48      */
onConnected()49     public void onConnected() {}
50 
51     /**
52      * Called when the DDM server disconnects.  Can be used to disable
53      * periodic transmissions or clean up saved state.
54      */
onDisconnected()55     public void onDisconnected() {}
56 
57     /**
58      * Handle a chunk of data.
59      */
handleChunk(Chunk request)60     public Chunk handleChunk(Chunk request) {
61         if (false)
62             Log.v("ddm-heap", "Handling " + name(request.type) + " chunk");
63         int type = request.type;
64 
65         if (type == CHUNK_HPGC) {
66             return handleHPGC(request);
67         } else {
68             throw new RuntimeException("Unknown packet " + name(type));
69         }
70     }
71 
72     /*
73      * Handle a "HeaP Garbage Collection" request.
74      */
handleHPGC(Chunk request)75     private Chunk handleHPGC(Chunk request) {
76         //ByteBuffer in = wrapChunk(request);
77 
78         if (false)
79             Log.d("ddm-heap", "Heap GC request");
80         Runtime.getRuntime().gc();
81 
82         return null;        // empty response
83     }
84 }
85