com.sun.tools.attach.spi.AttachProvider Java Examples

The following examples show how to use com.sun.tools.attach.spi.AttachProvider. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VirtualMachine.java    From Carbon with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static VirtualMachine attach(String id) throws AttachNotSupportedException, IOException {
	if (id == null) {
		throw new NullPointerException("id cannot be null");
	}
	List<AttachProvider> providers = AttachProvider.providers();
	if (providers.size() == 0) {
		throw new AttachNotSupportedException("no providers installed");
	}
	AttachNotSupportedException lastExc = null;
	for (AttachProvider provider : providers) {
		try {
			return provider.attachVirtualMachine(id);
		} catch (AttachNotSupportedException x) {
			lastExc = x;
		}
	}
	throw lastExc;
}
 
Example #2
Source File: Instrumentator.java    From Carbon with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void instrumentate() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, IOException, AttachNotSupportedException, AgentLoadException, AgentInitializationException {
	Tools.addToLibPath(getLibraryPath(attachLibFolder));
	AttachProvider.setAttachProvider(getAttachProvider());
    AgentLoader.attachAgentToJVM(
    	Tools.getCurrentPID(), CarbonTransformAgent.class,
    	new String[] {
    		"org/bukkit/craftbukkit/v1_7_R4/inventory/BannerMeta.class",
    		"org/bukkit/craftbukkit/v1_7_R4/inventory/BannerMeta$BannerPattern.class",
    		"net/minecraft/server/v1_7_R4/EnumEntitySpawnZone.class",
    		"net/minecraft/server/v1_7_R4/EntitySpawnZone.class",
    	},
    	"org/bukkit/craftbukkit/v1_7_R4/inventory/CraftItemStack.class",
    	"org/bukkit/craftbukkit/v1_7_R4/inventory/CraftMetaItem.class",
    	"org/bukkit/craftbukkit/v1_7_R4/inventory/CraftMetaItem$SerializableMeta.class",
    	"org/bukkit/craftbukkit/v1_7_R4/inventory/CraftItemFactory.class",
    	"net/minecraft/server/v1_7_R4/EntityTracker.class",
    	"net/minecraft/server/v1_7_R4/EntityTrackerEntry.class",
    	"net/minecraft/server/v1_7_R4/DataWatcher.class",
    	"net/minecraft/server/v1_7_R4/SpawnerCreature.class",
    	"net/minecraft/server/v1_7_R4/SpawnerCreature$1.class",
    	"org/bukkit/Material.class"
    );
}
 
Example #3
Source File: HotSpotVirtualMachine.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
HotSpotVirtualMachine(AttachProvider provider, String id)
    throws AttachNotSupportedException, IOException
{
    super(provider, id);

    int pid;
    try {
        pid = Integer.parseInt(id);
    } catch (NumberFormatException e) {
        throw new AttachNotSupportedException("Invalid process identifier");
    }

    // The tool should be a different VM to the target. This check will
    // eventually be enforced by the target VM.
    if (!ALLOW_ATTACH_SELF && (pid == 0 || pid == CURRENT_PID)) {
        throw new IOException("Can not attach to current VM");
    }
}
 
Example #4
Source File: LocalVirtualMachineTemplateTest.java    From confucius-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecute() throws IOException, AttachNotSupportedException {
    LocalVirtualMachineTemplate localVirtualMachineTemplate = new LocalVirtualMachineTemplate();

    AttachProvider result = localVirtualMachineTemplate.execute(new HotSpotVirtualMachineCallback<AttachProvider>() {
        @Override
        public AttachProvider doInVirtualMachine(HotSpotVirtualMachine virtualMachine) throws IOException {
            AttachProvider attachProvider = virtualMachine.provider();
            return attachProvider;
        }
    });

    Assert.assertNotNull(result);
}
 
Example #5
Source File: VirtualMachineDescriptor.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a virtual machine descriptor from the given components.
 *
 * @param   provider      The AttachProvider to attach to the Java virtual machine.
 * @param   id            The virtual machine identifier.
 * @param   displayName   The display name.
 *
 * @throws  NullPointerException
 *          If any of the arguments are <code>null</code>
 */
