1 /*
2  * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
3  * Copyright 2013 SAP AG. All rights reserved.
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This code is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License version 2 only, as
8  * published by the Free Software Foundation.  Oracle designates this
9  * particular file as subject to the "Classpath" exception as provided
10  * by Oracle in the LICENSE file that accompanied this code.
11  *
12  * This code is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15  * version 2 for more details (a copy is included in the LICENSE file that
16  * accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License version
19  * 2 along with this work; if not, write to the Free Software Foundation,
20  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21  *
22  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
23  * or visit www.oracle.com if you need additional information or have any
24  * questions.
25  */
26 package sun.tools.attach;
27 
28 import com.sun.tools.attach.VirtualMachine;
29 import com.sun.tools.attach.VirtualMachineDescriptor;
30 import com.sun.tools.attach.AttachNotSupportedException;
31 import com.sun.tools.attach.spi.AttachProvider;
32 
33 import java.io.IOException;
34 
35 // Based on 'LinuxAttachProvider.java'. All occurrences of the string
36 // "Linux" have been textually replaced by "Aix" to avoid confusion.
37 
38 /*
39  * An AttachProvider implementation for Aix that uses a UNIX domain
40  * socket.
41  */
42 public class AixAttachProvider extends HotSpotAttachProvider {
43 
44     // perf counter for the JVM version
45     private static final String JVM_VERSION = "java.property.java.vm.version";
46 
AixAttachProvider()47     public AixAttachProvider() {
48     }
49 
name()50     public String name() {
51         return "sun";
52     }
53 
type()54     public String type() {
55         return "socket";
56     }
57 
attachVirtualMachine(String vmid)58     public VirtualMachine attachVirtualMachine(String vmid)
59         throws AttachNotSupportedException, IOException
60     {
61         checkAttachPermission();
62 
63         // AttachNotSupportedException will be thrown if the target VM can be determined
64         // to be not attachable.
65         testAttachable(vmid);
66 
67         return new AixVirtualMachine(this, vmid);
68     }
69 
attachVirtualMachine(VirtualMachineDescriptor vmd)70     public VirtualMachine attachVirtualMachine(VirtualMachineDescriptor vmd)
71         throws AttachNotSupportedException, IOException
72     {
73         if (vmd.provider() != this) {
74             throw new AttachNotSupportedException("provider mismatch");
75         }
76         // To avoid re-checking if the VM if attachable, we check if the descriptor
77         // is for a hotspot VM - these descriptors are created by the listVirtualMachines
78         // implementation which only returns a list of attachable VMs.
79         if (vmd instanceof HotSpotVirtualMachineDescriptor) {
80             assert ((HotSpotVirtualMachineDescriptor)vmd).isAttachable();
81             checkAttachPermission();
82             return new AixVirtualMachine(this, vmd.id());
83         } else {
84             return attachVirtualMachine(vmd.id());
85         }
86     }
87 
88 }
89