summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Philip P. Moltmann <moltmann@google.com> 2017-11-01 15:22:02 -0700
committer Philip P. Moltmann <moltmann@google.com> 2017-11-03 10:33:21 -0700
commitfd8ed85adb84b2822eb2a15550b17976758e44dd (patch)
tree411fa238fcfe61cfb93f4da129124ce1853bd023
parent9009eabbfefdc685f176419001bc2aeff4790089 (diff)
Allow to attach jvmti agents from inside of process
Test: cts-tradefed run singleCommand cts-dev -m CtsJvmtiAttachingTestCases Bug: 65016018 Change-Id: I6d445afa288c6fec1d860150159fa05ed63cf517
-rw-r--r--api/current.txt1
-rw-r--r--api/system-current.txt1
-rw-r--r--api/test-current.txt1
-rw-r--r--core/java/android/os/Debug.java23
4 files changed, 26 insertions, 0 deletions
diff --git a/api/current.txt b/api/current.txt
index 518d972e8e1a..b520e589c177 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -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[]);
diff --git a/api/system-current.txt b/api/system-current.txt
index 03fdf3a58e1b..065d637dc2f5 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -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[]);
diff --git a/api/test-current.txt b/api/test-current.txt
index 57c65813be9b..016990cc5aa4 100644
--- a/api/test-current.txt
+++ b/api/test-current.txt
@@ -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[]);
diff --git a/core/java/android/os/Debug.java b/core/java/android/os/Debug.java
index 75fea5253674..12932956a7b9 100644
--- a/core/java/android/os/Debug.java
+++ b/core/java/android/os/Debug.java
@@ -16,11 +16,14 @@
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);
+ }
+ }
}