Merge "Refactor ddm ChunkHandler utility methods from libcore to framework" into sc-dev

This commit is contained in:
Victor Chang
2021-05-26 08:27:06 +00:00
committed by Android (Google) Code Review
9 changed files with 108 additions and 59 deletions

View File

@@ -6413,7 +6413,7 @@ public final class ActivityThread extends ClientTransactionHandler
VMDebug.setAllocTrackerStackDepth(Integer.parseInt(property));
}
if (data.trackAllocation) {
DdmVmInternal.enableRecentAllocations(true);
DdmVmInternal.setRecentAllocationsTrackingEnabled(true);
}
// Note when this process has started.
Process.setStartTimes(SystemClock.elapsedRealtime(), SystemClock.uptimeMillis());

View File

@@ -0,0 +1,51 @@
/*
* Copyright (C) 2021 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.
*/
package android.ddm;
import org.apache.harmony.dalvik.ddmc.ChunkHandler;
import java.nio.ByteBuffer;
/**
* Contains utility methods for chunk serialization and deserialization.
*/
public abstract class DdmHandle extends ChunkHandler {
/**
* Utility function to copy a String out of a ByteBuffer.
*
* This is here because multiple chunk handlers can make use of it,
* and there's nowhere better to put it.
*/
public static String getString(ByteBuffer buf, int len) {
char[] data = new char[len];
for (int i = 0; i < len; i++) {
data[i] = buf.getChar();
}
return new String(data);
}
/**
* Utility function to copy a String into a ByteBuffer.
*/
public static void putString(ByteBuffer buf, String str) {
int len = str.length();
for (int i = 0; i < len; i++) {
buf.putChar(str.charAt(i));
}
}
}

View File

