1 12 package org.eclipse.jdi.internal; 13 14 15 import java.io.ByteArrayOutputStream ; 16 import java.io.DataInputStream ; 17 import java.io.DataOutputStream ; 18 import java.io.IOException ; 19 import java.lang.reflect.Modifier ; 20 import java.util.ArrayList ; 21 import java.util.Collections ; 22 import java.util.HashMap ; 23 import java.util.HashSet ; 24 import java.util.Hashtable ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 import java.util.Map ; 28 import java.util.Set ; 29 30 import org.eclipse.jdi.internal.jdwp.JdwpCommandPacket; 31 import org.eclipse.jdi.internal.jdwp.JdwpFieldID; 32 import org.eclipse.jdi.internal.jdwp.JdwpID; 33 import org.eclipse.jdi.internal.jdwp.JdwpMethodID; 34 import org.eclipse.jdi.internal.jdwp.JdwpReferenceTypeID; 35 import org.eclipse.jdi.internal.jdwp.JdwpReplyPacket; 36 37 import com.ibm.icu.text.MessageFormat; 38 import com.sun.jdi.AbsentInformationException; 39 import com.sun.jdi.ClassLoaderReference; 40 import com.sun.jdi.ClassNotLoadedException; 41 import com.sun.jdi.ClassNotPreparedException; 42 import com.sun.jdi.ClassObjectReference; 43 import com.sun.jdi.ClassType; 44 import com.sun.jdi.Field; 45 import com.sun.jdi.InternalException; 46 import com.sun.jdi.NativeMethodException; 47 import com.sun.jdi.ObjectCollectedException; 48 import com.sun.jdi.ReferenceType; 49 import com.sun.jdi.VMDisconnectedException; 50 import com.sun.jdi.Value; 51 52 58 public abstract class ReferenceTypeImpl extends TypeImpl implements ReferenceType, org.eclipse.jdi.hcr.ReferenceType { 59 60 61 public static final int JDWP_CLASS_STATUS_VERIFIED = 1; 62 public static final int JDWP_CLASS_STATUS_PREPARED = 2; 63 public static final int JDWP_CLASS_STATUS_INITIALIZED = 4; 64 public static final int JDWP_CLASS_STATUS_ERROR = 8; 65 66 67 private static String [] fgClassStatusStrings = null; 68 69 72 protected static class FileInfo { 73 74 77 protected int fFileId; 78 79 82 protected String fFileName; 83 84 87 protected String fAbsoluteFileName; 88 89 94 private HashMap fLineInfo; 95 96 103 public FileInfo(int fileId, String fileName, String absoluteFileName) { 104 fFileId= fileId; 105 fFileName= fileName; 106 fAbsoluteFileName= absoluteFileName; 107 fLineInfo= new HashMap (); 108 } 109 110 119 public void addLineInfo(int inputLine, int outputStartLine, int outputLineRange) { 120 Integer key= new Integer (inputLine); 121 List outputLines= (List )fLineInfo.get(key); 122 if (outputLines == null) { 123 outputLines= new ArrayList (); 124 fLineInfo.put(key, outputLines); 125 } 126 outputLines.add(new int[] {outputStartLine, outputLineRange}); 127 } 128 129 136 public List getOutputLinesForLine(int lineNumber) { 137 List list= new ArrayList (); 138 List outputLines= (List )fLineInfo.get(new Integer (lineNumber)); 139 if (outputLines != null) { 140 for (Iterator iter = outputLines.iterator(); iter.hasNext();) { 141 int[] info = (int[])iter.next(); 142 int outputLineNumber= info[0]; 143 int length = info[1]; 144 if (length == 0){ 145 length = length + 1; 146 } 147 for (int i= 0; i < length; i++) { 148 list.add(new Integer (outputLineNumber++)); 149 } 150 } 151 } 152 return list; 153 } 154 155 158 public boolean equals(Object object) { 159 if (!(object instanceof FileInfo)) { 160 return false; 161 } 162 return fFileId == ((FileInfo)object).fFileId; 163 } 164 165 } 166 167 170 protected static class Stratum { 171 172 175 private String fId; 176 177 180 private List fFileInfos; 181 182 185 private int fPrimaryFileId; 186 187 191 private HashMap fOutputLineToInputLine; 192 193 197 public Stratum(String id) { 198 fId= id; 199 fFileInfos= new ArrayList (); 200 fOutputLineToInputLine= new HashMap (); 201 fPrimaryFileId= -1; 202 } 203 204 210 public void addFileInfo(int fileId, String fileName) throws AbsentInformationException { 211 addFileInfo(fileId, fileName, null); 212 } 213 214 221 public void addFileInfo(int fileId, String fileName, String absoluteFileName) throws AbsentInformationException { 222 if (fPrimaryFileId == -1) { 223 fPrimaryFileId= fileId; 224 } 225 FileInfo fileInfo= new FileInfo(fileId, fileName, absoluteFileName); 226 if (fFileInfos.contains(fileInfo)) { 227 throw new AbsentInformationException(MessageFormat.format(JDIMessages.ReferenceTypeImpl_28, new String [] {Integer.toString(fileId), fId})); 228 } 229 fFileInfos.add(fileInfo); 230 } 231 232 242 public void addLineInfo(int inputStartLine, int lineFileId, int repeatCount, int outputStartLine, int outputLineIncrement) throws AbsentInformationException { 243 FileInfo fileInfo= null; 244 for (Iterator iter = fFileInfos.iterator(); iter.hasNext();) { 246 FileInfo element = (FileInfo)iter.next(); 247 if (element.fFileId == lineFileId) { 248 fileInfo= element; 249 } 250 } 251 if (fileInfo == null) { 252 throw new AbsentInformationException(MessageFormat.format(JDIMessages.ReferenceTypeImpl_29, new String [] {Integer.toString(lineFileId)})); 253 } 254 for (int i= 0; i < repeatCount; i++, inputStartLine++) { 256 fileInfo.addLineInfo(inputStartLine, outputStartLine, outputLineIncrement); 257 if (outputLineIncrement == 0) { 258 addLineInfoToMap(inputStartLine, lineFileId, outputStartLine); 260 } else { 261 for (int j= 0; j < outputLineIncrement; j++, outputStartLine++) { 262 addLineInfoToMap(inputStartLine, lineFileId, outputStartLine); 263 } 264 } 265 } 266 } 267 268 271 private void addLineInfoToMap(int inputStartLine, int lineFileId, int outputStartLine) { 272 Integer key= new Integer (outputStartLine); 273 List inputLines= (List )fOutputLineToInputLine.get(key); 274 if (inputLines == null) { 275 inputLines= new ArrayList (); 276 fOutputLineToInputLine.put(key, inputLines); 277 } 278 inputLines.add(new int[] {lineFileId, inputStartLine}); 279 } 280 281 286 public FileInfo getFileInfo(String sourceName) { 287 for (Iterator iter = fFileInfos.iterator(); iter.hasNext();) { 288 FileInfo fileInfo = (FileInfo)iter.next(); 289 if (fileInfo.fFileName.equals(sourceName)) { 290 return fileInfo; 291 } 292 } 293 return null; 294 } 295 296 300 public List getInputLineInfos(int outputLineNumber) { 301 return (List )fOutputLineToInputLine.get(new Integer (outputLineNumber)); 302 } 303 304 } 305 306 307 308 309 private JdwpReferenceTypeID fReferenceTypeID; 310 311 312 protected List fInterfaces = null; 313 private List fMethods = null; 314 private Hashtable fMethodTable= null; 315 private List fFields = null; 316 private List fAllMethods = null; 317 private List fVisibleMethods = null; 318 private List fAllFields = null; 319 private List fVisibleFields = null; 320 private List fAllInterfaces = null; 321 private Map fStratumAllLineLocations = null; 322 private String fSourceName = null; 323 private int fModifierBits = -1; 324 private ClassLoaderReferenceImpl fClassLoader = null; 325 private ClassObjectReferenceImpl fClassObject = null; 326 327 private String fGenericSignature; private boolean fGenericSignatureKnown; 330 private boolean fGotClassFileVersion = false; private int fClassFileVersion; private boolean fIsHCREligible; private boolean fIsVersionKnown; 335 private boolean fSourceDebugExtensionAvailable= true; 337 340 private String fDefaultStratumId; 342 347 private Map fStrata; 349 352 private String fSmap; 354 357 protected ReferenceTypeImpl(String description, VirtualMachineImpl vmImpl, JdwpReferenceTypeID referenceTypeID) { 358 super(description, vmImpl); 359 fReferenceTypeID = referenceTypeID; 360 } 361 362 365 protected ReferenceTypeImpl(String description, VirtualMachineImpl vmImpl, JdwpReferenceTypeID referenceTypeID, String signature, String genericSignature) { 366 super(description, vmImpl); 367 fReferenceTypeID = referenceTypeID; 368 setSignature(signature); 369 setGenericSignature(genericSignature); 370 } 371 372 375 public abstract byte typeTag(); 376 377 380 public void flushStoredJdwpResults() { 381 Iterator iter; 382 383 if (fMethods != null) { 385 iter = fMethods.iterator(); 386 while (iter.hasNext()) { 387 MethodImpl method = (MethodImpl)iter.next(); 388 method.flushStoredJdwpResults(); 389 } 390 fMethods = null; 391 fMethodTable= null; 392 } 393 394 if (fFields != null) { 396 iter = fFields.iterator(); 397 while (iter.hasNext()) { 398 FieldImpl field = (FieldImpl)iter.next(); 399 field.flushStoredJdwpResults(); 400 } 401 fFields = null; 402 } 403 404 fInterfaces = null; 405 fAllMethods = null; 406 fVisibleMethods = null; 407 fAllFields = null; 408 fVisibleFields = null; 409 fAllInterfaces = null; 410 fStratumAllLineLocations = null; 411 fSourceName = null; 412 fModifierBits = -1; 413 fClassLoader = null; 414 fClassObject = null; 415 fGotClassFileVersion = false; 416 fGenericSignature= null; 418 fGenericSignatureKnown= false; 419 420 fSourceDebugExtensionAvailable= true; 422 fDefaultStratumId= null; 423 fStrata= null; 424 fSmap= null; 425 426 fSignature = null; 428 fSourceName = null; 429 } 430 431 434 public List allInterfaces() { 435 if (fAllInterfaces != null) { 436 return fAllInterfaces; 437 } 438 439 444 HashSet allInterfacesSet = new HashSet (interfaces()); 447 448 Iterator interfaces = interfaces().iterator(); 450 InterfaceTypeImpl inter; 451 while (interfaces.hasNext()) { 452 inter = (InterfaceTypeImpl)interfaces.next(); 453 allInterfacesSet.addAll(inter.allInterfaces()); 454 } 455 456 if (this instanceof ClassType) { 458 ClassType superclass = ((ClassType)this).superclass(); 459 if (superclass != null) { 460 allInterfacesSet.addAll(superclass.allInterfaces()); 461 } 462 } 463 464 fAllInterfaces = new ArrayList (allInterfacesSet); 465 return fAllInterfaces; 466 } 467 468 471 public JdwpReferenceTypeID getRefTypeID() { 472 return fReferenceTypeID; 473 } 474 475 478 public int modifiers() { 479 if (fModifierBits != -1) 480 return fModifierBits; 481 482 initJdwpRequest(); 483 try { 484 JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.RT_MODIFIERS, this); 485 defaultReplyErrorHandler(replyPacket.errorCode()); 486 DataInputStream replyData = replyPacket.dataInStream(); 487 fModifierBits = readInt("modifiers", AccessibleImpl.getModifierStrings(), replyData); return fModifierBits; 489 } catch (IOException e) { 490 defaultIOExceptionHandler(e); 491 return 0; 492 } finally { 493 handledJdwpRequest(); 494 } 495 } 496 497 500 private void addVisibleMethods(List inheritedMethods, Set nameAndSignatures, List resultMethods) { 501 Iterator iter = inheritedMethods.iterator(); 502 MethodImpl inheritedMethod; 503 while (iter.hasNext()) { 504 inheritedMethod = (MethodImpl)iter.next(); 505 if (!nameAndSignatures.contains(inheritedMethod.name() + inheritedMethod.signature())) { 506 resultMethods.add(inheritedMethod); 507 } 508 } 509 } 510 511 514 public List visibleMethods() { 515 if (fVisibleMethods != null) 516 return fVisibleMethods; 517 518 523 Set namesAndSignatures = new HashSet (); 525 List visibleMethods= new ArrayList (); 526 527 for (Iterator iter= methods().iterator(); iter.hasNext();) { 529 MethodImpl method= (MethodImpl) iter.next(); 530 namesAndSignatures.add(method.name() + method.signature()); 531 visibleMethods.add(method); 532 } 533 534 Iterator interfaces = interfaces().iterator(); 536 InterfaceTypeImpl inter; 537 while (interfaces.hasNext()) { 538 inter = (InterfaceTypeImpl)interfaces.next(); 539 addVisibleMethods(inter.visibleMethods(), namesAndSignatures, visibleMethods); 540 } 541 542 if (this instanceof ClassType) { 544 ClassType superclass = ((ClassType)this).superclass(); 545 if (superclass != null) 546 addVisibleMethods(superclass.visibleMethods(), namesAndSignatures, visibleMethods); 547 } 548 549 fVisibleMethods= visibleMethods; 550 return fVisibleMethods; 551 } 552 553 556 public List allMethods() { 557 if (fAllMethods != null) 558 return fAllMethods; 559 560 565 HashSet resultSet = new HashSet (); 567 568 resultSet.addAll(methods()); 570 571 Iterator interfaces = interfaces().iterator(); 573 InterfaceTypeImpl inter; 574 while (interfaces.hasNext()) { 575 inter = (InterfaceTypeImpl)interfaces.next(); 576 resultSet.addAll(inter.allMethods()); 577 } 578 579 if (this instanceof ClassType) { 581 ClassType superclass = ((ClassType)this).superclass(); 582 if (superclass != null) 583 resultSet.addAll(superclass.allMethods()); 584 } 585 586 fAllMethods = new ArrayList (resultSet); 587 return fAllMethods; 588 } 589 590 593 public List interfaces() { 594 if (fInterfaces != null) { 595 return fInterfaces; 596 } 597 598 initJdwpRequest(); 599 try { 600 JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.RT_INTERFACES, this); 601 switch (replyPacket.errorCode()) { 602 case JdwpReplyPacket.NOT_FOUND: 603 return Collections.EMPTY_LIST; 606 default: 607 defaultReplyErrorHandler(replyPacket.errorCode()); 608 } 609 DataInputStream replyData = replyPacket.dataInStream(); 610 List elements = new ArrayList (); 611 int nrOfElements = readInt("elements", replyData); for (int i = 0; i < nrOfElements; i++) { 613 InterfaceTypeImpl ref = InterfaceTypeImpl.read(this, replyData); 614 if (ref == null) { 615 continue; 616 } 617 elements.add(ref); 618 } 619 fInterfaces = elements; 620 return elements; 621 } catch (IOException e) { 622 defaultIOExceptionHandler(e); 623 return null; 624 } finally { 625 handledJdwpRequest(); 626 } 627 } 628 629 632 private void addVisibleFields(List newFields, Set names, List resultFields) { 633 Iterator iter = newFields.iterator(); 634 FieldImpl field; 635 while (iter.hasNext()) { 636 field = (FieldImpl)iter.next(); 637 String name = field.name(); 638 if (!names.contains(name)) { 639 resultFields.add(field); 640 names.add(name); 641 } 642 } 643 } 644 645 648 public List visibleFields() { 649 if (fVisibleFields != null) 650 return fVisibleFields; 651 652 657 HashSet fieldNames = new HashSet (); 659 660 List visibleFields = new ArrayList (); 662 addVisibleFields(fields(), fieldNames, visibleFields); 663 664 Iterator interfaces = interfaces().iterator(); 666 InterfaceTypeImpl inter; 667 while (interfaces.hasNext()) { 668 inter = (InterfaceTypeImpl)interfaces.next(); 669 addVisibleFields(inter.visibleFields(), fieldNames, visibleFields); 670 } 671 672 if (this instanceof ClassType) { 674 ClassType superclass = ((ClassType)this).superclass(); 675 if (superclass != null) 676 addVisibleFields(superclass.visibleFields(), fieldNames, visibleFields); 677 } 678 679 fVisibleFields = visibleFields; 680 return fVisibleFields; 681 } 682 683 686 public List allFields() { 687 if (fAllFields != null) 688 return fAllFields; 689 690 695 HashSet resultSet = new HashSet (); 697 698 resultSet.addAll(fields()); 700 701 Iterator interfaces = interfaces().iterator(); 703 InterfaceTypeImpl inter; 704 while (interfaces.hasNext()) { 705 inter = (InterfaceTypeImpl)interfaces.next(); 706 resultSet.addAll(inter.allFields()); 707 } 708 709 if (this instanceof ClassType) { 711 ClassType superclass = ((ClassType)this).superclass(); 712 if (superclass != null) 713 resultSet.addAll(superclass.allFields()); 714 } 715 716 fAllFields = new ArrayList (resultSet); 717 return fAllFields; 718 } 719 720 723 public ClassLoaderReference classLoader() { 724 if (fClassLoader != null) 725 return fClassLoader; 726 727 initJdwpRequest(); 728 try { 729 JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.RT_CLASS_LOADER, this); 730 defaultReplyErrorHandler(replyPacket.errorCode()); 731 DataInputStream replyData = replyPacket.dataInStream(); 732 fClassLoader = ClassLoaderReferenceImpl.read(this, replyData); 733 return fClassLoader; 734 } catch (IOException e) { 735 defaultIOExceptionHandler(e); 736 return null; 737 } finally { 738 handledJdwpRequest(); 739 } 740 } 741 742 745 public ClassObjectReference classObject() { 746 if (fClassObject != null) 747 return fClassObject; 748 749 initJdwpRequest(); 750 try { 751 JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.RT_CLASS_OBJECT, this); 752 defaultReplyErrorHandler(replyPacket.errorCode()); 753 DataInputStream replyData = replyPacket.dataInStream(); 754 fClassObject = ClassObjectReferenceImpl.read(this, replyData); 755 return fClassObject; 756 } catch (IOException e) { 757 defaultIOExceptionHandler(e); 758 return null; 759 } finally { 760 handledJdwpRequest(); 761 } 762 } 763 764 767 protected int status() { 768 initJdwpRequest(); 770 try { 771 JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.RT_STATUS, this); 772 defaultReplyErrorHandler(replyPacket.errorCode()); 773 DataInputStream replyData = replyPacket.dataInStream(); 774 int status = readInt("status", classStatusStrings(), replyData); return status; 776 } catch (IOException e) { 777 defaultIOExceptionHandler(e); 778 return 0; 779 } finally { 780 handledJdwpRequest(); 781 } 782 } 783 784 787 public boolean failedToInitialize() { 788 return (status() & JDWP_CLASS_STATUS_ERROR) != 0; 789 } 790 791 794 public boolean isInitialized() { 795 return (status() & JDWP_CLASS_STATUS_INITIALIZED) != 0; 796 } 797 798 801 public boolean isPrepared() { 802 return (status() & JDWP_CLASS_STATUS_PREPARED) != 0; 803 } 804 805 808 public boolean isVerified() { 809 return (status() & JDWP_CLASS_STATUS_VERIFIED) != 0; 810 } 811 812 815 public Field fieldByName(String name) { 816 Iterator iter = visibleFields().iterator(); 817 while (iter.hasNext()) { 818 FieldImpl field = (FieldImpl)iter.next(); 819 if (field.name().equals(name)) 820 return field; 821 } 822 return null; 823 } 824 825 828 public List fields() { 829 if (fFields != null) { 830 return fFields; 831 } 832 833 initJdwpRequest(); 836 try { 837 boolean withGenericSignature= virtualMachineImpl().isJdwpVersionGreaterOrEqual(1, 5); 838 int jdwpCommand= withGenericSignature ? JdwpCommandPacket.RT_FIELDS_WITH_GENERIC : JdwpCommandPacket.RT_FIELDS; 839 JdwpReplyPacket replyPacket = requestVM(jdwpCommand, this); 840 defaultReplyErrorHandler(replyPacket.errorCode()); 841 DataInputStream replyData = replyPacket.dataInStream(); 842 List elements = new ArrayList (); 843 int nrOfElements = readInt("elements", replyData); for (int i = 0; i < nrOfElements; i++) { 845 FieldImpl elt = FieldImpl.readWithNameSignatureModifiers(this, this, withGenericSignature, replyData); 846 if (elt == null) { 847 continue; 848 } 849 elements.add(elt); 850 } 851 fFields = elements; 852 return fFields; 853 } catch (IOException e) { 854 defaultIOExceptionHandler(e); 855 return null; 856 } finally { 857 handledJdwpRequest(); 858 } 859 } 860 861 864 public FieldImpl findField(JdwpFieldID fieldID) { 865 Iterator iter = fields().iterator(); 866 while(iter.hasNext()) { 867 FieldImpl field = (FieldImpl)iter.next(); 868 if (field.getFieldID().equals(fieldID)) 869 return field; 870 } 871 return null; 872 } 873 874 877 public MethodImpl findMethod(JdwpMethodID methodID) { 878 if (methodID.value() == 0) { 879 return new MethodImpl(virtualMachineImpl(), this, methodID, JDIMessages.ReferenceTypeImpl_Obsolete_method_1, "", null, -1); } 881 if (fMethodTable == null) { 882 fMethodTable= new Hashtable (); 883 Iterator iter = methods().iterator(); 884 while(iter.hasNext()) { 885 MethodImpl method = (MethodImpl)iter.next(); 886 fMethodTable.put(method.getMethodID(), method); 887 } 888 } 889 return (MethodImpl)fMethodTable.get(methodID); 890 } 891 892 895 public Value getValue(Field field) { 896 ArrayList list = new ArrayList (1); 897 list.add(field); 898 return (ValueImpl)getValues(list).get(field); 899 } 900 901 904 public Map getValues(List fields) { 905 if (fields.isEmpty()) { 907 return new HashMap (); 908 } 909 initJdwpRequest(); 911 try { 912 ByteArrayOutputStream outBytes = new ByteArrayOutputStream (); 913 DataOutputStream outData = new DataOutputStream (outBytes); 914 int fieldsSize = fields.size(); 915 write(this, outData); 916 writeInt(fieldsSize, "size", outData); for (int i = 0; i < fieldsSize; i++) { 918 FieldImpl field = (FieldImpl)fields.get(i); 919 checkVM(field); 920 field.getFieldID().write(outData); 921 } 922 923 JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.RT_GET_VALUES, outBytes); 924 defaultReplyErrorHandler(replyPacket.errorCode()); 925 926 DataInputStream replyData = replyPacket.dataInStream(); 927 HashMap map = new HashMap (); 928 int nrOfElements = readInt("elements", replyData); if (nrOfElements != fieldsSize) 930 throw new InternalError (JDIMessages.ReferenceTypeImpl_Retrieved_a_different_number_of_values_from_the_VM_than_requested_3); 931 932 for (int i = 0; i < nrOfElements; i++) { 933 map.put(fields.get(i), ValueImpl.readWithTag(this, replyData)); 934 } 935 return map; 936 } catch (IOException e) { 937 defaultIOExceptionHandler(e); 938 return null; 939 } finally { 940 handledJdwpRequest(); 941 } 942 } 943 944 947 public int hashCode() { 948 return fReferenceTypeID.hashCode(); 949 } 950 951 955 public boolean equals(Object object) { 956 return object != null 957 && object.getClass().equals(this.getClass()) 958 && fReferenceTypeID.equals(((ReferenceTypeImpl)object).fReferenceTypeID) 959 && virtualMachine().equals(((MirrorImpl)object).virtualMachine()); 960 } 961 962 965 public int compareTo(Object object) { 966 if (object == null || !object.getClass().equals(this.getClass())) 967 throw new ClassCastException (JDIMessages.ReferenceTypeImpl_Can__t_compare_reference_type_to_given_object_4); 968 return name().compareTo(((ReferenceType)object).name()); 969 } 970 971 974 public boolean isAbstract() { 975 return (modifiers() & MODIFIER_ACC_ABSTRACT) != 0; 976 } 977 978 981 public boolean isFinal() { 982 return (modifiers() & MODIFIER_ACC_FINAL) != 0; 983 } 984 985 988 public boolean isStatic() { 989 return (modifiers() & MODIFIER_ACC_STATIC) != 0; 990 } 991 992 995 public List locationsOfLine(int line) throws AbsentInformationException { 996 return locationsOfLine(virtualMachine().getDefaultStratum(), null, line); 997 } 998 999 1002 public List methods() { 1003 if (fMethods != null) 1005 return fMethods; 1006 1007 initJdwpRequest(); 1010 try { 1011 boolean withGenericSignature= virtualMachineImpl().isJdwpVersionGreaterOrEqual(1, 5); 1012 int jdwpCommand= withGenericSignature ? JdwpCommandPacket.RT_METHODS_WITH_GENERIC : JdwpCommandPacket.RT_METHODS; 1013 JdwpReplyPacket replyPacket = requestVM(jdwpCommand, this); 1014 defaultReplyErrorHandler(replyPacket.errorCode()); 1015 DataInputStream replyData = replyPacket.dataInStream(); 1016 List elements = new ArrayList (); 1017 int nrOfElements = readInt("elements", replyData); for (int i = 0; i < nrOfElements; i++) { 1019 MethodImpl elt = MethodImpl.readWithNameSignatureModifiers(this, this, withGenericSignature, replyData); 1020 if (elt == null) { 1021 continue; 1022 } 1023 elements.add(elt); 1024 } 1025 fMethods = elements; 1026 return fMethods; 1027 } catch (IOException e) { 1028 defaultIOExceptionHandler(e); 1029 return null; 1030 } finally { 1031 handledJdwpRequest(); 1032 } 1033 } 1034 1035 1038 public List methodsByName(String name) { 1039 List elements = new ArrayList (); 1040 Iterator iter = visibleMethods().iterator(); 1041 while (iter.hasNext()) { 1042 MethodImpl method = (MethodImpl)iter.next(); 1043 if (method.name().equals(name)){ 1044 elements.add(method); 1045 } 1046 } 1047 return elements; 1048 } 1049 1050 1053 public List methodsByName(String name, String signature) { 1054 List elements = new ArrayList (); 1055 Iterator iter = visibleMethods().iterator(); 1056 while (iter.hasNext()) { 1057 MethodImpl method = (MethodImpl)iter.next(); 1058 if (method.name().equals(name) && method.signature().equals(signature)) { 1059 elements.add(method); 1060 } 1061 } 1062 return elements; 1063 } 1064 1065 1068 public String name() { 1069 if (fName == null) { 1071 setName(signatureToName(signature())); 1072 } 1073 return fName; 1074 } 1075 1076 1079 public String signature() { 1080 if (fSignature != null) { 1081 return fSignature; 1082 } 1083 initJdwpRequest(); 1084 try { 1085 JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.RT_SIGNATURE, this); 1086 defaultReplyErrorHandler(replyPacket.errorCode()); 1087 DataInputStream replyData = replyPacket.dataInStream(); 1088 setSignature(readString("signature", replyData)); return fSignature; 1090 } catch (IOException e) { 1091 defaultIOExceptionHandler(e); 1092 return null; 1093 } finally { 1094 handledJdwpRequest(); 1095 } 1096 } 1097 1098 1101 public List nestedTypes() { 1102 List result = new ArrayList (); 1105 Iterator itr = virtualMachineImpl().allRefTypes(); 1106 while (itr.hasNext()) { 1107 try { 1108 ReferenceTypeImpl refType = (ReferenceTypeImpl)itr.next(); 1109 String refName = refType.name(); 1110 if (refName.length() > name().length() && refName.startsWith(name()) && refName.charAt(name().length()) == '$') { 1111 result.add(refType); 1112 } 1113 } catch (ClassNotPreparedException e) { 1114 continue; 1115 } 1116 } 1117 return result; 1118 } 1119 1120 1123 public String sourceName() throws AbsentInformationException { 1124 return (String )sourceNames(virtualMachine().getDefaultStratum()).get(0); 1127 } 1128 1129 1132 public int getClassFileVersion() { 1133 virtualMachineImpl().checkHCRSupported(); 1134 if (fGotClassFileVersion) 1135 return fClassFileVersion; 1136 1137 initJdwpRequest(); 1138 try { 1139 JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.HCR_GET_CLASS_VERSION, this); 1140 defaultReplyErrorHandler(replyPacket.errorCode()); 1141 DataInputStream replyData = replyPacket.dataInStream(); 1142 fIsHCREligible = readBoolean("HCR eligible", replyData); fIsVersionKnown = readBoolean("version known", replyData); fClassFileVersion = readInt("class file version", replyData); fGotClassFileVersion = true; 1146 return fClassFileVersion; 1147 } catch (IOException e) { 1148 defaultIOExceptionHandler(e); 1149 return 0; 1150 } finally { 1151 handledJdwpRequest(); 1152 } 1153 } 1154 1155 1158 public boolean isVersionKnown() { 1159 getClassFileVersion(); 1160 return fIsVersionKnown; 1161 } 1162 1163 1166 public boolean isHCREligible() { 1167 getClassFileVersion(); 1168 return fIsHCREligible; 1169 } 1170 1171 1174 public void write(MirrorImpl target, DataOutputStream out) throws IOException { 1175 fReferenceTypeID.write(out); 1176 if (target.fVerboseWriter != null) 1177 target.fVerboseWriter.println("referenceType", fReferenceTypeID.value()); } 1179 1180 1183 public static void writeNull(MirrorImpl target, DataOutputStream out) throws IOException { 1184 JdwpReferenceTypeID ID = new JdwpReferenceTypeID(target.virtualMachineImpl()); 1186 ID.write(out); 1187 if (target.fVerboseWriter != null) 1188 target.fVerboseWriter.println("referenceType", ID.value()); } 1190 1191 1194 public void writeWithTag(MirrorImpl target, DataOutputStream out) throws IOException { 1195 target.writeByte(typeTag(), "type tag", JdwpID.typeTagMap(), out); write(target, out); 1197 } 1198 1199 1202 public static ReferenceTypeImpl readWithTypeTag(MirrorImpl target, DataInputStream in) throws IOException { 1203 byte typeTag = target.readByte("type tag", JdwpID.typeTagMap(), in); switch (typeTag) { 1205 case 0: 1206 return null; 1207 case ArrayTypeImpl.typeTag: 1208 return ArrayTypeImpl.read(target, in); 1209 case ClassTypeImpl.typeTag: 1210 return ClassTypeImpl.read(target, in); 1211 case InterfaceTypeImpl.typeTag: 1212 return InterfaceTypeImpl.read(target, in); 1213 } 1214 throw new InternalException(JDIMessages.ReferenceTypeImpl_Invalid_ReferenceTypeID_tag_encountered___8 + typeTag); 1215 } 1216 1217 1220 public List allLineLocations() throws AbsentInformationException { 1221 return allLineLocations(virtualMachine().getDefaultStratum(), null); 1222 } 1223 1224 1227 public static ReferenceTypeImpl readWithTypeTagAndSignature(MirrorImpl target, boolean withGenericSignature, DataInputStream in) throws IOException { 1228 byte typeTag = target.readByte("type tag", JdwpID.typeTagMap(), in); switch (typeTag) { 1230 case 0: 1231 return null; 1232 case ArrayTypeImpl.typeTag: 1233 return ArrayTypeImpl.readWithSignature(target, withGenericSignature, in); 1234 case ClassTypeImpl.typeTag: 1235 return ClassTypeImpl.readWithSignature(target, withGenericSignature, in); 1236 case InterfaceTypeImpl.typeTag: 1237 return InterfaceTypeImpl.readWithSignature(target, withGenericSignature, in); 1238 } 1239 throw new InternalException(JDIMessages.ReferenceTypeImpl_Invalid_ReferenceTypeID_tag_encountered___8 + typeTag); 1240 } 1241 1242 1246 public static TypeImpl create(VirtualMachineImpl vmImpl, String signature, ClassLoaderReference classLoader) throws ClassNotLoadedException { 1247 ReferenceTypeImpl refTypeBootstrap = null; 1248 List classes= vmImpl.classesBySignature(signature); 1249 ReferenceTypeImpl type; 1250 Iterator iter= classes.iterator(); 1251 while (iter.hasNext()) { 1252 type = (ReferenceTypeImpl)iter.next(); 1254 if (type.classLoader() == null) { if (classLoader == null) { 1256 return type; 1257 } 1258 refTypeBootstrap = type; 1259 } 1260 if (classLoader != null && classLoader.equals(type.classLoader())) { 1261 return type; 1262 } 1263 } 1264 if (refTypeBootstrap != null) { 1267 return refTypeBootstrap; 1268 } 1269 1270 List visibleTypes; 1271 iter= classes.iterator(); 1272 while (iter.hasNext()) { 1273 type = (ReferenceTypeImpl)iter.next(); 1276 visibleTypes= classLoader.visibleClasses(); 1277 Iterator visibleIter= visibleTypes.iterator(); 1278 while (visibleIter.hasNext()) { 1279 if (type.equals(visibleIter.next())) { 1280 return type; 1281 } 1282 } 1283 } 1284 1285 throw new ClassNotLoadedException(classSignatureToName(signature), JDIMessages.ReferenceTypeImpl_Type_has_not_been_loaded_10); 1286 } 1287 1288 1291 public static void getConstantMaps() { 1292 if (fgClassStatusStrings != null) { 1293 return; 1294 } 1295 1296 java.lang.reflect.Field [] fields = ReferenceTypeImpl.class.getDeclaredFields(); 1297 fgClassStatusStrings = new String [32]; 1298 1299 for (int i = 0; i < fields.length; i++) { 1300 java.lang.reflect.Field field = fields[i]; 1301 if ((field.getModifiers() & Modifier.PUBLIC) == 0 || (field.getModifiers() & Modifier.STATIC) == 0 || (field.getModifiers() & Modifier.FINAL) == 0) { 1302 continue; 1303 } 1304 1305 String name = field.getName(); 1306 if (!name.startsWith("JDWP_CLASS_STATUS_")) { continue; 1308 } 1309 1310 name = name.substring(18); 1311 1312 try { 1313 int value = field.getInt(null); 1314 1315 for (int j = 0; j < fgClassStatusStrings.length; j++) { 1316 if ((1 << j & value) != 0) { 1317 fgClassStatusStrings[j]= name; 1318 break; 1319 } 1320 } 1321 } catch (IllegalAccessException e) { 1322 } catch (IllegalArgumentException e) { 1324 } 1328 } 1329 } 1330 1331 1334 public static String [] classStatusStrings() { 1335 getConstantMaps(); 1336 return fgClassStatusStrings; 1337 } 1338 1339 1342 public Value createNullValue() { 1343 return null; 1344 } 1345 1346 1349 public List sourceNames(String stratumId) throws AbsentInformationException { 1350 List list= new ArrayList (); 1351 Stratum stratum= getStratum(stratumId); 1352 if (stratum != null) { 1353 List fileInfos= stratum.fFileInfos; 1355 if (fileInfos.isEmpty()) { 1356 throw new AbsentInformationException(JDIMessages.ReferenceTypeImpl_30); 1357 } 1358 for (Iterator iter = stratum.fFileInfos.iterator(); iter.hasNext();) { 1359 list.add(((FileInfo) iter.next()).fFileName); 1360 } 1361 return list; 1362 } 1363 if (fSourceName == null) { 1365 getSourceName(); 1366 } 1367 list.add(fSourceName); 1368 return list; 1369 } 1370 1371 1374 public List sourcePaths(String stratumId) throws AbsentInformationException { 1375 List list= new ArrayList (); 1376 Stratum stratum= getStratum(stratumId); 1377 if (stratum != null) { 1378 for (Iterator iter = stratum.fFileInfos.iterator(); iter.hasNext();) { 1380 FileInfo fileInfo= (FileInfo) iter.next(); 1381 String path= fileInfo.fAbsoluteFileName; 1382 if (path == null) { 1383 path= getPath(fileInfo.fFileName); 1384 } 1385 list.add(path); 1386 } 1387 return list; 1388 } 1389 if (fSourceName == null) { 1391 getSourceName(); 1392 } 1393 list.add(getPath(fSourceName)); 1394 return list; 1395 } 1396 1397 1400 public String sourceDebugExtension() throws AbsentInformationException { 1401 if (isSourceDebugExtensionAvailable()) { 1402 return fSmap; 1403 } 1404 if (!virtualMachine().canGetSourceDebugExtension()) { 1405 throw new UnsupportedOperationException (); 1406 } 1407 throw new AbsentInformationException(); 1408 } 1409 1410 1413 public List allLineLocations(String stratum, String sourceName) throws AbsentInformationException { 1414 Iterator allMethods = methods().iterator(); 1415 if (stratum == null) { stratum= defaultStratum(); 1417 } 1418 List allLineLocations= null; 1419 Map sourceNameAllLineLocations= null; 1420 if (fStratumAllLineLocations == null) { fStratumAllLineLocations= new HashMap (); 1422 } else { 1423 sourceNameAllLineLocations= (Map )fStratumAllLineLocations.get(stratum); 1425 } 1426 if (sourceNameAllLineLocations == null) { sourceNameAllLineLocations= new HashMap (); 1428 fStratumAllLineLocations.put(stratum, sourceNameAllLineLocations); 1429 } else { 1430 allLineLocations= (List )sourceNameAllLineLocations.get(sourceName); 1432 } 1433 if (allLineLocations == null) { allLineLocations = new ArrayList (); 1435 while (allMethods.hasNext()) { 1436 MethodImpl method = (MethodImpl)allMethods.next(); 1437 if (method.isAbstract() || method.isNative()) { 1438 continue; 1439 } 1440 allLineLocations.addAll(method.allLineLocations(stratum, sourceName)); 1441 } 1442 sourceNameAllLineLocations.put(sourceName, allLineLocations); 1443 } 1444 return allLineLocations; 1445 } 1446 1447 1450 public List locationsOfLine(String stratum, String sourceName, int lineNumber) throws AbsentInformationException { 1451 Iterator allMethods = methods().iterator(); 1452 List locations= new ArrayList (); 1453 boolean hasLineInformation= false; 1454 AbsentInformationException exception= null; 1455 while (allMethods.hasNext()) { 1456 MethodImpl method = (MethodImpl)allMethods.next(); 1457 if (method.isAbstract() || method.isNative()) { 1458 continue; 1459 } 1460 try { 1463 locations.addAll(locationsOfLine(stratum, sourceName, lineNumber, method)); 1464 hasLineInformation= true; 1465 } catch (AbsentInformationException e) { 1466 exception= e; 1467 } 1468 } 1469 if (!hasLineInformation && exception != null) { 1470 throw exception; 1471 } 1472 return locations; 1473 } 1474 1475 1478 public List availableStrata() { 1479 List list= new ArrayList (); 1480 if (isSourceDebugExtensionAvailable()) { 1482 list.addAll(fStrata.keySet()); 1483 } 1484 list.add(VirtualMachineImpl.JAVA_STRATUM_NAME); 1486 return list; 1487 } 1488 1489 1492 public String defaultStratum() { 1493 if (isSourceDebugExtensionAvailable()) { 1494 return fDefaultStratumId; 1495 } 1496 return VirtualMachineImpl.JAVA_STRATUM_NAME; 1498 } 1499 1500 1507 private String getPath(String sourceName) { 1508 String name= name(); 1509 int lastDotOffset= name.lastIndexOf('.'); 1510 if (lastDotOffset == -1) { 1511 return sourceName; 1512 } 1513 char fileSeparator= System.getProperty("file.separator").charAt(0); return name.substring(0, lastDotOffset).replace('.', fileSeparator) + fileSeparator + sourceName; 1515 } 1516 1517 1524 private Stratum getStratum(String stratumId) { 1525 if (!VirtualMachineImpl.JAVA_STRATUM_NAME.equals(stratumId) && isSourceDebugExtensionAvailable()) { 1526 if (stratumId == null || !fStrata.keySet().contains(stratumId)) { 1527 stratumId= fDefaultStratumId; 1528 } 1529 if (!VirtualMachineImpl.JAVA_STRATUM_NAME.equals(stratumId)) { 1530 return (Stratum)fStrata.get(stratumId); 1531 } 1532 } 1533 return null; 1534 } 1535 1536 1540 private void getSourceDebugExtension() throws AbsentInformationException { 1541 initJdwpRequest(); 1542 try { 1543 JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.RT_SOURCE_DEBUG_EXTENSION, this); 1544 if (replyPacket.errorCode() == JdwpReplyPacket.ABSENT_INFORMATION) { 1545 throw new AbsentInformationException(JDIMessages.ReferenceTypeImpl_31); 1546 } 1547 defaultReplyErrorHandler(replyPacket.errorCode()); 1548 DataInputStream replyData = replyPacket.dataInStream(); 1549 fSmap= readString(JDIMessages.ReferenceTypeImpl_32, replyData); 1550 } catch (IOException e) { 1551 defaultIOExceptionHandler(e); 1552 } finally { 1553 handledJdwpRequest(); 1554 } 1555 if ("".equals(fSmap)) { throw new AbsentInformationException(JDIMessages.ReferenceTypeImpl_31); 1560 } 1561 fStrata= new HashMap (); 1563 SourceDebugExtensionParser.parse(fSmap, this); 1564 } 1565 1566 1570 private void getSourceName() throws AbsentInformationException { 1571 if (fSourceName != null || isSourceDebugExtensionAvailable()) { 1572 return; 1573 } 1574 initJdwpRequest(); 1575 try { 1576 JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.RT_SOURCE_FILE, this); 1577 if (replyPacket.errorCode() == JdwpReplyPacket.ABSENT_INFORMATION) { 1578 throw new AbsentInformationException(JDIMessages.ReferenceTypeImpl_Source_name_is_not_known_7); 1579 } 1580 1581 defaultReplyErrorHandler(replyPacket.errorCode()); 1582 1583 DataInputStream replyData = replyPacket.dataInStream(); 1584 fSourceName = readString("source name", replyData); } catch (IOException e) { 1586 defaultIOExceptionHandler(e); 1587 } finally { 1588 handledJdwpRequest(); 1589 } 1590 } 1591 1592 1600 private synchronized boolean isSourceDebugExtensionAvailable() { 1601 if (!fSourceDebugExtensionAvailable) { 1602 return false; 1603 } 1604 if (!virtualMachine().canGetSourceDebugExtension()) { 1605 fSourceDebugExtensionAvailable= false; 1606 return false; 1607 } 1608 if (fSmap == null) { 1609 try { 1610 getSourceDebugExtension(); 1611 } catch (AbsentInformationException e) { 1612 fSourceDebugExtensionAvailable= false; 1613 return false; 1614 } 1615 } 1616 return true; 1617 } 1618 1619 1623 protected void setOutputFileName(String outputFileName) { 1624 fSourceName= outputFileName; 1625 } 1626 1627 1631 protected void setDefaultStratumId(String defaultStratumId) { 1632 fDefaultStratumId= defaultStratumId; 1633 } 1634 1635 1638 protected void addStratum(Stratum stratum) { 1639 fStrata.put(stratum.fId, stratum); 1640 } 1641 1642 1652 protected String sourceName(long codeIndex, MethodImpl method, String stratumId) throws AbsentInformationException { 1653 Stratum stratum= getStratum(stratumId); 1654 if (stratum != null) { 1655 FileInfo fileInfo= fileInfo(codeIndex, method, stratum); 1656 if (fileInfo != null) { 1657 return fileInfo.fFileName; 1658 } 1659 } 1660 if (fSourceName == null) { 1662 getSourceName(); 1663 } 1664 return fSourceName; 1665 } 1666 1667 1677 private FileInfo fileInfo(long codeIndex, MethodImpl method, Stratum stratum) { 1678 int fileId= stratum.fPrimaryFileId; 1679 if (stratum.fFileInfos.size() > 1) { 1680 List lineInfos= null; 1681 try { 1682 lineInfos = lineInfos(codeIndex, method, stratum); 1683 } catch (AbsentInformationException e) { 1684 } 1686 if (lineInfos != null) { 1687 fileId= ((int[])lineInfos.get(0))[0]; 1688 } 1689 } 1690 for (Iterator iter = stratum.fFileInfos.iterator(); iter.hasNext();) { 1691 FileInfo fileInfo = (FileInfo)iter.next(); 1692 if (fileInfo.fFileId == fileId) { 1693 return fileInfo; 1694 } 1695 } 1696 return null; 1698 } 1699 1700 1709 private List lineInfos(long codeIndex, MethodImpl method, Stratum stratum) throws AbsentInformationException { 1710 int outputLineNumber= -1; 1711 try { 1712 outputLineNumber = method.javaStratumLineNumber(codeIndex); 1713 } catch (NativeMethodException e) { return null; 1715 } 1716 if (outputLineNumber != -1) { 1717 return stratum.getInputLineInfos(outputLineNumber); 1718 } 1719 return null; 1720 } 1721 1722 1732 protected String sourcePath(long codeIndex, MethodImpl method, String stratumId) throws AbsentInformationException { 1733 Stratum stratum= getStratum(stratumId); 1734 if (stratum != null) { 1735 FileInfo fileInfo= fileInfo(codeIndex, method, stratum); 1736 if (fileInfo != null) { 1737 String path= fileInfo.fAbsoluteFileName; 1738 if (path == null) { 1739 return getPath(fileInfo.fFileName); 1740 } 1741 return path; 1742 } 1743 } 1744 if (fSourceName == null) { 1746 getSourceName(); 1747 } 1748 return getPath(fSourceName); 1749 } 1750 1751 1759 protected int lineNumber(long codeIndex, MethodImpl method, String stratumId) { 1760 Stratum stratum= getStratum(stratumId); 1761 try { 1762 if (stratum != null) { 1763 List lineInfos = lineInfos(codeIndex, method, stratum); 1764 if (lineInfos != null) { 1765 return ((int[])lineInfos.get(0))[1]; 1766 } 1767 return LocationImpl.LINE_NR_NOT_AVAILABLE; 1768 } 1769 try { 1771 return method.javaStratumLineNumber(codeIndex); 1772 } catch (NativeMethodException e) { return LocationImpl.LINE_NR_NOT_AVAILABLE; 1774 } 1775 } catch (AbsentInformationException e) { 1776 return LocationImpl.LINE_NR_NOT_AVAILABLE; 1777 } 1778 } 1779 1780 1793 public List locationsOfLine(String stratumId, String sourceName, int lineNumber, MethodImpl method) throws AbsentInformationException { 1794 Stratum stratum= getStratum(stratumId); 1795 List javaLines= new ArrayList (); 1796 if (stratum != null) { 1797 boolean found= false; 1798 for (Iterator iter = stratum.fFileInfos.iterator(); iter.hasNext() && !found;) { 1799 FileInfo fileInfo = (FileInfo)iter.next(); 1800 if (sourceName == null || (found= sourceName.equals(fileInfo.fFileName))) { 1801 javaLines.addAll(fileInfo.getOutputLinesForLine(lineNumber)); 1802 } 1803 } 1804 if (sourceName != null && !found) { 1805 throw new AbsentInformationException(JDIMessages.ReferenceTypeImpl_34); 1806 } 1807 } else { javaLines.add(new Integer (lineNumber)); 1809 } 1810 return method.javaStratumLocationsOfLines(javaLines); 1811 } 1812 1813 1826 public List allLineLocations(String stratumId, String sourceName, MethodImpl method, long[] codeIndexTable, int[] javaStratumLineNumberTable) throws AbsentInformationException { 1827 Stratum stratum= getStratum(stratumId); 1828 if (stratum != null) { 1829 int[][] lineInfoTable= new int[codeIndexTable.length][]; 1830 if (sourceName == null) { 1831 int lastIndex=0; 1832 for (int i = 0, length= javaStratumLineNumberTable.length; i < length; i++) { 1833 List lineInfos= stratum.getInputLineInfos(javaStratumLineNumberTable[i]); 1835 if (lineInfos != null) { 1836 int[] lineInfo= (int[])lineInfos.get(0); 1837 if (!lineInfo.equals(lineInfoTable[lastIndex])) { 1838 lineInfoTable[i]= lineInfo; 1839 lastIndex= i; 1840 } 1841 } 1842 } 1843 } else { FileInfo fileInfo= stratum.getFileInfo(sourceName); 1845 if (fileInfo == null) { 1846 throw new AbsentInformationException(JDIMessages.ReferenceTypeImpl_34); 1847 } 1848 int fileId= fileInfo.fFileId; 1849 int lastIndex= 0; 1850 for (int i = 0, length= javaStratumLineNumberTable.length; i < length; i++) { 1851 List lineInfos= stratum.getInputLineInfos(javaStratumLineNumberTable[i]); 1852 if (lineInfos != null) { 1853 for (Iterator iter = lineInfos.iterator(); iter.hasNext();) { 1854 int[] lineInfo= (int[])iter.next(); 1855 if (lineInfo[0] == fileId) { 1856 if (!lineInfo.equals(lineInfoTable[lastIndex])) { 1857 lineInfoTable[i]= lineInfo; 1858 lastIndex= i; 1859 } 1860 break; 1861 } 1862 } 1863 } 1864 } 1865 } 1866 List locations= new ArrayList (); 1867 for (int i = 0, length= lineInfoTable.length; i < length; i++) { 1868 if (lineInfoTable[i] != null) { 1869 locations.add(new LocationImpl(virtualMachineImpl(), method, codeIndexTable[i])); 1870 } 1871 } 1872 return locations; 1873 } 1874 List result = new ArrayList (); 1876 for (int i = 0; i < codeIndexTable.length; i++) { 1877 result.add(new LocationImpl(virtualMachineImpl(), method, codeIndexTable[i])); 1878 } 1879 return result; 1880 } 1881 1882 1886 public String genericSignature() { 1887 if (fGenericSignatureKnown) { 1888 return fGenericSignature; 1889 } 1890 if (virtualMachineImpl().isJdwpVersionGreaterOrEqual(1, 5)) { 1891 initJdwpRequest(); 1892 try { 1893 JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.RT_SIGNATURE_WITH_GENERIC, this); 1894 defaultReplyErrorHandler(replyPacket.errorCode()); 1895 DataInputStream replyData = replyPacket.dataInStream(); 1896 setSignature(readString("signature", replyData)); fGenericSignature= readString("generic signature", replyData); if (fGenericSignature.length() == 0) { 1899 fGenericSignature= null; 1900 } 1901 fGenericSignatureKnown= true; 1902 } catch (IOException e) { 1903 defaultIOExceptionHandler(e); 1904 return null; 1905 } finally { 1906 handledJdwpRequest(); 1907 } 1908 } else { 1909 fGenericSignatureKnown= true; 1910 } 1911 return fGenericSignature; 1912 } 1913 1914 1923 public void setGenericSignature(String genericSignature) { 1924 if (genericSignature == null) { 1925 fGenericSignature= null; 1926 fGenericSignatureKnown= false; 1927 } else { 1928 if (genericSignature.length() == 0) { 1929 fGenericSignature= null; 1930 } else { 1931 fGenericSignature= genericSignature; 1932 } 1933 fGenericSignatureKnown= true; 1934 } 1935 } 1936 1937 1941 public List instances(long maxInstances) { 1942 try { 1943 int max = (int)maxInstances; 1944 if (maxInstances >= Integer.MAX_VALUE) { 1945 max = Integer.MAX_VALUE; 1946 } 1947 ByteArrayOutputStream outBytes = new ByteArrayOutputStream (); 1948 DataOutputStream outData = new DataOutputStream (outBytes); 1949 write(this, outData); 1950 writeInt(max, "max instances", outData); 1952 JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.RT_INSTANCES, outBytes); 1953 switch(replyPacket.errorCode()) { 1954 case JdwpReplyPacket.INVALID_OBJECT: 1955 case JdwpReplyPacket.INVALID_CLASS: 1956 throw new ObjectCollectedException(JDIMessages.class_or_object_not_known); 1957 case JdwpReplyPacket.NOT_IMPLEMENTED: 1958 throw new UnsupportedOperationException (JDIMessages.ReferenceTypeImpl_27); 1959 case JdwpReplyPacket.ILLEGAL_ARGUMENT: 1960 throw new IllegalArgumentException (JDIMessages.ReferenceTypeImpl_26); 1961 case JdwpReplyPacket.VM_DEAD: 1962 throw new VMDisconnectedException(JDIMessages.vm_dead); 1963 } 1964 defaultReplyErrorHandler(replyPacket.errorCode()); 1965 1966 DataInputStream replyData = replyPacket.dataInStream(); 1967 int elements = readInt("element count", replyData); if(max > 0 && elements > max) { 1969 elements = max; 1970 } 1971 ArrayList list = new ArrayList (); 1972 for(int i = 0; i < elements; i++) { 1973 list.add(ValueImpl.readWithTag(this, replyData)); 1974 } 1975 return list; 1976 } 1977 catch(IOException e) { 1978 defaultIOExceptionHandler(e); 1979 return null; 1980 } finally { 1981 handledJdwpRequest(); 1982 } 1983 } 1984 1985 1989 public int majorVersion() { 1990 try { 1991 ByteArrayOutputStream outBytes = new ByteArrayOutputStream (); 1992 DataOutputStream outData = new DataOutputStream (outBytes); 1993 getRefTypeID().write(outData); 1994 1995 JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.RT_CLASS_VERSION, outBytes); 1996 switch(replyPacket.errorCode()) { 1997 case JdwpReplyPacket.INVALID_CLASS: 1998 case JdwpReplyPacket.INVALID_OBJECT: 1999 throw new ObjectCollectedException(JDIMessages.class_or_object_not_known); 2000 case JdwpReplyPacket.ABSENT_INFORMATION: 2001 return 0; 2002 case JdwpReplyPacket.NOT_IMPLEMENTED: 2003 throw new UnsupportedOperationException (JDIMessages.ReferenceTypeImpl_no_class_version_support24); 2004 case JdwpReplyPacket.VM_DEAD: 2005 throw new VMDisconnectedException(JDIMessages.vm_dead); 2006 } 2007 defaultReplyErrorHandler(replyPacket.errorCode()); 2008 2009 DataInputStream replyData = replyPacket.dataInStream(); 2010 return readInt("major version", replyData); } 2012 catch(IOException e) { 2013 defaultIOExceptionHandler(e); 2014 return 0; 2015 } finally { 2016 handledJdwpRequest(); 2017 } 2018 } 2019 2020 2024 public int minorVersion() { 2025 try { 2026 ByteArrayOutputStream outBytes = new ByteArrayOutputStream (); 2027 DataOutputStream outData = new DataOutputStream (outBytes); 2028 getRefTypeID().write(outData); 2029 2030 JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.RT_CLASS_VERSION, outBytes); 2031 switch(replyPacket.errorCode()) { 2032 case JdwpReplyPacket.INVALID_CLASS: 2033 case JdwpReplyPacket.INVALID_OBJECT: 2034 throw new ObjectCollectedException(JDIMessages.class_or_object_not_known); 2035 case JdwpReplyPacket.ABSENT_INFORMATION: 2036 return 0; 2037 case JdwpReplyPacket.NOT_IMPLEMENTED: 2038 throw new UnsupportedOperationException (JDIMessages.ReferenceTypeImpl_no_class_version_support24); 2039 case JdwpReplyPacket.VM_DEAD: 2040 throw new VMDisconnectedException(JDIMessages.vm_dead); 2041 } 2042 defaultReplyErrorHandler(replyPacket.errorCode()); 2043 2044 DataInputStream replyData = replyPacket.dataInStream(); 2045 readInt("major version", replyData); return readInt("minor version", replyData); } 2048 catch(IOException e) { 2049 defaultIOExceptionHandler(e); 2050 return 0; 2051 } finally { 2052 handledJdwpRequest(); 2053 } 2054 } 2055 2056 2060 public int constantPoolCount() { 2061 try { 2062 ByteArrayOutputStream outBytes = new ByteArrayOutputStream (); 2063 DataOutputStream outData = new DataOutputStream (outBytes); 2064 this.getRefTypeID().write(outData); 2065 2066 JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.RT_CONSTANT_POOL, outBytes); 2067 switch(replyPacket.errorCode()) { 2068 case JdwpReplyPacket.INVALID_CLASS: 2069 case JdwpReplyPacket.INVALID_OBJECT: 2070 throw new ObjectCollectedException(JDIMessages.class_or_object_not_known); 2071 case JdwpReplyPacket.ABSENT_INFORMATION: 2072 return 0; 2073 case JdwpReplyPacket.NOT_IMPLEMENTED: 2074 throw new UnsupportedOperationException (JDIMessages.ReferenceTypeImpl_no_constant_pool_support); 2075 case JdwpReplyPacket.VM_DEAD: 2076 throw new VMDisconnectedException(JDIMessages.vm_dead); 2077 } 2078 defaultReplyErrorHandler(replyPacket.errorCode()); 2079 2080 DataInputStream replyData = replyPacket.dataInStream(); 2081 return readInt("pool count", replyData); } 2083 catch(IOException e) { 2084 defaultIOExceptionHandler(e); 2085 return 0; 2086 } finally { 2087 handledJdwpRequest(); 2088 } 2089 } 2090 2091 2095 public byte[] constantPool() { 2096 try { 2097 ByteArrayOutputStream outBytes = new ByteArrayOutputStream (); 2098 DataOutputStream outData = new DataOutputStream (outBytes); 2099 this.getRefTypeID().write(outData); 2100 2101 JdwpReplyPacket replyPacket = requestVM(JdwpCommandPacket.RT_CONSTANT_POOL, outBytes); 2102 switch(replyPacket.errorCode()) { 2103 case JdwpReplyPacket.INVALID_CLASS: 2104 case JdwpReplyPacket.INVALID_OBJECT: 2105 throw new ObjectCollectedException(JDIMessages.class_or_object_not_known); 2106 case JdwpReplyPacket.ABSENT_INFORMATION: 2107 return new byte[0]; 2108 case JdwpReplyPacket.NOT_IMPLEMENTED: 2109 throw new UnsupportedOperationException (JDIMessages.ReferenceTypeImpl_no_constant_pool_support); 2110 case JdwpReplyPacket.VM_DEAD: 2111 throw new VMDisconnectedException(JDIMessages.vm_dead); 2112 } 2113 defaultReplyErrorHandler(replyPacket.errorCode()); 2114 2115 DataInputStream replyData = replyPacket.dataInStream(); 2116 readInt("pool count", replyData); int bytes = readInt("byte count", replyData); byte[] array = new byte[bytes]; 2119 for (int i = 0; i < bytes; i++) { 2120 array[i] = readByte("byte read", replyData); } 2122 return array; 2123 } 2124 catch(IOException e) { 2125 defaultIOExceptionHandler(e); 2126 return null; 2127 } finally { 2128 handledJdwpRequest(); 2129 } 2130 } 2131} 2132 | Popular Tags |