public VirtualMachineDescriptor(AttachProvider provider, String id, String displayName) {
    if (provider == null) {
        throw new NullPointerException("provider cannot be null");
    }
    if (id == null) {
        throw new NullPointerException("identifier cannot be null");
    }
    if (displayName == null) {
        throw new NullPointerException("display name cannot be null");
    }
    this.provider = provider;
    this.id = id;
    this.displayName = displayName;
}
 
Example #6
Source File: ProviderTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {
    // deal with internal builds where classes are loaded from the
    // 'classes' directory rather than rt.jar
    ClassLoader cl = AttachProvider.class.getClassLoader();
    if (cl != ClassLoader.getSystemClassLoader()) {
        System.out.println("Attach API not loaded by system class loader - test skipped");
        return;
    }
    VirtualMachine.attach("simple:1234").detach();
}
 
Example #7
Source File: ProviderTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {
    // deal with internal builds where classes are loaded from the
    // 'classes' directory rather than rt.jar
    ClassLoader cl = AttachProvider.class.getClassLoader();
    if (cl != ClassLoader.getSystemClassLoader()) {
        System.out.println("Attach API not loaded by system class loader - test skipped");
        return;
    }
    VirtualMachine.attach("simple:1234").detach();
}
 
Example #8
Source File: VirtualMachineDescriptor.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a virtual machine descriptor from the given components.
 *
 * @param   provider      The AttachProvider to attach to the Java virtual machine.
 * @param   id            The virtual machine identifier.
 * @param   displayName   The display name.
 *
 * @throws  NullPointerException
 *          If any of the arguments are <code>null</code>
 */
public VirtualMachineDescriptor(AttachProvider provider, String id, String displayName) {
    if (provider == null) {
        throw new NullPointerException("provider cannot be null");
    }
    if (id == null) {
        throw new NullPointerException("identifier cannot be null");
    }
    if (displayName == null) {
        throw new NullPointerException("display name cannot be null");
    }
    this.provider = provider;
    this.id = id;
    this.displayName = displayName;
}
 
Example #9
Source File: VirtualMachineDescriptor.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a virtual machine descriptor from the given components.
 *
 * @param   provider      The AttachProvider to attach to the Java virtual machine.
 * @param   id            The virtual machine identifier.
 * @param   displayName   The display name.
 *
 * @throws  NullPointerException
 *          If any of the arguments are <code>null</code>
 */
public VirtualMachineDescriptor(AttachProvider provider, String id, String displayName) {
    if (provider == null) {
        throw new NullPointerException("provider cannot be null");
    }
    if (id == null) {
        throw new NullPointerException("identifier cannot be null");
    }
    if (displayName == null) {
        throw new NullPointerException("display name cannot be null");
    }
    this.provider = provider;
    this.id = id;
    this.displayName = displayName;
}
 
Example #10
Source File: ProviderTest.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {
    // deal with internal builds where classes are loaded from the
    // 'classes' directory rather than rt.jar
    ClassLoader cl = AttachProvider.class.getClassLoader();
    if (cl != ClassLoader.getSystemClassLoader()) {
        System.out.println("Attach API not loaded by system class loader - test skipped");
        return;
    }
    VirtualMachine.attach("simple:1234").detach();
}
 
Example #11
Source File: VirtualMachineDescriptor.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a virtual machine descriptor from the given components.
 *
 * @param   provider      The AttachProvider to attach to the Java virtual machine.
 * @param   id            The virtual machine identifier.
 * @param   displayName   The display name.
 *
 * @throws  NullPointerException
 *          If any of the arguments are <code>null</code>
 */
public VirtualMachineDescriptor(AttachProvider provider, String id, String displayName) {
    if (provider == null) {
        throw new NullPointerException("provider cannot be null");
    }
    if (id == null) {
        throw new NullPointerException("identifier cannot be null");
    }
    if (displayName == null) {
        throw new NullPointerException("display name cannot be null");
    }
    this.provider = provider;
    this.id = id;
    this.displayName = displayName;
}
 
Example #12
Source File: VirtualMachineDescriptor.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a virtual machine descriptor from the given components.
 *
 * @param   provider      The AttachProvider to attach to the Java virtual machine.
 * @param   id            The virtual machine identifier.
 * @param   displayName   The display name.
 *
 * @throws  NullPointerException
 *          If any of the arguments are {@code null}
 */
