Search in sources :

Example 11 with VirtualMachineDescriptor

use of com.sun.tools.attach.VirtualMachineDescriptor in project openj9 by eclipse.

the class ListVms method listVms.

private static void listVms() {
    List<AttachProvider> providers = AttachProvider.providers();
    AttachProvider ap = providers.get(0);
    if (null == ap) {
        System.err.println("no attach providers available");
    }
    @SuppressWarnings("null") List<VirtualMachineDescriptor> vmds = ap.listVirtualMachines();
    System.out.println("looking for attach targets");
    for (VirtualMachineDescriptor vmd : vmds) {
        System.out.println("id: " + vmd.id() + " name: " + vmd.displayName());
    }
    System.out.println(LIST_VMS_EXIT);
    System.out.flush();
    System.out.close();
    System.err.close();
}
Also used : VirtualMachineDescriptor(com.sun.tools.attach.VirtualMachineDescriptor) AttachProvider(com.sun.tools.attach.spi.AttachProvider)

Example 12 with VirtualMachineDescriptor

use of com.sun.tools.attach.VirtualMachineDescriptor in project openj9 by eclipse.

the class TestAttachAPI method test_vmname03.

/**
 * @testcase vmname03
 * @procedure start a process without displayName specified
 * @expect the id is an integer (PID), the displayName is the command
 * @variations
 */
@Test
public void test_vmname03() {
    logger.debug("starting " + testName);
    TargetManager target = launchTarget();
    try {
        List<AttachProvider> providers = com.sun.tools.attach.spi.AttachProvider.providers();
        AttachProvider myProvider = providers.get(0);
        List<VirtualMachineDescriptor> vmdList = myProvider.listVirtualMachines();
        if (vmdList.size() < 1) {
            fail("test_vmname03 ERROR: no target VMs found");
        }
        boolean found = false;
        Iterator<VirtualMachineDescriptor> vmi = vmdList.iterator();
        VirtualMachineDescriptor vm = null;
        while (!found && vmi.hasNext()) {
            vm = vmi.next();
            if (TestConstants.TARGET_VM_CLASS.equals(vm.displayName())) {
                found = true;
            }
        }
        if (null == vm) {
            fail("vm is null");
            return;
        }
        if (found) {
            try {
                Integer.parseInt(vm.id());
            } catch (NumberFormatException e) {
                fail("vm ID = " + vm.id());
            }
        } else {
            fail("displayName " + TestConstants.TARGET_VM_CLASS + " not found");
        }
    } finally {
        target.terminateTarget();
    }
}
Also used : VirtualMachineDescriptor(com.sun.tools.attach.VirtualMachineDescriptor) AttachProvider(com.sun.tools.attach.spi.AttachProvider) Test(org.testng.annotations.Test)

Example 13 with VirtualMachineDescriptor

use of com.sun.tools.attach.VirtualMachineDescriptor in project openj9 by eclipse.

the class TestAttachAPI method vmIdExists.

private boolean vmIdExists(String id, String id2, String displayName) {
    List<AttachProvider> providers = AttachProvider.providers();
    AttachProvider ap = providers.get(0);
    AssertJUnit.assertNotNull("no default attach provider", ap);
    List<VirtualMachineDescriptor> vmds = ap.listVirtualMachines();
    Iterator<VirtualMachineDescriptor> vmi = vmds.iterator();
    while (vmi.hasNext()) {
        VirtualMachineDescriptor vm = vmi.next();
        if ((id.equals(vm.id()) || id2.equals(vm.id())) && ((null == displayName) || displayName.equals(vm.displayName()))) {
            return true;
        }
    }
    return false;
}
Also used : VirtualMachineDescriptor(com.sun.tools.attach.VirtualMachineDescriptor) AttachProvider(com.sun.tools.attach.spi.AttachProvider)

Example 14 with VirtualMachineDescriptor

use of com.sun.tools.attach.VirtualMachineDescriptor in project openj9 by eclipse.

the class TestAttachAPI method checkHashes.