@@ -30,9 +30,9 @@ import java.nio.ByteBuffer;
/**
* Track our app name. We don't (currently) handle any inbound packets.
*/
public class DdmHandleAppName extends ChunkHandler {
public class DdmHandleAppName extends DdmHandle {
public static final int CHUNK_APNM = type("APNM");
public static final int CHUNK_APNM = ChunkHandler.type("APNM");
private static volatile Names sNames = new Names("", "");
@@ -51,13 +51,13 @@ public class DdmHandleAppName extends ChunkHandler {
* Called when the DDM server connects. The handler is allowed to
* send messages to the server.
*/
public void connected() {}
public void onConnected() {}
/**
* Called when the DDM server disconnects. Can be used to disable
* periodic transmissions or clean up saved state.
*/
public void disconnected() {}
public void onDisconnected() {}
/**
* Handle a chunk of data.

View File

@@ -16,18 +16,20 @@
package android.ddm;
import android.util.Log;
import org.apache.harmony.dalvik.ddmc.Chunk;
import org.apache.harmony.dalvik.ddmc.ChunkHandler;
import org.apache.harmony.dalvik.ddmc.DdmServer;
import android.util.Log;
import java.nio.ByteBuffer;
/**
* Handle an EXIT chunk.
*/
public class DdmHandleExit extends ChunkHandler {
public class DdmHandleExit extends DdmHandle {
public static final int CHUNK_EXIT = type("EXIT");
public static final int CHUNK_EXIT = ChunkHandler.type("EXIT");
private static DdmHandleExit mInstance = new DdmHandleExit();
@@ -46,13 +48,13 @@ public class DdmHandleExit extends ChunkHandler {
* Called when the DDM server connects. The handler is allowed to
* send messages to the server.
*/
public void connected() {}
public void onConnected() {}
/**
* Called when the DDM server disconnects. Can be used to disable
* periodic transmissions or clean up saved state.
*/
public void disconnected() {}
public void onDisconnected() {}
/**
* Handle a chunk of data. We're only registered for "EXIT".

View File

@@ -16,21 +16,18 @@
package android.ddm;
import android.util.Log;
import org.apache.harmony.dalvik.ddmc.Chunk;
import org.apache.harmony.dalvik.ddmc.ChunkHandler;
import org.apache.harmony.dalvik.ddmc.DdmServer;
import org.apache.harmony.dalvik.ddmc.DdmVmInternal;
import android.os.Debug;
import android.util.Log;
import java.io.IOException;
import java.nio.ByteBuffer;
/**
* Handle native and virtual heap requests.
*/
public class DdmHandleHeap extends ChunkHandler {
public class DdmHandleHeap extends DdmHandle {
public static final int CHUNK_HPGC = type("HPGC");
public static final int CHUNK_HPGC = ChunkHandler.type("HPGC");
private static DdmHandleHeap mInstance = new DdmHandleHeap();
@@ -49,13 +46,13 @@ public class DdmHandleHeap extends ChunkHandler {
* Called when the DDM server connects. The handler is allowed to
* send messages to the server.
*/
public void connected() {}
public void onConnected() {}
/**
* Called when the DDM server disconnects. Can be used to disable
* periodic transmissions or clean up saved state.
*/
public void disconnected() {}
public void onDisconnected() {}
/**
* Handle a chunk of data.
@@ -68,8 +65,7 @@ public class DdmHandleHeap extends ChunkHandler {
if (type == CHUNK_HPGC) {
return handleHPGC(request);
} else {
throw new RuntimeException("Unknown packet "
+ ChunkHandler.name(type));
throw new RuntimeException("Unknown packet " + name(type));
}
}

View File

@@ -31,11 +31,11 @@ import java.nio.ByteBuffer;
/**
* Handle "hello" messages and feature discovery.
*/
public class DdmHandleHello extends ChunkHandler {
public class DdmHandleHello extends DdmHandle {
public static final int CHUNK_HELO = type("HELO");
public static final int CHUNK_WAIT = type("WAIT");
public static final int CHUNK_FEAT = type("FEAT");
public static final int CHUNK_HELO = ChunkHandler.type("HELO");
public static final int CHUNK_WAIT = ChunkHandler.type("WAIT");
public static final int CHUNK_FEAT = ChunkHandler.type("FEAT");
private static final int CLIENT_PROTOCOL_VERSION = 1;
@@ -61,15 +61,14 @@ public class DdmHandleHello extends ChunkHandler {
* Called when the DDM server connects. The handler is allowed to
* send messages to the server.
*/
public void connected() {
public void onConnected() {
if (false)
Log.v("ddm-hello", "Connected!");
if (false) {
/* test spontaneous transmission */
byte[] data = new byte[] { 0, 1, 2, 3, 4, -4, -3, -2, -1, 127 };
Chunk testChunk =
new Chunk(ChunkHandler.type("TEST"), data, 1, data.length-2);
Chunk testChunk = new Chunk(ChunkHandler.type("TEST"), data, 1, data.length - 2);
DdmServer.sendChunk(testChunk);
}
}
@@ -78,7 +77,7 @@ public class DdmHandleHello extends ChunkHandler {
* Called when the DDM server disconnects. Can be used to disable
* periodic transmissions or clean up saved state.
*/
public void disconnected() {
public void onDisconnected() {
if (false)
Log.v("ddm-hello", "Disconnected!");
}
@@ -96,8 +95,7 @@ public class DdmHandleHello extends ChunkHandler {
} else if (type == CHUNK_FEAT) {
return handleFEAT(request);
} else {
throw new RuntimeException("Unknown packet "
+ ChunkHandler.name(type));
throw new RuntimeException("Unknown packet " + name(type));
}
}

View File

@@ -16,17 +16,18 @@
package android.ddm;
import android.util.Log;
import org.apache.harmony.dalvik.ddmc.Chunk;
import org.apache.harmony.dalvik.ddmc.ChunkHandler;
import org.apache.harmony.dalvik.ddmc.DdmServer;
import android.util.Log;
/**
* Handle thread-related traffic.
*/
public class DdmHandleNativeHeap extends ChunkHandler {
public class DdmHandleNativeHeap extends DdmHandle {
public static final int CHUNK_NHGT = type("NHGT");
public static final int CHUNK_NHGT = ChunkHandler.type("NHGT");
private static DdmHandleNativeHeap mInstance = new DdmHandleNativeHeap();
@@ -45,13 +46,13 @@ public class DdmHandleNativeHeap extends ChunkHandler {
* Called when the DDM server connects. The handler is allowed to
* send messages to the server.
*/
public void connected() {}
public void onConnected() {}
/**
* Called when the DDM server disconnects. Can be used to disable
* periodic transmissions or clean up saved state.
*/
public void disconnected() {}
public void onDisconnected() {}
/**
* Handle a chunk of data.
@@ -63,8 +64,7 @@ public class DdmHandleNativeHeap extends ChunkHandler {
if (type == CHUNK_NHGT) {
return handleNHGT(request);
} else {
throw new RuntimeException("Unknown packet "
+ ChunkHandler.name(type));
throw new RuntimeException("Unknown packet " + name(type));
}
}

View File

@@ -16,25 +16,28 @@
package android.ddm;
import android.os.Debug;
import android.util.Log;
import org.apache.harmony.dalvik.ddmc.Chunk;
import org.apache.harmony.dalvik.ddmc.ChunkHandler;
import org.apache.harmony.dalvik.ddmc.DdmServer;
import android.os.Debug;
import android.util.Log;
import java.nio.ByteBuffer;
/**
* Handle profiling requests.
*/
public class DdmHandleProfiling extends ChunkHandler {
public class DdmHandleProfiling extends DdmHandle {
public static final int CHUNK_MPRS = type("MPRS");
public static final int CHUNK_MPRE = type("MPRE");
public static final int CHUNK_MPSS = type("MPSS");
public static final int CHUNK_MPSE = type("MPSE");
public static final int CHUNK_MPRQ = type("MPRQ");
public static final int CHUNK_SPSS = type("SPSS");
public static final int CHUNK_SPSE = type("SPSE");
public static final int CHUNK_MPRS = ChunkHandler.type("MPRS");
public static final int CHUNK_MPRE = ChunkHandler.type("MPRE");
public static final int CHUNK_MPSS = ChunkHandler.type("MPSS");
public static final int CHUNK_MPSE = ChunkHandler.type("MPSE");
public static final int CHUNK_MPRQ = ChunkHandler.type("MPRQ");
public static final int CHUNK_SPSS = ChunkHandler.type("SPSS");
public static final int CHUNK_SPSE = ChunkHandler.type("SPSE");
private static final boolean DEBUG = false;
private static DdmHandleProfiling mInstance = new DdmHandleProfiling();
@@ -60,13 +63,13 @@ public class DdmHandleProfiling extends ChunkHandler {
* Called when the DDM server connects. The handler is allowed to
* send messages to the server.
*/
public void connected() {}
public void onConnected() {}
/**
* Called when the DDM server disconnects. Can be used to disable
* periodic transmissions or clean up saved state.
*/
public void disconnected() {}
public void onDisconnected() {}
/**
* Handle a chunk of data.
@@ -91,8 +94,7 @@ public class DdmHandleProfiling extends ChunkHandler {
} else if (type == CHUNK_SPSE) {
return handleMPSEOrSPSE(request, "Sample");
} else {
throw new RuntimeException("Unknown packet "
+ ChunkHandler.name(type));
throw new RuntimeException("Unknown packet " + name(type));
}
}

View File

@@ -39,12 +39,12 @@ import java.nio.ByteBuffer;
* Handle various requests related to profiling / debugging of the view system.
* Support for these features are advertised via {@link DdmHandleHello}.
*/
public class DdmHandleViewDebug extends ChunkHandler {
public class DdmHandleViewDebug extends DdmHandle {
/** List {@link ViewRootImpl}'s of this process. */
private static final int CHUNK_VULW = type("VULW");
private static final int CHUNK_VULW = ChunkHandler.type("VULW");
/** Operation on view root, first parameter in packet should be one of VURT_* constants */
private static final int CHUNK_VURT = type("VURT");
private static final int CHUNK_VURT = ChunkHandler.type("VURT");
/** Dump view hierarchy. */
private static final int VURT_DUMP_HIERARCHY = 1;
@@ -59,7 +59,7 @@ public class DdmHandleViewDebug extends ChunkHandler {
* Generic View Operation, first parameter in the packet should be one of the
* VUOP_* constants below.
*/
private static final int CHUNK_VUOP = type("VUOP");
private static final int CHUNK_VUOP = ChunkHandler.type("VUOP");
/** Capture View. */
private static final int VUOP_CAPTURE_VIEW = 1;
@@ -99,11 +99,11 @@ public class DdmHandleViewDebug extends ChunkHandler {
}
@Override
public void connected() {
public void onConnected() {
}
@Override
public void disconnected() {
public void onDisconnected() {
}
@Override
@@ -154,7 +154,7 @@ public class DdmHandleViewDebug extends ChunkHandler {
return createFailChunk(ERR_INVALID_OP, "Unknown view operation: " + op);
}
} else {
throw new RuntimeException("Unknown packet " + ChunkHandler.name(type));
throw new RuntimeException("Unknown packet " + name(type));
}
}