public VirtualMachineDescriptor(AttachProvider provider, String id, String displayName) {
    if (provider == null) {
        throw new NullPointerException("provider cannot be null");
    }
    if (id == null) {
        throw new NullPointerException("identifier cannot be null");
    }
    if (displayName == null) {
        throw new NullPointerException("display name cannot be null");
    }
    this.provider = provider;
    this.id = id;
    this.displayName = displayName;
}
 
Example #13
Source File: ProviderTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {
    // deal with internal builds where classes are loaded from the
    // 'classes' directory rather than rt.jar
    ClassLoader cl = AttachProvider.class.getClassLoader();
    if (cl != ClassLoader.getSystemClassLoader()) {
        System.out.println("Attach API not loaded by system class loader - test skipped");
        return;
    }
    VirtualMachine.attach("simple:1234").detach();
}
 
Example #14
Source File: ProviderTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {
    // deal with internal builds where classes are loaded from the
    // 'classes' directory rather than rt.jar
    ClassLoader cl = AttachProvider.class.getClassLoader();
    if (cl != ClassLoader.getSystemClassLoader()) {
        System.out.println("Attach API not loaded by system class loader - test skipped");
        return;
    }
    VirtualMachine.attach("simple:1234").detach();
}
 
Example #15
Source File: ProviderTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {
    // deal with internal builds where classes are loaded from the
    // 'classes' directory rather than rt.jar
    ClassLoader cl = AttachProvider.class.getClassLoader();
    if (cl != ClassLoader.getSystemClassLoader()) {
        System.out.println("Attach API not loaded by system class loader - test skipped");
        return;
    }
    VirtualMachine.attach("simple:1234").detach();
}
 
Example #16
Source File: ProviderTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {
    // deal with internal builds where classes are loaded from the
    // 'classes' directory rather than rt.jar
    ClassLoader cl = AttachProvider.class.getClassLoader();
    if (cl != ClassLoader.getSystemClassLoader()) {
        System.out.println("Attach API not loaded by system class loader - test skipped");
        return;
    }
    VirtualMachine.attach("simple:1234").detach();
}
 
Example #17
Source File: VirtualMachineDescriptor.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a virtual machine descriptor from the given components.
 *
 * @param   provider      The AttachProvider to attach to the Java virtual machine.
 * @param   id            The virtual machine identifier.
 * @param   displayName   The display name.
 *
 * @throws  NullPointerException
 *          If any of the arguments are <code>null</code>
 */
public VirtualMachineDescriptor(AttachProvider provider, String id, String displayName) {
    if (provider == null) {
        throw new NullPointerException("provider cannot be null");
    }
    if (id == null) {
        throw new NullPointerException("identifier cannot be null");
    }
    if (displayName == null) {
        throw new NullPointerException("display name cannot be null");
    }
    this.provider = provider;
    this.id = id;
    this.displayName = displayName;
}
 
Example #18
Source File: VirtualMachineDescriptor.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a virtual machine descriptor from the given components.
 *
 * @param   provider      The AttachProvider to attach to the Java virtual machine.
 * @param   id            The virtual machine identifier.
 * @param   displayName   The display name.
 *
 * @throws  NullPointerException
 *          If any of the arguments are <code>null</code>
 */
public VirtualMachineDescriptor(AttachProvider provider, String id, String displayName) {
    if (provider == null) {
        throw new NullPointerException("provider cannot be null");
    }
    if (id == null) {
        throw new NullPointerException("identifier cannot be null");
    }
    if (displayName == null) {
        throw new NullPointerException("display name cannot be null");
    }
    this.provider = provider;
    this.id = id;
    this.displayName = displayName;
}
 
Example #19
Source File: ProviderTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {
    // deal with internal builds where classes are loaded from the
    // 'classes' directory rather than rt.jar
    ClassLoader cl = AttachProvider.class.getClassLoader();
    if (cl != ClassLoader.getSystemClassLoader()) {
        System.out.println("Attach API not loaded by system class loader - test skipped");
        return;
    }
    VirtualMachine.attach("simple:1234").detach();
}
 
