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();
}
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();
}
}
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;
}
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;
}
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;
}
Aggregations