OSDN Git Service

Allow to attach jvmti agents from inside of process
authorPhilip P. Moltmann <moltmann@google.com>
Wed, 1 Nov 2017 22:22:02 +0000 (15:22 -0700)
committerPhilip P. Moltmann <moltmann@google.com>
Fri, 3 Nov 2017 17:33:21 +0000 (10:33 -0700)
Test: cts-tradefed run singleCommand cts-dev -m CtsJvmtiAttachingTestCases
Bug: 65016018
Change-Id: I6d445afa288c6fec1d860150159fa05ed63cf517

api/current.txt
api/system-current.txt
api/test-current.txt
core/java/android/os/Debug.java

index 518d972..b520e58 100644 (file)
@@ -30747,6 +30747,7 @@ package android.os {
   }
 
   public final class Debug {
+    method public static void attachJvmtiAgent(java.lang.String, java.lang.String) throws java.io.IOException;
     method public static deprecated void changeDebugPort(int);
     method public static void dumpHprofData(java.lang.String) throws java.io.IOException;
     method public static boolean dumpService(java.lang.String, java.io.FileDescriptor, java.lang.String[]);
index 03fdf3a..065d637 100644 (file)
@@ -33470,6 +33470,7 @@ package android.os {
   }
 
   public final class Debug {
+    method public static void attachJvmtiAgent(java.lang.String, java.lang.String) throws java.io.IOException;
     method public static deprecated void changeDebugPort(int);
     method public static void dumpHprofData(java.lang.String) throws java.io.IOException;
     method public static boolean dumpService(java.lang.String, java.io.FileDescriptor, java.lang.String[]);
index 57c6581..016990c 100644 (file)
@@ -30857,6 +30857,7 @@ package android.os {
   }
 
   public final class Debug {
+    method public static void attachJvmtiAgent(java.lang.String, java.lang.String) throws java.io.IOException;
     method public static deprecated void changeDebugPort(int);
     method public static void dumpHprofData(java.lang.String) throws java.io.IOException;
     method public static boolean dumpService(java.lang.String, java.io.FileDescriptor, java.lang.String[]);
index 75fea52..1293295 100644 (file)
 
 package android.os;
 
+import android.annotation.NonNull;
+import android.annotation.Nullable;
 import android.app.AppGlobals;
 import android.content.Context;
 import android.util.Log;
 
 import com.android.internal.util.FastPrintWriter;
+import com.android.internal.util.Preconditions;
 import com.android.internal.util.TypedProperties;
 
 import dalvik.bytecode.OpcodeInfo;
@@ -2371,4 +2374,24 @@ public final class Debug
     public static String getCaller() {
         return getCaller(Thread.currentThread().getStackTrace(), 0);
     }
+
+    /**
+     * Attach a library as a jvmti agent to the current runtime.
+     *
+     * @param library library containing the agent
+     * @param options options passed to the agent
+     *
+     * @throws IOException If the agent could not be attached
+     */
+    public static void attachJvmtiAgent(@NonNull String library, @Nullable String options)
+            throws IOException {
+        Preconditions.checkNotNull(library);
+        Preconditions.checkArgument(!library.contains("="));
+
+        if (options == null) {
+            VMDebug.attachAgent(library);
+        } else {
+            VMDebug.attachAgent(library + "=" + options);
+        }
+    }
 }