|
|
|
@ -1,17 +1,17 @@
|
|
|
|
|
From 4dcae48a47d1c2123d5ec86f3e2d6ef1adab8a83 Mon Sep 17 00:00:00 2001
|
|
|
|
|
From 9f9ca4a15ef217284557d1fa88dfed8551a365ae Mon Sep 17 00:00:00 2001
|
|
|
|
|
From: Marian Koncek <mkoncek@redhat.com>
|
|
|
|
|
Date: Wed, 30 Sep 2020 13:04:45 +0200
|
|
|
|
|
Date: Thu, 12 Sep 2019 11:18:51 +0200
|
|
|
|
|
Subject: [PATCH] Remove dependency on jna
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
.../net/bytebuddy/agent/VirtualMachine.java | 2275 +++--------------
|
|
|
|
|
1 file changed, 357 insertions(+), 1918 deletions(-)
|
|
|
|
|
.../net/bytebuddy/agent/VirtualMachine.java | 2234 +++--------------
|
|
|
|
|
1 file changed, 357 insertions(+), 1877 deletions(-)
|
|
|
|
|
|
|
|
|
|
diff --git a/byte-buddy-agent/src/main/java/net/bytebuddy/agent/VirtualMachine.java b/byte-buddy-agent/src/main/java/net/bytebuddy/agent/VirtualMachine.java
|
|
|
|
|
index 245581d..80cab63 100644
|
|
|
|
|
index 6e16424..e2138c1 100644
|
|
|
|
|
--- a/byte-buddy-agent/src/main/java/net/bytebuddy/agent/VirtualMachine.java
|
|
|
|
|
+++ b/byte-buddy-agent/src/main/java/net/bytebuddy/agent/VirtualMachine.java
|
|
|
|
|
@@ -15,13 +15,6 @@
|
|
|
|
|
@@ -15,11 +15,6 @@
|
|
|
|
|
*/
|
|
|
|
|
package net.bytebuddy.agent;
|
|
|
|
|
|
|
|
|
@ -20,12 +20,22 @@ index 245581d..80cab63 100644
|
|
|
|
|
-import com.sun.jna.ptr.IntByReference;
|
|
|
|
|
-import com.sun.jna.win32.StdCallLibrary;
|
|
|
|
|
-import com.sun.jna.win32.W32APIOptions;
|
|
|
|
|
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
|
|
|
|
-
|
|
|
|
|
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
|
|
|
|
|
|
|
|
|
import java.io.*;
|
|
|
|
|
import java.net.ServerSocket;
|
|
|
|
|
import java.net.Socket;
|
|
|
|
|
@@ -227,23 +220,6 @@ public interface VirtualMachine {
|
|
|
|
|
@@ -149,11 +144,6 @@ public interface VirtualMachine {
|
|
|
|
|
* {@inheritDoc}
|
|
|
|
|
*/
|
|
|
|
|
public Class<? extends VirtualMachine> run() {
|
|
|
|
|
- try {
|
|
|
|
|
- Class.forName("com.sun.jna.Platform");
|
|
|
|
|
- } catch (ClassNotFoundException exception) {
|
|
|
|
|
- throw new IllegalStateException("Optional JNA dependency is not available", exception);
|
|
|
|
|
- }
|
|
|
|
|
return System.getProperty("java.vm.vendor").toUpperCase(Locale.US).contains("J9")
|
|
|
|
|
? ForOpenJ9.class
|
|
|
|
|
: ForHotSpot.class;
|
|
|
|
|
@@ -227,23 +217,6 @@ public interface VirtualMachine {
|
|
|
|
|
this.connection = connection;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -49,15 +59,7 @@ index 245581d..80cab63 100644
|
|
|
|
|
/**
|
|
|
|
|
* Attaches to the supplied process id using the supplied connection factory.
|
|
|
|
|
*
|
|
|
|
|
@@ -515,7 +491,6 @@ public interface VirtualMachine {
|
|
|
|
|
/**
|
|
|
|
|
* {@inheritDoc}
|
|
|
|
|
*/
|
|
|
|
|
- @SuppressFBWarnings(value = "DMI_HARDCODED_ABSOLUTE_FILENAME", justification = "File name convention is specified.")
|
|
|
|
|
public Connection connect(String processId) throws IOException {
|
|
|
|
|
File socket = new File(temporaryDirectory, SOCKET_FILE_PREFIX + processId);
|
|
|
|
|
if (!socket.exists()) {
|
|
|
|
|
@@ -679,1949 +654,413 @@ public interface VirtualMachine {
|
|
|
|
|
@@ -679,1905 +652,412 @@ public interface VirtualMachine {
|
|
|
|
|
*/
|
|
|
|
|
protected abstract int read(T connection, byte[] buffer) throws IOException;
|
|
|
|
|
}
|
|
|
|
@ -138,7 +140,7 @@ index 245581d..80cab63 100644
|
|
|
|
|
- library.connect(handle, address, address.size());
|
|
|
|
|
- return handle;
|
|
|
|
|
- } finally {
|
|
|
|
|
- address = null;
|
|
|
|
|
- address.clear();
|
|
|
|
|
- }
|
|
|
|
|
- } catch (RuntimeException exception) {
|
|
|
|
|
- library.close(handle);
|
|
|
|
@ -311,18 +313,12 @@ index 245581d..80cab63 100644
|
|
|
|
|
- * @param timeUnit The time unit of the pause time.
|
|
|
|
|
- * @return An appropriate connection factory.
|
|
|
|
|
- */
|
|
|
|
|
- @SuppressWarnings("deprecation")
|
|
|
|
|
- public static Connection.Factory withDefaultTemporaryFolder(int attempts, long pause, TimeUnit timeUnit) {
|
|
|
|
|
- String temporaryDirectory;
|
|
|
|
|
- if (Platform.isMac()) {
|
|
|
|
|
- MacLibrary library = Native.loadLibrary("c", MacLibrary.class);
|
|
|
|
|
- Memory memory = new Memory(4096);
|
|
|
|
|
- try {
|
|
|
|
|
- long length = library.confstr(MacLibrary.CS_DARWIN_USER_TEMP_DIR, memory, memory.size());
|
|
|
|
|
- if (length == 0 || length > 4096) {
|
|
|
|
|
- temporaryDirectory = "/tmp";
|
|
|
|
|
- } else {
|
|
|
|
|
- temporaryDirectory = memory.getString(0);
|
|
|
|
|
- temporaryDirectory = System.getenv("TMPDIR");
|
|
|
|
|
- if (temporaryDirectory == null) {
|
|
|
|
|
- temporaryDirectory = "/tmp";
|
|
|
|
|
+ long userId = dispatcher.userId();
|
|
|
|
|
+ virtualMachines = new ArrayList<Properties>();
|
|
|
|
|
+ for (File aVmFolder : vmFolder) {
|
|
|
|
@ -362,9 +358,7 @@ index 245581d..80cab63 100644
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
}
|
|
|
|
|
- } finally {
|
|
|
|
|
- memory = null;
|
|
|
|
|
+ }
|
|
|
|
|
}
|
|
|
|
|
- } else {
|
|
|
|
|
- temporaryDirectory = "/tmp";
|
|
|
|
@ -382,27 +376,6 @@ index 245581d..80cab63 100644
|
|
|
|
|
- @Override
|
|
|
|
|
- public Connection doConnect(File socket) {
|
|
|
|
|
- return new Connection.ForJnaPosixSocket(library, socket);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * A library for reading a Mac user's temporary directory.
|
|
|
|
|
- */
|
|
|
|
|
- public interface MacLibrary extends Library {
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * The temporary directory.
|
|
|
|
|
- */
|
|
|
|
|
- int CS_DARWIN_USER_TEMP_DIR = 65537;
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Reads a configuration dependant variable into a memory segment.
|
|
|
|
|
- *
|
|
|
|
|
- * @param name The name of the variable.
|
|
|
|
|
- * @param buffer The buffer to read the variable into.
|
|
|
|
|
- * @param length The length of the buffer.
|
|
|
|
|
- * @return The amount of bytes written to the buffer.
|
|
|
|
|
- */
|
|
|
|
|
- long confstr(int name, Pointer buffer, long length);
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ master.close();
|
|
|
|
|
}
|
|
|
|
@ -729,12 +702,6 @@ index 245581d..80cab63 100644
|
|
|
|
|
- public static class Factory implements Connection.Factory {
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * The name of the native code library that is included in this artifact to support Windows attachment.
|
|
|
|
|
- * This property can be set by other libraries that shade Byte Buddy agent and relocates the library.
|
|
|
|
|
- */
|
|
|
|
|
- public static final String LIBRARY_NAME = "net.bytebuddy.library.name";
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * The library to use for communicating with Windows native functions.
|
|
|
|
|
- */
|
|
|
|
|
- private final WindowsLibrary library;
|
|
|
|
@ -750,7 +717,7 @@ index 245581d..80cab63 100644
|
|
|
|
|
- @SuppressWarnings("deprecation")
|
|
|
|
|
- public Factory() {
|
|
|
|
|
- library = Native.loadLibrary("kernel32", WindowsLibrary.class, W32APIOptions.DEFAULT_OPTIONS);
|
|
|
|
|
- attachLibrary = Native.loadLibrary(System.getProperty(LIBRARY_NAME, "attach_hotspot_windows"), WindowsAttachLibrary.class);
|
|
|
|
|
- attachLibrary = Native.loadLibrary("attach_hotspot_windows", WindowsAttachLibrary.class);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
@ -843,13 +810,13 @@ index 245581d..80cab63 100644
|
|
|
|
|
- return new Response(library, door.descriptorPointer.getInt(4));
|
|
|
|
|
- }
|
|
|
|
|
- } finally {
|
|
|
|
|
- result = null;
|
|
|
|
|
- result.clear();
|
|
|
|
|
- }
|
|
|
|
|
- } finally {
|
|
|
|
|
- dataPointer = null;
|
|
|
|
|
- dataPointer.clear();
|
|
|
|
|
- }
|
|
|
|
|
- } finally {
|
|
|
|
|
- door = null;
|
|
|
|
|
- door.clear();
|
|
|
|
|
- }
|
|
|
|
|
- } finally {
|
|
|
|
|
- library.close(handle);
|
|
|
|
@ -1218,7 +1185,6 @@ index 245581d..80cab63 100644
|
|
|
|
|
- if (answer.contains(' ' + key + ' ')) {
|
|
|
|
|
- return new ForOpenJ9(socket);
|
|
|
|
|
- } else {
|
|
|
|
|
- socket.close();
|
|
|
|
|
- throw new IllegalStateException("Unexpected answered to attachment: " + answer);
|
|
|
|
|
- }
|
|
|
|
|
- } finally {
|
|
|
|
@ -1539,8 +1505,7 @@ index 245581d..80cab63 100644
|
|
|
|
|
- try {
|
|
|
|
|
- // The binding for 'stat' is very platform dependant. To avoid the complexity of binding the correct method,
|
|
|
|
|
- // stat is called as a separate command. This is less efficient but more portable.
|
|
|
|
|
- String statUserSwitch = Platform.isMac() ? "-f" : "-c";
|
|
|
|
|
- Process process = Runtime.getRuntime().exec("stat " + statUserSwitch + " %u " + file.getAbsolutePath());
|
|
|
|
|
- Process process = Runtime.getRuntime().exec("stat -c=%u " + file.getAbsolutePath());
|
|
|
|
|
- int attempts = this.attempts;
|
|
|
|
|
- boolean exited = false;
|
|
|
|
|
- String line = new BufferedReader(new InputStreamReader(process.getInputStream(), "UTF-8")).readLine();
|
|
|
|
@ -1557,7 +1522,7 @@ index 245581d..80cab63 100644
|
|
|
|
|
- Thread.sleep(timeUnit.toMillis(pause));
|
|
|
|
|
- } catch (InterruptedException exception) {
|
|
|
|
|
- Thread.currentThread().interrupt();
|
|
|
|
|
- throw new IllegalStateException(exception);
|
|
|
|
|
- throw new IllegalStateException("Interrupted while waiting for stat", exception);
|
|
|
|
|
+ String pid = Long.toString(dispatcher.pid());
|
|
|
|
|
+ for (Properties virtualMachine : virtualMachines) {
|
|
|
|
|
+ if (!virtualMachine.getProperty("processId").equalsIgnoreCase(pid)) {
|
|
|
|
@ -1578,7 +1543,7 @@ index 245581d..80cab63 100644
|
|
|
|
|
- process.destroy();
|
|
|
|
|
- throw new IllegalStateException("Command for stat did not exit in time");
|
|
|
|
|
- }
|
|
|
|
|
- return Integer.parseInt(line);
|
|
|
|
|
- return Integer.parseInt(line.substring(1));
|
|
|
|
|
- } catch (IOException exception) {
|
|
|
|
|
- throw new IllegalStateException("Unable to execute stat command", exception);
|
|
|
|
|
- }
|
|
|
|
@ -1626,8 +1591,7 @@ index 245581d..80cab63 100644
|
|
|
|
|
- try {
|
|
|
|
|
- library.semop(semaphore, target, 1);
|
|
|
|
|
- } catch (LastErrorException exception) {
|
|
|
|
|
- if (acceptUnavailable && (Native.getLastError() == PosixLibrary.EAGAIN
|
|
|
|
|
- || Native.getLastError() == PosixLibrary.EDEADLK)) {
|
|
|
|
|
- if (acceptUnavailable && Native.getLastError() == PosixLibrary.EAGAIN) {
|
|
|
|
|
- break;
|
|
|
|
|
- } else {
|
|
|
|
|
- throw exception;
|
|
|
|
@ -1647,7 +1611,7 @@ index 245581d..80cab63 100644
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- } finally {
|
|
|
|
|
- target = null;
|
|
|
|
|
- target.clear();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
@ -1672,11 +1636,6 @@ index 245581d..80cab63 100644
|
|
|
|
|
- int EAGAIN = 11;
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Indicates a dead lock on a resource.
|
|
|
|
|
- */
|
|
|
|
|
- int EDEADLK = 35;
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Indicates that a semaphore's operations should be undone at process shutdown.
|
|
|
|
|
- */
|
|
|
|
|
- short SEM_UNDO = 0x1000;
|
|
|
|
@ -1941,7 +1900,6 @@ index 245581d..80cab63 100644
|
|
|
|
|
+ if (answer.contains(' ' + key + ' ')) {
|
|
|
|
|
+ return new ForOpenJ9(socket);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ socket.close();
|
|
|
|
|
+ throw new IllegalStateException("Unexpected answered to attachment: " + answer);
|
|
|
|
|
}
|
|
|
|
|
- } else {
|
|
|
|
@ -1994,13 +1952,13 @@ index 245581d..80cab63 100644
|
|
|
|
|
+ }
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
- securityAttributes = null;
|
|
|
|
|
- securityAttributes.clear();
|
|
|
|
|
+ if (!reply.delete()) {
|
|
|
|
|
+ reply.deleteOnExit();
|
|
|
|
|
+ }
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
- securityDescriptor = null;
|
|
|
|
|
- securityDescriptor.clear();
|
|
|
|
|
+ serverSocket.close();
|
|
|
|
|
}
|
|
|
|
|
+ } finally {
|
|
|
|
@ -2365,5 +2323,5 @@ index 245581d..80cab63 100644
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
--
|
|
|
|
|
2.26.2
|
|
|
|
|
2.21.0
|
|
|
|
|
|