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

Commit 22f37f6c authored by Yu-Ting Tseng's avatar Yu-Ting Tseng
Browse files

Add support for constructor instrumentation

Update dynamic instrumentation manager to use a new ART API for looking
up offsets of class constructors.

Change-Id: Ia55f09c06ffc0daf33e46f0d02b55cef0c5ae088
Bug: 400457896
Flag: com.android.art.flags.executable_method_file_offsets_v2
Test: TH
parent 4ba96e93
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -273,6 +273,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.ref.WeakReference;
import java.lang.reflect.Executable;
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.nio.file.DirectoryStream;
@@ -2268,10 +2269,16 @@ public final class ActivityThread extends ClientTransactionHandler
        public void getExecutableMethodFileOffsets(
                @NonNull MethodDescriptor methodDescriptor,
                @NonNull IOffsetCallback resultCallback) {
            Method method = MethodDescriptorParser.parseMethodDescriptor(
            Executable executable = MethodDescriptorParser.parseMethodDescriptor(
                    getClass().getClassLoader(), methodDescriptor);
            VMDebug.ExecutableMethodFileOffsets location =
                    VMDebug.getExecutableMethodFileOffsets(method);
            VMDebug.ExecutableMethodFileOffsets location;
            if (com.android.art.flags.Flags.executableMethodFileOffsetsV2()) {
                location = VMDebug.getExecutableMethodFileOffsets(executable);
            } else if (executable instanceof Method) {
                location = VMDebug.getExecutableMethodFileOffsets((Method) executable);
            } else {
                throw new UnsupportedOperationException();
            }
            try {
                if (location == null) {
                    resultCallback.onResult(null);
+7 −3
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ package android.os.instrumentation;

import android.annotation.NonNull;

import java.lang.reflect.Method;
import java.lang.reflect.Executable;

/**
 * A utility class for dynamic instrumentation / uprobestats.
@@ -28,9 +28,9 @@ import java.lang.reflect.Method;
public final class MethodDescriptorParser {

    /**
     * Parses a {@link MethodDescriptor} (in string representation) into a {@link Method}.
     * Parses a {@link MethodDescriptor} (in string representation) into a {@link Executable}.
     */
    public static Method parseMethodDescriptor(ClassLoader classLoader,
    public static Executable parseMethodDescriptor(ClassLoader classLoader,
            @NonNull MethodDescriptor descriptor) {
        try {
            Class<?> javaClass = classLoader.loadClass(descriptor.fullyQualifiedClassName);
@@ -72,6 +72,10 @@ public final class MethodDescriptorParser {
                }
            }

            if (com.android.art.flags.Flags.executableMethodFileOffsetsV2()
                    && descriptor.methodName.equals("<init>")) {
                return javaClass.getDeclaredConstructor(parameters);
            }
            return javaClass.getDeclaredMethod(descriptor.methodName, parameters);
        } catch (ClassNotFoundException | NoSuchMethodException e) {
            throw new IllegalArgumentException(
+10 −3
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import com.android.server.SystemService;

import dalvik.system.VMDebug;

import java.lang.reflect.Executable;
import java.lang.reflect.Method;
import java.util.NoSuchElementException;
import java.util.Objects;
@@ -95,10 +96,16 @@ public class DynamicInstrumentationManagerService extends SystemService {
                }
            }

            Method method = MethodDescriptorParser.parseMethodDescriptor(
            Executable executable = MethodDescriptorParser.parseMethodDescriptor(
                    getClass().getClassLoader(), methodDescriptor);
            VMDebug.ExecutableMethodFileOffsets location =
                    VMDebug.getExecutableMethodFileOffsets(method);
            VMDebug.ExecutableMethodFileOffsets location;
            if (com.android.art.flags.Flags.executableMethodFileOffsetsV2()) {
                location = VMDebug.getExecutableMethodFileOffsets(executable);
            } else if (executable instanceof Method) {
                location = VMDebug.getExecutableMethodFileOffsets((Method) executable);
            } else {
                throw new UnsupportedOperationException();
            }

            try {
                if (location == null) {
+1 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ android_test {
    static_libs: [
        "androidx.test.core",
        "androidx.test.runner",
        "flag-junit",
        "hamcrest-library",
        "platform-test-annotations",
        "services.core",
+3 −0
Original line number Diff line number Diff line
@@ -17,6 +17,9 @@
package com.android.server;

public class TestClass {
    TestClass() {
    }

    void primitiveParams(boolean a, boolean[] b, byte c, byte[] d, char e, char[] f, short g,
            short[] h, int i, int[] j, long k, long[] l, float m, float[] n, double o, double[] p) {
    }
Loading