private boolean checkHashes(boolean detach, TargetManager[] tgts) {
    final int iterations = 4;
    List<VirtualMachineDescriptor> vmdList;
    int[] vmHashes, vmdHashes;
    VirtualMachine[] vms;
    boolean failed = false;
    List<AttachProvider> providers = com.sun.tools.attach.spi.AttachProvider.providers();
    AttachProvider myProvider = providers.get(0);
    vmdList = myProvider.listVirtualMachines();
    if (vmdList.size() < tgts.length) {
        fail("checkHashes ERROR: no target VMs found");
    }
    vmHashes = new int[vmdList.size()];
    vmdHashes = new int[vmdList.size()];
    vms = new VirtualMachine[vmdList.size()];
    HashMap<String, Integer> id2hash = new HashMap<String, Integer>(vmdList.size());
    Iterator<VirtualMachineDescriptor> vmdI = vmdList.iterator();
    while (vmdI.hasNext()) {
        VirtualMachineDescriptor vmd = vmdI.next();
        id2hash.put(vmd.id(), vmd.hashCode());
    }
    ArrayList<VirtualMachine> attachments = new ArrayList<VirtualMachine>();
    for (int iter = 0; iter < iterations; ++iter) {
        int vmNum = 0;
        for (TargetManager tm : tgts) {
            String vmId = tm.getTargetPid();
            logger.debug("checkHashes attaching to " + vmId);
            try {
                VirtualMachine vm = VirtualMachine.attach(vmId);
                int vhc = vm.hashCode();
                int dhc = id2hash.get(vmId);
                if (0 == iter) {
                    vms[vmNum] = vm;
                    vmHashes[vmNum] = vhc;
                    vmdHashes[vmNum] = dhc;
                    logger.debug("hashcodes for " + vmId + ": vm = " + vhc + " descriptor = " + dhc);
                } else {
                    if (!vm.equals(vms[vmNum])) {
                        logger.error("checkHashes ERROR: equals failed " + vmId);
                        failed = true;
                    }
                    if (dhc != vmdHashes[vmNum]) {
                        logger.error("checkHashes ERROR: " + vmId + " old descriptor hash " + vmdHashes[vmNum] + " new hash " + dhc);
                        failed = true;
                    }
                    if (vhc != vmHashes[vmNum]) {
                        logger.error("checkHashes ERROR: " + vmId + " old vm hash " + vmHashes[vmNum] + " new hash " + vhc);
                        failed = true;
                    }
                }
                if (detach) {
                    vm.detach();
                } else {
                    attachments.add(vm);
                }
            } catch (AttachNotSupportedException | IOException e) {
                logger.error(e.getMessage() + "\nfailure at " + vmId);
                listIpcDir();
                logExceptionInfoAndFail(e);
            }
            ++vmNum;
        }
    }
    for (VirtualMachine vm : attachments) {
        try {
            logger.debug("teardown detach " + vm.hashCode());
            vm.detach();
        } catch (IOException e) {
            logStackTrace(e);
            logger.error("IOException when detaching (permissible)");
        }
    }
    logger.debug("checkHashes verify that hashes are unique");
    for (int i = 0; i < vmHashes.length; ++i) {
        if (vms[i] == null) {
            continue;
        }
        for (int j = i + 1; j < i; ++j) {
            if (vms[i].equals(vms[j])) {
                logger.error("checkHashes ERROR: vm " + vmdList.get(i).id() + " equals " + vmdList.get(j).id());
                failed = true;
            }
            if (vmHashes[i] == vmHashes[j]) {
                logger.error("checkHashes ERROR: vm hashcode " + vmHashes[i] + " for " + vmdList.get(i).id() + " same as " + vmdList.get(j).id());
                failed = true;
            }
            if (vmdHashes[i] == vmdHashes[j]) {
                logger.error("checkHashes ERROR: descriptor hashcode " + vmdHashes[i] + " for " + vmdList.get(i).id() + " same as " + vmdList.get(j).id());
                failed = true;
            }
        }
    }
    return !failed;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) VirtualMachineDescriptor(com.sun.tools.attach.VirtualMachineDescriptor) IOException(java.io.IOException) AttachNotSupportedException(com.sun.tools.attach.AttachNotSupportedException) AttachProvider(com.sun.tools.attach.spi.AttachProvider) VirtualMachine(com.sun.tools.attach.VirtualMachine)

Example 15 with VirtualMachineDescriptor

use of com.sun.tools.attach.VirtualMachineDescriptor in project openj9 by eclipse.

the class TargetManager method vmIdExists.

public boolean vmIdExists() {
    List<AttachProvider> providers = AttachProvider.providers();
    AttachProvider ap = providers.get(0);
    if (null == ap) {
        logger.error("no attach providers available");
        return false;
    }
    List<VirtualMachineDescriptor> vmds = ap.listVirtualMachines();
    Iterator<VirtualMachineDescriptor> vmi = vmds.iterator();
    while (vmi.hasNext()) {
        VirtualMachineDescriptor vm = vmi.next();
        if (targetId.equals(vm.id()) && ((null == displayName) || displayName.equals(vm.displayName()))) {
            return true;
        }
    }
    return false;
}
Also used : VirtualMachineDescriptor(com.sun.tools.attach.VirtualMachineDescriptor) AttachProvider(com.sun.tools.attach.spi.AttachProvider)

Aggregations

VirtualMachineDescriptor (com.sun.tools.attach.VirtualMachineDescriptor)26 IOException (java.io.IOException)16 AttachNotSupportedException (com.sun.tools.attach.AttachNotSupportedException)13 AttachProvider (com.sun.tools.attach.spi.AttachProvider)12 VirtualMachine (com.sun.tools.attach.VirtualMachine)11 Test (org.testng.annotations.Test)7 ArrayList (java.util.ArrayList)5 Msg.getString (com.ibm.oti.util.Msg.getString)2 AgentLoadException (com.sun.tools.attach.AgentLoadException)2 File (java.io.File)2 URISyntaxException (java.net.URISyntaxException)2 JMXServiceURL (javax.management.remote.JMXServiceURL)2 MonitorException (sun.jvmstat.monitor.MonitorException)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 FileLock (com.ibm.tools.attach.target.FileLock)1 Reply (com.ibm.tools.attach.target.Reply)1 AgentInitializationException (com.sun.tools.attach.AgentInitializationException)1 AttachOperationFailedException (com.sun.tools.attach.AttachOperationFailedException)1 CommonContext (io.aeron.CommonContext)1 AeronCluster (io.aeron.cluster.client.AeronCluster)1