From 3ce54185b29e97fdd6d978a3f233eaa4f5122b0f Mon Sep 17 00:00:00 2001 From: Andreas Gampe Date: Thu, 18 Jan 2018 21:30:28 -0800 Subject: Dexmaker: Update attachJvmtiAgent API use Pass the classloader to attachJvmtiAgent. Remove agent extraction code. Bug: 65016018 Bug: 70901841 Test: mmma external/dexmaker Test: cts-tradefed run singleCommand cts-dev -m CtsInlineMockingTestCases Change-Id: I2be3ac3218c11f2ccf9a675fffd35f4fab548070 --- .../com/android/dx/mockito/inline/JvmtiAgent.java | 26 ++++------------------ 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/dexmaker-mockito-inline/src/main/java/com/android/dx/mockito/inline/JvmtiAgent.java b/dexmaker-mockito-inline/src/main/java/com/android/dx/mockito/inline/JvmtiAgent.java index 1b4a550..aca7a0c 100644 --- a/dexmaker-mockito-inline/src/main/java/com/android/dx/mockito/inline/JvmtiAgent.java +++ b/dexmaker-mockito-inline/src/main/java/com/android/dx/mockito/inline/JvmtiAgent.java @@ -34,7 +34,7 @@ import dalvik.system.BaseDexClassLoader; * Interface to the native jvmti agent in agent.cc */ class JvmtiAgent { - private static final String AGENT_LIB_NAME = "dexmakerjvmtiagent"; + private static final String AGENT_LIB_NAME = "libdexmakerjvmtiagent.so"; private static final Object lock = new Object(); @@ -65,32 +65,14 @@ class JvmtiAgent { + "by a BaseDexClassLoader"); } - // Currently Debug.attachJvmtiAgent requires a file in the right directory - File copiedAgent = File.createTempFile("agent", ".so"); - copiedAgent.deleteOnExit(); - - try (InputStream is = new FileInputStream( - ((BaseDexClassLoader) cl).findLibrary(AGENT_LIB_NAME))) { - try (OutputStream os = new FileOutputStream(copiedAgent)) { - byte[] buffer = new byte[64 * 1024]; - - while (true) { - int numRead = is.read(buffer); - if (numRead == -1) { - break; - } - os.write(buffer, 0, numRead); - } - } - } - try { /* * TODO (moltmann@google.com): Replace with regular method call once the API becomes * public */ Class.forName("android.os.Debug").getMethod("attachJvmtiAgent", String.class, - String.class).invoke(null, copiedAgent.getAbsolutePath(), null); + String.class, ClassLoader.class).invoke(null, AGENT_LIB_NAME, + null, cl); } catch (InvocationTargetException e) { loadJvmtiException = e.getCause(); } catch (IllegalAccessException | ClassNotFoundException | NoSuchMethodException e) { @@ -99,7 +81,7 @@ class JvmtiAgent { if (loadJvmtiException != null) { if (loadJvmtiException instanceof IOException) { - throw (IOException)loadJvmtiException; + throw new IOException(cl.toString(), loadJvmtiException); } else { throw new IOException("Could not load jvmti plugin", loadJvmtiException); -- cgit v1.2.3