1 /* |
1 /* |
2 * Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
24 */ |
24 */ |
25 |
25 |
26 package com.sun.tools.jdi; |
26 package com.sun.tools.jdi; |
27 |
27 |
28 import com.sun.jdi.*; |
28 import com.sun.jdi.*; |
|
29 import com.sun.jdi.ModuleReference; |
29 import com.sun.jdi.connect.spi.Connection; |
30 import com.sun.jdi.connect.spi.Connection; |
30 import com.sun.jdi.request.EventRequestManager; |
31 import com.sun.jdi.request.EventRequestManager; |
31 import com.sun.jdi.request.EventRequest; |
32 import com.sun.jdi.request.EventRequest; |
32 import com.sun.jdi.request.BreakpointRequest; |
33 import com.sun.jdi.request.BreakpointRequest; |
33 import com.sun.jdi.event.EventQueue; |
34 import com.sun.jdi.event.EventQueue; |
46 public final int sizeofFieldRef; |
47 public final int sizeofFieldRef; |
47 public final int sizeofMethodRef; |
48 public final int sizeofMethodRef; |
48 public final int sizeofObjectRef; |
49 public final int sizeofObjectRef; |
49 public final int sizeofClassRef; |
50 public final int sizeofClassRef; |
50 public final int sizeofFrameRef; |
51 public final int sizeofFrameRef; |
|
52 public final int sizeofModuleRef; |
51 |
53 |
52 final int sequenceNumber; |
54 final int sequenceNumber; |
53 |
55 |
54 private final TargetVM target; |
56 private final TargetVM target; |
55 private final EventQueueImpl eventQueue; |
57 private final EventQueueImpl eventQueue; |
72 // tested unsynchronized (since once true, it stays true), but must |
74 // tested unsynchronized (since once true, it stays true), but must |
73 // be set synchronously |
75 // be set synchronously |
74 private Map<Long, ReferenceType> typesByID; |
76 private Map<Long, ReferenceType> typesByID; |
75 private TreeSet<ReferenceType> typesBySignature; |
77 private TreeSet<ReferenceType> typesBySignature; |
76 private boolean retrievedAllTypes = false; |
78 private boolean retrievedAllTypes = false; |
|
79 |
|
80 private Map<Long, ModuleReference> modulesByID; |
77 |
81 |
78 // For other languages support |
82 // For other languages support |
79 private String defaultStratum = null; |
83 private String defaultStratum = null; |
80 |
84 |
81 // ObjectReference cache |
85 // ObjectReference cache |
202 sizeofFieldRef = idSizes.fieldIDSize; |
206 sizeofFieldRef = idSizes.fieldIDSize; |
203 sizeofMethodRef = idSizes.methodIDSize; |
207 sizeofMethodRef = idSizes.methodIDSize; |
204 sizeofObjectRef = idSizes.objectIDSize; |
208 sizeofObjectRef = idSizes.objectIDSize; |
205 sizeofClassRef = idSizes.referenceTypeIDSize; |
209 sizeofClassRef = idSizes.referenceTypeIDSize; |
206 sizeofFrameRef = idSizes.frameIDSize; |
210 sizeofFrameRef = idSizes.frameIDSize; |
|
211 sizeofModuleRef = idSizes.objectIDSize; |
207 |
212 |
208 /** |
213 /** |
209 * Set up requests needed by internal event handler. |
214 * Set up requests needed by internal event handler. |
210 * Make sure they are distinguished by creating them with |
215 * Make sure they are distinguished by creating them with |
211 * an internal event request manager. |
216 * an internal event request manager. |
261 return this == obj; |
266 return this == obj; |
262 } |
267 } |
263 |
268 |
264 public int hashCode() { |
269 public int hashCode() { |
265 return System.identityHashCode(this); |
270 return System.identityHashCode(this); |
|
271 } |
|
272 |
|
273 public List<ModuleReference> allModules() { |
|
274 validateVM(); |
|
275 List<ModuleReference> modules = retrieveAllModules(); |
|
276 return Collections.unmodifiableList(modules); |
266 } |
277 } |
267 |
278 |
268 public List<ReferenceType> classesByName(String className) { |
279 public List<ReferenceType> classesByName(String className) { |
269 validateVM(); |
280 validateVM(); |
270 String signature = JNITypeParser.typeNameToSignature(className); |
281 String signature = JNITypeParser.typeNameToSignature(className); |
583 } |
594 } |
584 return versionInfo; |
595 return versionInfo; |
585 } catch (JDWPException exc) { |
596 } catch (JDWPException exc) { |
586 throw exc.toJDIException(); |
597 throw exc.toJDIException(); |
587 } |
598 } |
588 } |
599 } |
|
600 |
589 public String description() { |
601 public String description() { |
590 validateVM(); |
602 validateVM(); |
591 |
603 |
592 return MessageFormat.format(vmManager.getString("version_format"), |
604 return MessageFormat.format(vmManager.getString("version_format"), |
593 "" + vmManager.majorInterfaceVersion(), |
605 "" + vmManager.majorInterfaceVersion(), |
672 public boolean canGetMethodReturnValues() { |
684 public boolean canGetMethodReturnValues() { |
673 return versionInfo().jdwpMajor > 1 || |
685 return versionInfo().jdwpMajor > 1 || |
674 versionInfo().jdwpMinor >= 6; |
686 versionInfo().jdwpMinor >= 6; |
675 } |
687 } |
676 public boolean canGetInstanceInfo() { |
688 public boolean canGetInstanceInfo() { |
677 if (versionInfo().jdwpMajor < 1 || |
689 if (versionInfo().jdwpMajor > 1 || |
678 versionInfo().jdwpMinor < 6) { |
690 versionInfo().jdwpMinor >= 6) { |
|
691 validateVM(); |
|
692 return hasNewCapabilities() && |
|
693 capabilitiesNew().canGetInstanceInfo; |
|
694 } else { |
679 return false; |
695 return false; |
680 } |
696 } |
681 validateVM(); |
|
682 return hasNewCapabilities() && |
|
683 capabilitiesNew().canGetInstanceInfo; |
|
684 } |
697 } |
685 public boolean canUseSourceNameFilters() { |
698 public boolean canUseSourceNameFilters() { |
686 if (versionInfo().jdwpMajor < 1 || |
699 return versionInfo().jdwpMajor > 1 || |
687 versionInfo().jdwpMinor < 6) { |
700 versionInfo().jdwpMinor >= 6; |
688 return false; |
|
689 } |
|
690 return true; |
|
691 } |
701 } |
692 public boolean canForceEarlyReturn() { |
702 public boolean canForceEarlyReturn() { |
693 validateVM(); |
703 validateVM(); |
694 return hasNewCapabilities() && |
704 return hasNewCapabilities() && |
695 capabilitiesNew().canForceEarlyReturn; |
705 capabilitiesNew().canForceEarlyReturn; |
701 validateVM(); |
711 validateVM(); |
702 return hasNewCapabilities() && |
712 return hasNewCapabilities() && |
703 capabilitiesNew().canGetSourceDebugExtension; |
713 capabilitiesNew().canGetSourceDebugExtension; |
704 } |
714 } |
705 public boolean canGetClassFileVersion() { |
715 public boolean canGetClassFileVersion() { |
706 if ( versionInfo().jdwpMajor < 1 && |
716 return versionInfo().jdwpMajor > 1 || |
707 versionInfo().jdwpMinor < 6) { |
717 versionInfo().jdwpMinor >= 6; |
708 return false; |
|
709 } else { |
|
710 return true; |
|
711 } |
|
712 } |
718 } |
713 public boolean canGetConstantPool() { |
719 public boolean canGetConstantPool() { |
714 validateVM(); |
720 validateVM(); |
715 return hasNewCapabilities() && |
721 return hasNewCapabilities() && |
716 capabilitiesNew().canGetConstantPool; |
722 capabilitiesNew().canGetConstantPool; |
727 } |
733 } |
728 public boolean canGetMonitorFrameInfo() { |
734 public boolean canGetMonitorFrameInfo() { |
729 validateVM(); |
735 validateVM(); |
730 return hasNewCapabilities() && |
736 return hasNewCapabilities() && |
731 capabilitiesNew().canGetMonitorFrameInfo; |
737 capabilitiesNew().canGetMonitorFrameInfo; |
|
738 } |
|
739 public boolean canGetModuleInfo() { |
|
740 validateVM(); |
|
741 return versionInfo().jdwpMajor >= 9; |
732 } |
742 } |
733 |
743 |
734 public void setDebugTraceMode(int traceFlags) { |
744 public void setDebugTraceMode(int traceFlags) { |
735 validateVM(); |
745 validateVM(); |
736 this.traceFlags = traceFlags; |
746 this.traceFlags = traceFlags; |
925 } catch (JDWPException exc) { |
935 } catch (JDWPException exc) { |
926 throw exc.toJDIException(); |
936 throw exc.toJDIException(); |
927 } |
937 } |
928 } |
938 } |
929 return capabilitiesNew; |
939 return capabilitiesNew; |
|
940 } |
|
941 |
|
942 private synchronized ModuleReference addModule(long id) { |
|
943 if (modulesByID == null) { |
|
944 modulesByID = new HashMap<Long, ModuleReference>(77); |
|
945 } |
|
946 ModuleReference module = new ModuleReferenceImpl(vm, id); |
|
947 modulesByID.put(id, module); |
|
948 return module; |
|
949 } |
|
950 |
|
951 ModuleReference getModule(long id) { |
|
952 if (id == 0) { |
|
953 return null; |
|
954 } else { |
|
955 ModuleReference module = null; |
|
956 synchronized (this) { |
|
957 if (modulesByID != null) { |
|
958 module = modulesByID.get(id); |
|
959 } |
|
960 if (module == null) { |
|
961 module = addModule(id); |
|
962 } |
|
963 } |
|
964 return module; |
|
965 } |
|
966 } |
|
967 |
|
968 private synchronized List<ModuleReference> retrieveAllModules() { |
|
969 ModuleReferenceImpl[] reqModules; |
|
970 try { |
|
971 reqModules = JDWP.VirtualMachine.AllModules.process(vm).modules; |
|
972 } catch (JDWPException exc) { |
|
973 throw exc.toJDIException(); |
|
974 } |
|
975 ArrayList<ModuleReference> modules = new ArrayList<>(); |
|
976 for (int i = 0; i < reqModules.length; i++) { |
|
977 long moduleRef = reqModules[i].ref(); |
|
978 ModuleReference module = getModule(moduleRef); |
|
979 modules.add(module); |
|
980 } |
|
981 return modules; |
930 } |
982 } |
931 |
983 |
932 private List<ReferenceType> retrieveClassesBySignature(String signature) { |
984 private List<ReferenceType> retrieveClassesBySignature(String signature) { |
933 if ((vm.traceFlags & VirtualMachine.TRACE_REFTYPES) != 0) { |
985 if ((vm.traceFlags & VirtualMachine.TRACE_REFTYPES) != 0) { |
934 vm.printTrace("Retrieving matching ReferenceTypes, sig=" + signature); |
986 vm.printTrace("Retrieving matching ReferenceTypes, sig=" + signature); |
1362 ClassObjectReferenceImpl classObjectMirror(long id) { |
1414 ClassObjectReferenceImpl classObjectMirror(long id) { |
1363 return (ClassObjectReferenceImpl)objectMirror(id, |
1415 return (ClassObjectReferenceImpl)objectMirror(id, |
1364 JDWP.Tag.CLASS_OBJECT); |
1416 JDWP.Tag.CLASS_OBJECT); |
1365 } |
1417 } |
1366 |
1418 |
|
1419 ModuleReferenceImpl moduleMirror(long id) { |
|
1420 return (ModuleReferenceImpl)getModule(id); |
|
1421 } |
|
1422 |
1367 /* |
1423 /* |
1368 * Implementation of PathSearchingVirtualMachine |
1424 * Implementation of PathSearchingVirtualMachine |
1369 */ |
1425 */ |
1370 private JDWP.VirtualMachine.ClassPaths getClasspath() { |
1426 private JDWP.VirtualMachine.ClassPaths getClasspath() { |
1371 if (pathInfo == null) { |
1427 if (pathInfo == null) { |