Example #20
Source File: VirtualMachineDescriptor.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a virtual machine descriptor from the given components.
 *
 * @param   provider      The AttachProvider to attach to the Java virtual machine.
 * @param   id            The virtual machine identifier.
 * @param   displayName   The display name.
 *
 * @throws  NullPointerException
 *          If any of the arguments are <code>null</code>
 */
public VirtualMachineDescriptor(AttachProvider provider, String id, String displayName) {
    if (provider == null) {
        throw new NullPointerException("provider cannot be null");
    }
    if (id == null) {
        throw new NullPointerException("identifier cannot be null");
    }
    if (displayName == null) {
        throw new NullPointerException("display name cannot be null");
    }
    this.provider = provider;
    this.id = id;
    this.displayName = displayName;
}
 
Example #21
Source File: VirtualMachineDescriptor.java    From Carbon with GNU Lesser General Public License v3.0 5 votes vote down vote up
public VirtualMachineDescriptor(AttachProvider provider, String id, String displayName) {
	if (provider == null) {
		throw new NullPointerException("provider cannot be null");
	}
	if (id == null) {
		throw new NullPointerException("identifier cannot be null");
	}
	if (displayName == null) {
		throw new NullPointerException("display name cannot be null");
	}
	this.provider = provider;
	this.id = id;
	this.displayName = displayName;
}
 
Example #22
Source File: VirtualMachineDescriptor.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a virtual machine descriptor from the given components.
 *
 * @param   provider      The AttachProvider to attach to the Java virtual machine.
 * @param   id            The virtual machine identifier.
 * @param   displayName   The display name.
 *
 * @throws  NullPointerException
 *          If any of the arguments are <code>null</code>
 */
public VirtualMachineDescriptor(AttachProvider provider, String id, String displayName) {
    if (provider == null) {
        throw new NullPointerException("provider cannot be null");
    }
    if (id == null) {
        throw new NullPointerException("identifier cannot be null");
    }
    if (displayName == null) {
        throw new NullPointerException("display name cannot be null");
    }
    this.provider = provider;
    this.id = id;
    this.displayName = displayName;
}
 
Example #23
Source File: VirtualMachineDescriptor.java    From Carbon with GNU Lesser General Public License v3.0 4 votes vote down vote up
public AttachProvider provider() {
	return provider;
}
 
Example #24
Source File: HotSpotVirtualMachine.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
HotSpotVirtualMachine(AttachProvider provider, String id) {
    super(provider, id);
}
 
Example #25
Source File: HotSpotVirtualMachine.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
HotSpotVirtualMachine(AttachProvider provider, String id) {
    super(provider, id);
}
 
Example #26
Source File: HotSpotAttachProvider.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
HotSpotVirtualMachineDescriptor(AttachProvider provider,
                                String id,
                                String displayName) {
    super(provider, id, displayName);
}
 
Example #27
Source File: SolarisVirtualMachine.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Attaches to the target VM
 */
SolarisVirtualMachine(AttachProvider provider, String vmid)
    throws AttachNotSupportedException, IOException
{
    super(provider, vmid);
    // This provider only understands process-ids (pids).
    int pid;
    try {
        pid = Integer.parseInt(vmid);
    } catch (NumberFormatException x) {
        throw new AttachNotSupportedException("invalid process identifier");
    }

    // Opens the door file to the target VM. If the file is not
    // found it might mean that the attach mechanism isn't started in the
    // target VM so we attempt to start it and retry.
    try {
        fd = openDoor(pid);
    } catch (FileNotFoundException fnf1) {
        File f = createAttachFile(pid);
        try {
            // kill -QUIT will tickle target VM to check for the
            // attach file.
            sigquit(pid);

            // give the target VM time to start the attach mechanism
            int i = 0;
            long delay = 200;
            int retries = (int)(attachTimeout() / delay);
            do {
                try {
                    Thread.sleep(delay);
                } catch (InterruptedException x) { }
                try {
                    fd = openDoor(pid);
                } catch (FileNotFoundException fnf2) { }
                i++;
            } while (i <= retries && fd == -1);
            if (fd == -1) {
                throw new AttachNotSupportedException(
                    "Unable to open door: target process not responding or " +
                    "HotSpot VM not loaded");
            }
        } finally {
            f.delete();
        }
    }
    assert fd >= 0;
}
 
