Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Openj9 attach #684

Merged
merged 13 commits into from
Jul 11, 2019
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ matrix:
- env: TARGET='-Pjava11' EXPERIMENTAL='true' EXCLUDE='-pl ''!byte-buddy-gradle-plugin'''
jdk: openjdk-ea
# OpenJ9 - Java 11
- env: JDK="OpenJ9 11" TARGET='-Pjava11' EXPERIMENTAL='false' EXCLUDE =''
- env: JDK="OpenJ9 11" TARGET='-Pjava11' EXPERIMENTAL='false' EXCLUDE=''
before_script:
- . ci/install-jdk.sh -W ~/custom-java --url "https://api.adoptopenjdk.net/v2/binary/releases/openjdk11?openjdk_impl=openj9&os=linux&arch=x64&release=latest&type=jdk&heap_size=normal"

Expand Down
9 changes: 7 additions & 2 deletions byte-buddy-agent/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand Down Expand Up @@ -140,7 +141,11 @@
<packages>${packages.list}</packages>
<exports>${packages.list}</exports>
<requires>java.instrument</requires>
<static-requires>jdk.attach</static-requires>
<static-requires>
jdk.attach,
com.sun.jna,
com.sun.jna.platform
</static-requires>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,14 @@ public static Instrumentation getInstrumentation() {
}

