< prev index next >

src/jdk.jdi/share/classes/com/sun/tools/jdi/ObjectReferenceImpl.java

Print this page




  59     protected static class Cache {
  60         JDWP.ObjectReference.MonitorInfo monitorInfo = null;
  61     }
  62 
  63     private static final Cache noInitCache = new Cache();
  64     private static final Cache markerCache = new Cache();
  65     private Cache cache = noInitCache;
  66 
  67     private void disableCache() {
  68         synchronized (vm.state()) {
  69             cache = null;
  70         }
  71     }
  72 
  73     private void enableCache() {
  74         synchronized (vm.state()) {
  75             cache = markerCache;
  76         }
  77     }
  78 




  79     // Override in subclasses
  80     protected Cache newCache() {
  81         return new Cache();
  82     }
  83 
  84     protected Cache getCache() {
  85         synchronized (vm.state()) {
  86             if (cache == noInitCache) {
  87                 if (vm.state().isSuspended()) {
  88                     // Set cache now, otherwise newly created objects are
  89                     // not cached until resuspend
  90                     enableCache();
  91                 } else {
  92                     disableCache();
  93                 }
  94             }
  95             if (cache == markerCache) {
  96                 cache = newCache();
  97             }
  98             return cache;


 128         // make sure that cache and listener management are synchronized
 129         synchronized (vm.state()) {
 130             if (cache != null && (vm.traceFlags & VirtualMachine.TRACE_OBJREFS) != 0) {
 131                 vm.printTrace("Clearing temporary cache for " + description());
 132             }
 133             disableCache();
 134             if (addedListener) {
 135                 /*
 136                  * If a listener was added (i.e. this is not a
 137                  * ObjectReference that adds a listener on startup),
 138                  * remove it here.
 139                  */
 140                 addedListener = false;
 141                 return false;  // false says remove
 142             } else {
 143                 return true;
 144             }
 145         }
 146     }
 147 
















 148     public boolean equals(Object obj) {
 149         if ((obj != null) && (obj instanceof ObjectReferenceImpl)) {
 150             ObjectReferenceImpl other = (ObjectReferenceImpl)obj;




 151             return (ref() == other.ref()) &&
 152                    super.equals(obj);

 153         } else {
 154             return false;
 155         }
 156     }
 157 
 158     public int hashCode() {
 159         return(int)ref();
 160     }
 161 
 162     public Type type() {
 163         return referenceType();
 164     }
 165 
 166     public ReferenceType referenceType() {
 167         if (type == null) {
 168             try {
 169                 JDWP.ObjectReference.ReferenceType rtinfo =
 170                     JDWP.ObjectReference.ReferenceType.process(vm, this);
 171                 type = vm.referenceType(rtinfo.typeID,
 172                                         rtinfo.refTypeTag);


 453             } catch (JDWPException exc) {
 454                 // If already collected, no harm done, no exception
 455                 if (exc.errorCode() != JDWP.Error.INVALID_OBJECT) {
 456                     throw exc.toJDIException();
 457                 }
 458                 return;
 459             }
 460         }
 461     }
 462 
 463     public boolean isCollected() {
 464         try {
 465             return JDWP.ObjectReference.IsCollected.process(vm, this).
 466                                                               isCollected;
 467         } catch (JDWPException exc) {
 468             throw exc.toJDIException();
 469         }
 470     }
 471 
 472     public long uniqueID() {



 473         return ref();
 474     }
 475 
 476     JDWP.ObjectReference.MonitorInfo jdwpMonitorInfo()
 477                              throws IncompatibleThreadStateException {
 478         JDWP.ObjectReference.MonitorInfo info = null;
 479         try {
 480             Cache local;
 481 
 482             // getCache() and addlistener() must be synchronized
 483             // so that no events are lost.
 484             synchronized (vm.state()) {
 485                 local = getCache();
 486 
 487                 if (local != null) {
 488                     info = local.monitorInfo;
 489 
 490                     // Check if there will be something to cache
 491                     // and there is not already a listener
 492                     if (info == null && !vm.state().hasListener(this)) {


 594             (type().signature().charAt(0) != '[')) {
 595             throw new InvalidTypeException("Can't assign non-array value to an array");
 596         }
 597         if ("void".equals(destination.typeName())) {
 598             throw new InvalidTypeException("Can't assign object value to a void");
 599         }
 600 
 601         // Validate assignment
 602         ReferenceType destType = (ReferenceTypeImpl)destination.type();
 603         ReferenceTypeImpl myType = (ReferenceTypeImpl)referenceType();
 604         if (!myType.isAssignableTo(destType)) {
 605             JNITypeParser parser = new JNITypeParser(destType.signature());
 606             String destTypeName = parser.typeName();
 607             throw new InvalidTypeException("Can't assign " +
 608                                            type().name() +
 609                                            " to " + destTypeName);
 610         }
 611     }
 612 
 613     public String toString() {



 614         return "instance of " + referenceType().name() + "(id=" + uniqueID() + ")";
 615     }

 616 
 617     byte typeValueKey() {
 618         return JDWP.Tag.OBJECT;
 619     }
 620 
 621     private static boolean isNonVirtual(int options) {
 622         return (options & INVOKE_NONVIRTUAL) != 0;
 623     }
 624 }


  59     protected static class Cache {
  60         JDWP.ObjectReference.MonitorInfo monitorInfo = null;
  61     }
  62 
  63     private static final Cache noInitCache = new Cache();
  64     private static final Cache markerCache = new Cache();
  65     private Cache cache = noInitCache;
  66 
  67     private void disableCache() {
  68         synchronized (vm.state()) {
  69             cache = null;
  70         }
  71     }
  72 
  73     private void enableCache() {
  74         synchronized (vm.state()) {
  75             cache = markerCache;
  76         }
  77     }
  78 
  79     private boolean isInlineType() {
  80         return referenceType().signature().startsWith("Q");
  81     }
  82 
  83     // Override in subclasses
  84     protected Cache newCache() {
  85         return new Cache();
  86     }
  87 
  88     protected Cache getCache() {
  89         synchronized (vm.state()) {
  90             if (cache == noInitCache) {
  91                 if (vm.state().isSuspended()) {
  92                     // Set cache now, otherwise newly created objects are
  93                     // not cached until resuspend
  94                     enableCache();
  95                 } else {
  96                     disableCache();
  97                 }
  98             }
  99             if (cache == markerCache) {
 100                 cache = newCache();
 101             }
 102             return cache;


 132         // make sure that cache and listener management are synchronized
 133         synchronized (vm.state()) {
 134             if (cache != null && (vm.traceFlags & VirtualMachine.TRACE_OBJREFS) != 0) {
 135                 vm.printTrace("Clearing temporary cache for " + description());
 136             }
 137             disableCache();
 138             if (addedListener) {
 139                 /*
 140                  * If a listener was added (i.e. this is not a
 141                  * ObjectReference that adds a listener on startup),
 142                  * remove it here.
 143                  */
 144                 addedListener = false;
 145                 return false;  // false says remove
 146             } else {
 147                 return true;
 148             }
 149         }
 150     }
 151 
 152     private boolean isSubtituable(ObjectReferenceImpl other) {
 153         if (referenceType() != other.referenceType()) return false;
 154         List<Field> fields = referenceType().fields();
 155         for (Field f : fields) {
 156             if (f.isStatic()) {
 157                 fields.remove(f);
 158             }
 159         }
 160         Map<Field,Value> thisFields = getValues(fields);
 161         Map<Field,Value> otherFields = other.getValues(fields);
 162         for (Field f : fields) {
 163             if (!thisFields.get(f).equals(otherFields.get(f))) return false;
 164         }
 165         return true;
 166     }
 167 
 168     public boolean equals(Object obj) {
 169         if ((obj != null) && (obj instanceof ObjectReferenceImpl)) {
 170             ObjectReferenceImpl other = (ObjectReferenceImpl) obj;
 171             if (isInlineType()) {
 172                 return isSubtituable(other);
 173 
 174             } else {
 175                 return (ref() == other.ref()) &&
 176                         super.equals(obj);
 177             }
 178         } else {
 179             return false;
 180         }
 181     }
 182 
 183     public int hashCode() {
 184         return(int)ref();
 185     }
 186 
 187     public Type type() {
 188         return referenceType();
 189     }
 190 
 191     public ReferenceType referenceType() {
 192         if (type == null) {
 193             try {
 194                 JDWP.ObjectReference.ReferenceType rtinfo =
 195                     JDWP.ObjectReference.ReferenceType.process(vm, this);
 196                 type = vm.referenceType(rtinfo.typeID,
 197                                         rtinfo.refTypeTag);


 478             } catch (JDWPException exc) {
 479                 // If already collected, no harm done, no exception
 480                 if (exc.errorCode() != JDWP.Error.INVALID_OBJECT) {
 481                     throw exc.toJDIException();
 482                 }
 483                 return;
 484             }
 485         }
 486     }
 487 
 488     public boolean isCollected() {
 489         try {
 490             return JDWP.ObjectReference.IsCollected.process(vm, this).
 491                                                               isCollected;
 492         } catch (JDWPException exc) {
 493             throw exc.toJDIException();
 494         }
 495     }
 496 
 497     public long uniqueID() {
 498         if (isInlineType()) {
 499             throw new UnsupportedOperationException("Inline types cannot have unique IDs");
 500         }
 501         return ref();
 502     }
 503 
 504     JDWP.ObjectReference.MonitorInfo jdwpMonitorInfo()
 505                              throws IncompatibleThreadStateException {
 506         JDWP.ObjectReference.MonitorInfo info = null;
 507         try {
 508             Cache local;
 509 
 510             // getCache() and addlistener() must be synchronized
 511             // so that no events are lost.
 512             synchronized (vm.state()) {
 513                 local = getCache();
 514 
 515                 if (local != null) {
 516                     info = local.monitorInfo;
 517 
 518                     // Check if there will be something to cache
 519                     // and there is not already a listener
 520                     if (info == null && !vm.state().hasListener(this)) {


 622             (type().signature().charAt(0) != '[')) {
 623             throw new InvalidTypeException("Can't assign non-array value to an array");
 624         }
 625         if ("void".equals(destination.typeName())) {
 626             throw new InvalidTypeException("Can't assign object value to a void");
 627         }
 628 
 629         // Validate assignment
 630         ReferenceType destType = (ReferenceTypeImpl)destination.type();
 631         ReferenceTypeImpl myType = (ReferenceTypeImpl)referenceType();
 632         if (!myType.isAssignableTo(destType)) {
 633             JNITypeParser parser = new JNITypeParser(destType.signature());
 634             String destTypeName = parser.typeName();
 635             throw new InvalidTypeException("Can't assign " +
 636                                            type().name() +
 637                                            " to " + destTypeName);
 638         }
 639     }
 640 
 641     public String toString() {
 642         if (isInlineType()) {
 643             return "instance of " + referenceType().name();
 644         } else {
 645             return "instance of " + referenceType().name() + "(id=" + uniqueID() + ")";
 646         }
 647     }
 648 
 649     byte typeValueKey() {
 650         return JDWP.Tag.OBJECT;
 651     }
 652 
 653     private static boolean isNonVirtual(int options) {
 654         return (options & INVOKE_NONVIRTUAL) != 0;
 655     }
 656 }
< prev index next >