Example #28
Source File: HotSpotAttachProvider.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
HotSpotVirtualMachineDescriptor(AttachProvider provider,
                                String id,
                                String displayName) {
    super(provider, id, displayName);
}
 
Example #29
Source File: SolarisVirtualMachine.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Attaches to the target VM
 */
SolarisVirtualMachine(AttachProvider provider, String vmid)
    throws AttachNotSupportedException, IOException
{
    super(provider, vmid);
    // This provider only understands process-ids (pids).
    int pid;
    try {
        pid = Integer.parseInt(vmid);
    } catch (NumberFormatException x) {
        throw new AttachNotSupportedException("invalid process identifier");
    }

    // Opens the door file to the target VM. If the file is not
    // found it might mean that the attach mechanism isn't started in the
    // target VM so we attempt to start it and retry.
    try {
        fd = openDoor(pid);
    } catch (FileNotFoundException fnf1) {
        File f = createAttachFile(pid);
        try {
            // kill -QUIT will tickle target VM to check for the
            // attach file.
            sigquit(pid);

            // give the target VM time to start the attach mechanism
            int i = 0;
            long delay = 200;
            int retries = (int)(attachTimeout() / delay);
            do {
                try {
                    Thread.sleep(delay);
                } catch (InterruptedException x) { }
                try {
                    fd = openDoor(pid);
                } catch (FileNotFoundException fnf2) { }
                i++;
            } while (i <= retries && fd == -1);
            if (fd == -1) {
                throw new AttachNotSupportedException(
                    "Unable to open door: target process not responding or " +
                    "HotSpot VM not loaded");
            }
        } finally {
            f.delete();
        }
    }
    assert fd >= 0;
}
 
Example #30
Source File: VirtualMachine.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Attaches to a Java virtual machine.
 *
 * <p> This method obtains the list of attach providers by invoking the
 * {@link com.sun.tools.attach.spi.AttachProvider#providers()
 * AttachProvider.providers()} method. It then iterates overs the list
 * and invokes each provider's {@link
 * com.sun.tools.attach.spi.AttachProvider#attachVirtualMachine(java.lang.String)
 * attachVirtualMachine} method in turn. If a provider successfully
 * attaches then the iteration terminates, and the VirtualMachine created
 * by the provider that successfully attached is returned by this method.
 * If the <code>attachVirtualMachine</code> method of all providers throws
 * {@link com.sun.tools.attach.AttachNotSupportedException AttachNotSupportedException}
 * then this method also throws <code>AttachNotSupportedException</code>.
 * This means that <code>AttachNotSupportedException</code> is thrown when
 * the identifier provided to this method is invalid, or the identifier
 * corresponds to a Java virtual machine that does not exist, or none
 * of the providers can attach to it. This exception is also thrown if
 * {@link com.sun.tools.attach.spi.AttachProvider#providers()
 * AttachProvider.providers()} returns an empty list. </p>
 *
 * @param   id
 *          The abstract identifier that identifies the Java virtual machine.
 *
 * @return  A VirtualMachine representing the target VM.
 *
 * @throws  SecurityException
 *          If a security manager has been installed and it denies
 *          {@link com.sun.tools.attach.AttachPermission AttachPermission}
 *          <tt>("attachVirtualMachine")</tt>, or another permission
 *          required by the implementation.
 *
 * @throws  AttachNotSupportedException
 *          If the <code>attachVirtualmachine</code> method of all installed
 *          providers throws <code>AttachNotSupportedException</code>, or
 *          there aren't any providers installed.
 *
 * @throws  IOException
 *          If an I/O error occurs
 *
 * @throws  NullPointerException
 *          If <code>id</code> is <code>null</code>.
 */
public static VirtualMachine attach(String id)
    throws AttachNotSupportedException, IOException
{
    if (id == null) {
        throw new NullPointerException("id cannot be null");
    }
    List<AttachProvider> providers = AttachProvider.providers();
    if (providers.size() == 0) {
        throw new AttachNotSupportedException("no providers installed");
    }
    AttachNotSupportedException lastExc = null;
    for (AttachProvider provider: providers) {
        try {
            return provider.attachVirtualMachine(id);
        } catch (AttachNotSupportedException x) {
            lastExc = x;
        }
    }
    throw lastExc;
}