/**
* <p>
* Attaches the given agent Jar on the target process which must be a virtual machine process. The default attachment provider
* is used for applying the attachment. This operation blocks until the attachment is complete. If the current VM does not supply
* any known form of attachment to a remote VM, an {@link IllegalStateException} is thrown. The agent is not provided an argument.
* </p>
* <p>
* <b>Important</b>: It is only possible to attach to processes that are executed by the same operating system user.
* </p>
*
* @param agentJar The agent jar file.
* @param processId The target process id.
Expand All @@ -211,9 +216,14 @@ public static void attach(File agentJar, String processId) {
}

/**
* <p>
* Attaches the given agent Jar on the target process which must be a virtual machine process. The default attachment provider
* is used for applying the attachment. This operation blocks until the attachment is complete. If the current VM does not supply
* any known form of attachment to a remote VM, an {@link IllegalStateException} is thrown.
* </p>
* <p>
* <b>Important</b>: It is only possible to attach to processes that are executed by the same operating system user.
* </p>
*
* @param agentJar The agent jar file.
* @param processId The target process id.
Expand All @@ -224,8 +234,13 @@ public static void attach(File agentJar, String processId, String argument) {
}

/**
* <p>
* Attaches the given agent Jar on the target process which must be a virtual machine process. This operation blocks until the
* attachment is complete. The agent is not provided an argument.
* </p>
* <p>
* <b>Important</b>: It is only possible to attach to processes that are executed by the same operating system user.
* </p>
*
* @param agentJar The agent jar file.
* @param processId The target process id.
Expand All @@ -236,8 +251,13 @@ public static void attach(File agentJar, String processId, AttachmentProvider at
}

/**
* <p>
* Attaches the given agent Jar on the target process which must be a virtual machine process. This operation blocks until the
* attachment is complete.
* </p>
* <p>
* <b>Important</b>: It is only possible to attach to processes that are executed by the same operating system user.
* </p>
*
* @param agentJar The agent jar file.
* @param processId The target process id.
Expand All @@ -249,9 +269,14 @@ public static void attach(File agentJar, String processId, String argument, Atta
}

/**
* <p>
* Attaches the given agent Jar on the target process which must be a virtual machine process. The default attachment provider
* is used for applying the attachment. This operation blocks until the attachment is complete. If the current VM does not supply
* any known form of attachment to a remote VM, an {@link IllegalStateException} is thrown. The agent is not provided an argument.
* </p>
* <p>
* <b>Important</b>: It is only possible to attach to processes that are executed by the same operating system user.
* </p>
*
* @param agentJar The agent jar file.
* @param processProvider A provider of the target process id.
Expand All @@ -261,9 +286,14 @@ public static void attach(File agentJar, ProcessProvider processProvider) {
}

/**
* <p>
* Attaches the given agent Jar on the target process which must be a virtual machine process. The default attachment provider
* is used for applying the attachment. This operation blocks until the attachment is complete. If the current VM does not supply
* any known form of attachment to a remote VM, an {@link IllegalStateException} is thrown.
* </p>
* <p>
* <b>Important</b>: It is only possible to attach to processes that are executed by the same operating system user.
* </p>
*
* @param agentJar The agent jar file.
* @param processProvider A provider of the target process id.
Expand All @@ -274,8 +304,13 @@ public static void attach(File agentJar, ProcessProvider processProvider, String
}

/**
* <p>
* Attaches the given agent Jar on the target process which must be a virtual machine process. This operation blocks until the
* attachment is complete. The agent is not provided an argument.
* </p>
* <p>
* <b>Important</b>: It is only possible to attach to processes that are executed by the same operating system user.
* </p>
*
* @param agentJar The agent jar file.
* @param processProvider A provider of the target process id.
Expand All @@ -286,8 +321,13 @@ public static void attach(File agentJar, ProcessProvider processProvider, Attach
}

/**
* <p>
* Attaches the given agent Jar on the target process which must be a virtual machine process. This operation blocks until the
* attachment is complete.
* </p>
* <p>
* <b>Important</b>: It is only possible to attach to processes that are executed by the same operating system user.
* </p>
*
* @param agentJar The agent jar file.
* @param processProvider A provider of the target process id.
Expand All @@ -299,9 +339,14 @@ public static void attach(File agentJar, ProcessProvider processProvider, String
}

/**
* <p>
* Attaches the given agent library on the target process which must be a virtual machine process. The default attachment provider
* is used for applying the attachment. This operation blocks until the attachment is complete. If the current VM does not supply
* any known form of attachment to a remote VM, an {@link IllegalStateException} is thrown. The agent is not provided an argument.
* </p>
* <p>
* <b>Important</b>: It is only possible to attach to processes that are executed by the same operating system user.
* </p>
*
* @param agentLibrary The agent jar file.
* @param processId The target process id.
Expand All @@ -311,9 +356,14 @@ public static void attachNative(File agentLibrary, String processId) {
}

/**
* <p>
* Attaches the given agent library on the target process which must be a virtual machine process. The default attachment provider
* is used for applying the attachment. This operation blocks until the attachment is complete. If the current VM does not supply
* any known form of attachment to a remote VM, an {@link IllegalStateException} is thrown.
* </p>
* <p>
* <b>Important</b>: It is only possible to attach to processes that are executed by the same operating system user.
* </p>
*
* @param agentLibrary The agent library.
* @param processId The target process id.
Expand All @@ -324,8 +374,13 @@ public static void attachNative(File agentLibrary, String processId, String argu
}

/**
* <p>
* Attaches the given agent library on the target process which must be a virtual machine process. This operation blocks until the
* attachment is complete. The agent is not provided an argument.
* </p>
* <p>
* <b>Important</b>: It is only possible to attach to processes that are executed by the same operating system user.
* </p>
*
* @param agentLibrary The agent library.
* @param processId The target process id.
Expand All @@ -336,8 +391,13 @@ public static void attachNative(File agentLibrary, String processId, AttachmentP
}

/**
* <p>
* Attaches the given agent library on the target process which must be a virtual machine process. This operation blocks until the
* attachment is complete.
* </p>
* <p>
* <b>Important</b>: It is only possible to attach to processes that are executed by the same operating system user.
* </p>
*
* @param agentLibrary The agent library.
* @param processId The target process id.
Expand All @@ -349,9 +409,14 @@ public static void attachNative(File agentLibrary, String processId, String argu
}

/**
* <p>
* Attaches the given agent library on the target process which must be a virtual machine process. The default attachment provider
* is used for applying the attachment. This operation blocks until the attachment is complete. If the current VM does not supply
* any known form of attachment to a remote VM, an {@link IllegalStateException} is thrown. The agent is not provided an argument.
* </p>
* <p>
* <b>Important</b>: It is only possible to attach to processes that are executed by the same operating system user.
* </p>
*
* @param agentLibrary The agent library.
* @param processProvider A provider of the target process id.
Expand All @@ -361,9 +426,14 @@ public static void attachNative(File agentLibrary, ProcessProvider processProvid
}

/**
* <p>
* Attaches the given agent library on the target process which must be a virtual machine process. The default attachment provider
* is used for applying the attachment. This operation blocks until the attachment is complete. If the current VM does not supply
* any known form of attachment to a remote VM, an {@link IllegalStateException} is thrown.
* </p>
* <p>
* <b>Important</b>: It is only possible to attach to processes that are executed by the same operating system user.
* </p>
*
* @param agentLibrary The agent library.
* @param processProvider A provider of the target process id.
Expand All @@ -374,8 +444,13 @@ public static void attachNative(File agentLibrary, ProcessProvider processProvid
}

/**
* <p>
* Attaches the given agent library on the target process which must be a virtual machine process. This operation blocks until the
* attachment is complete. The agent is not provided an argument.
* </p>
* <p>
* <b>Important</b>: It is only possible to attach to processes that are executed by the same operating system user.
* </p>
*
* @param agentLibrary The agent library.
* @param processProvider A provider of the target process id.
Expand All @@ -386,8 +461,13 @@ public static void attachNative(File agentLibrary, ProcessProvider processProvid
}

/**
* <p>
* Attaches the given agent library on the target process which must be a virtual machine process. This operation blocks until the
* attachment is complete.
* </p>
* <p>
* <b>Important</b>: It is only possible to attach to processes that are executed by the same operating system user.
* </p>
*
* @param agentLibrary The agent library.
* @param processProvider A provider of the target process id.
Expand Down Expand Up @@ -921,16 +1001,16 @@ public ExternalAttachment getExternalAttachment() {
}

/**
* A simple implementation of an accessible accessor that does not allow for external attachment.
* A simple implementation of an accessible accessor that attaches using a virtual machine emulation that does not require external attachment.
*/
protected static class WithoutExternalAttachment extends Simple {
protected static class WithDirectAttachment extends Simple {

/**
* Creates a new simple accessor that does not allow for external attachment.
* Creates a new simple accessor that implements direct attachment.
*
* @param virtualMachineType A {@code VirtualMachine} class.
*/
public WithoutExternalAttachment(Class<?> virtualMachineType) {
public WithDirectAttachment(Class<?> virtualMachineType) {
super(virtualMachineType);
}

Expand Down Expand Up @@ -1097,7 +1177,7 @@ enum ForUnixHotSpotVm implements AttachmentProvider {
*/
public Accessor attempt() {
try {
return new Accessor.Simple.WithoutExternalAttachment(VirtualMachine.ForHotSpotVm.assertAvailability());
return new Accessor.Simple.WithDirectAttachment(AccessController.doPrivileged(VirtualMachine.Resolver.INSTANCE));
} catch (Throwable ignored) {
return Accessor.Unavailable.INSTANCE;
}
Expand Down
Loading