src/share/classes/com/sun/tools/jdi/VirtualMachineImpl.java

Print this page
rev 10195 : 8048267: Replace uses of 'new Long()' with appropriate alternative across core classes
Reviewed-by: chegar, psandoz
Contributed-by: otaviojava@java.net


 764             case JDWP.TypeTag.INTERFACE:
 765                 type = new InterfaceTypeImpl(vm, id);
 766                 break;
 767             case JDWP.TypeTag.ARRAY:
 768                 type = new ArrayTypeImpl(vm, id);
 769                 break;
 770             default:
 771                 throw new InternalException("Invalid reference type tag");
 772         }
 773 
 774         /*
 775          * If a signature was specified, make sure to set it ASAP, to
 776          * prevent any needless JDWP command to retrieve it. (for example,
 777          * typesBySignature.add needs the signature, to maintain proper
 778          * ordering.
 779          */
 780         if (signature != null) {
 781             type.setSignature(signature);
 782         }
 783 
 784         typesByID.put(new Long(id), type);
 785         typesBySignature.add(type);
 786 
 787         if ((vm.traceFlags & VirtualMachine.TRACE_REFTYPES) != 0) {
 788            vm.printTrace("Caching new ReferenceType, sig=" + signature +
 789                          ", id=" + id);
 790         }
 791 
 792         return type;
 793     }
 794 
 795     synchronized void removeReferenceType(String signature) {
 796         if (typesByID == null) {
 797             return;
 798         }
 799         /*
 800          * There can be multiple classes with the same name. Since
 801          * we can't differentiate here, we first remove all
 802          * matching classes from our cache...
 803          */
 804         Iterator<ReferenceType> iter = typesBySignature.iterator();
 805         int matches = 0;
 806         while (iter.hasNext()) {
 807             ReferenceTypeImpl type = (ReferenceTypeImpl)iter.next();
 808             int comp = signature.compareTo(type.signature());
 809             if (comp == 0) {
 810                 matches++;
 811                 iter.remove();
 812                 typesByID.remove(new Long(type.ref()));
 813                 if ((vm.traceFlags & VirtualMachine.TRACE_REFTYPES) != 0) {
 814                    vm.printTrace("Uncaching ReferenceType, sig=" + signature +
 815                                  ", id=" + type.ref());
 816                 }
 817 /* fix for 4359077 , don't break out. list is no longer sorted
 818         in the order we think
 819  */
 820             }
 821         }
 822 
 823         /*
 824          * ...and if there was more than one, re-retrieve the classes
 825          * with that name
 826          */
 827         if (matches > 1) {
 828             retrieveClassesBySignature(signature);
 829         }
 830     }
 831 
 832     private synchronized List<ReferenceType> findReferenceTypes(String signature) {


 878                 sb.append("Class");
 879             } else if (tag == JDWP.TypeTag.INTERFACE) {
 880                 sb.append("Interface");
 881             } else if (tag == JDWP.TypeTag.ARRAY) {
 882                 sb.append("ArrayType");
 883             } else {
 884                 sb.append("UNKNOWN TAG: " + tag);
 885             }
 886             if (signature != null) {
 887                 sb.append(", signature='" + signature + "'");
 888             }
 889             sb.append(", id=" + id);
 890             vm.printTrace(sb.toString());
 891         }
 892         if (id == 0) {
 893             return null;
 894         } else {
 895             ReferenceTypeImpl retType = null;
 896             synchronized (this) {
 897                 if (typesByID != null) {
 898                     retType = (ReferenceTypeImpl)typesByID.get(new Long(id));
 899                 }
 900                 if (retType == null) {
 901                     retType = addReferenceType(id, tag, signature);
 902                 }
 903             }
 904             return retType;
 905         }
 906     }
 907 
 908     private JDWP.VirtualMachine.Capabilities capabilities() {
 909         if (capabilities == null) {
 910             try {
 911                 capabilities = JDWP.VirtualMachine
 912                                  .Capabilities.process(vm);
 913             } catch (JDWPException exc) {
 914                 throw exc.toJDIException();
 915             }
 916         }
 917         return capabilities;
 918     }


1230         Reference<?> ref;
1231         //if ((traceFlags & TRACE_OBJREFS) != 0) {
1232         //    printTrace("Checking for softly reachable objects");
1233         //}
1234         while ((ref = referenceQueue.poll()) != null) {
1235             SoftObjectReference softRef = (SoftObjectReference)ref;
1236             removeObjectMirror(softRef);
1237             batchForDispose(softRef);
1238         }
1239     }
1240 
1241     synchronized ObjectReferenceImpl objectMirror(long id, int tag) {
1242 
1243         // Handle any queue elements that are not strongly reachable
1244         processQueue();
1245 
1246         if (id == 0) {
1247             return null;
1248         }
1249         ObjectReferenceImpl object = null;
1250         Long key = new Long(id);
1251 
1252         /*
1253          * Attempt to retrieve an existing object object reference
1254          */
1255         SoftObjectReference ref = objectsByID.get(key);
1256         if (ref != null) {
1257             object = ref.object();
1258         }
1259 
1260         /*
1261          * If the object wasn't in the table, or it's soft reference was
1262          * cleared, create a new instance.
1263          */
1264         if (object == null) {
1265             switch (tag) {
1266                 case JDWP.Tag.OBJECT:
1267                     object = new ObjectReferenceImpl(vm, id);
1268                     break;
1269                 case JDWP.Tag.STRING:
1270                     object = new StringReferenceImpl(vm, id);


1296              * If there was no previous entry in the table, we add one here
1297              * If the previous entry was cleared, we replace it here.
1298              */
1299             objectsByID.put(key, ref);
1300             if ((traceFlags & TRACE_OBJREFS) != 0) {
1301                 printTrace("Creating new " +
1302                            object.getClass().getName() + " (id = " + id + ")");
1303             }
1304         } else {
1305             ref.incrementCount();
1306         }
1307 
1308         return object;
1309     }
1310 
1311     synchronized void removeObjectMirror(ObjectReferenceImpl object) {
1312 
1313         // Handle any queue elements that are not strongly reachable
1314         processQueue();
1315 
1316         SoftObjectReference ref = objectsByID.remove(new Long(object.ref()));
1317         if (ref != null) {
1318             batchForDispose(ref);
1319         } else {
1320             /*
1321              * If there's a live ObjectReference about, it better be part
1322              * of the cache.
1323              */
1324             throw new InternalException("ObjectReference " + object.ref() +
1325                                         " not found in object cache");
1326         }
1327     }
1328 
1329     synchronized void removeObjectMirror(SoftObjectReference ref) {
1330         /*
1331          * This will remove the soft reference if it has not been
1332          * replaced in the cache.
1333          */
1334         objectsByID.remove(ref.key());
1335     }
1336 




 764             case JDWP.TypeTag.INTERFACE:
 765                 type = new InterfaceTypeImpl(vm, id);
 766                 break;
 767             case JDWP.TypeTag.ARRAY:
 768                 type = new ArrayTypeImpl(vm, id);
 769                 break;
 770             default:
 771                 throw new InternalException("Invalid reference type tag");
 772         }
 773 
 774         /*
 775          * If a signature was specified, make sure to set it ASAP, to
 776          * prevent any needless JDWP command to retrieve it. (for example,
 777          * typesBySignature.add needs the signature, to maintain proper
 778          * ordering.
 779          */
 780         if (signature != null) {
 781             type.setSignature(signature);
 782         }
 783 
 784         typesByID.put(id, type);
 785         typesBySignature.add(type);
 786 
 787         if ((vm.traceFlags & VirtualMachine.TRACE_REFTYPES) != 0) {
 788            vm.printTrace("Caching new ReferenceType, sig=" + signature +
 789                          ", id=" + id);
 790         }
 791 
 792         return type;
 793     }
 794 
 795     synchronized void removeReferenceType(String signature) {
 796         if (typesByID == null) {
 797             return;
 798         }
 799         /*
 800          * There can be multiple classes with the same name. Since
 801          * we can't differentiate here, we first remove all
 802          * matching classes from our cache...
 803          */
 804         Iterator<ReferenceType> iter = typesBySignature.iterator();
 805         int matches = 0;
 806         while (iter.hasNext()) {
 807             ReferenceTypeImpl type = (ReferenceTypeImpl)iter.next();
 808             int comp = signature.compareTo(type.signature());
 809             if (comp == 0) {
 810                 matches++;
 811                 iter.remove();
 812                 typesByID.remove(type.ref());
 813                 if ((vm.traceFlags & VirtualMachine.TRACE_REFTYPES) != 0) {
 814                    vm.printTrace("Uncaching ReferenceType, sig=" + signature +
 815                                  ", id=" + type.ref());
 816                 }
 817 /* fix for 4359077 , don't break out. list is no longer sorted
 818         in the order we think
 819  */
 820             }
 821         }
 822 
 823         /*
 824          * ...and if there was more than one, re-retrieve the classes
 825          * with that name
 826          */
 827         if (matches > 1) {
 828             retrieveClassesBySignature(signature);
 829         }
 830     }
 831 
 832     private synchronized List<ReferenceType> findReferenceTypes(String signature) {


 878                 sb.append("Class");
 879             } else if (tag == JDWP.TypeTag.INTERFACE) {
 880                 sb.append("Interface");
 881             } else if (tag == JDWP.TypeTag.ARRAY) {
 882                 sb.append("ArrayType");
 883             } else {
 884                 sb.append("UNKNOWN TAG: " + tag);
 885             }
 886             if (signature != null) {
 887                 sb.append(", signature='" + signature + "'");
 888             }
 889             sb.append(", id=" + id);
 890             vm.printTrace(sb.toString());
 891         }
 892         if (id == 0) {
 893             return null;
 894         } else {
 895             ReferenceTypeImpl retType = null;
 896             synchronized (this) {
 897                 if (typesByID != null) {
 898                     retType = (ReferenceTypeImpl)typesByID.get(id);
 899                 }
 900                 if (retType == null) {
 901                     retType = addReferenceType(id, tag, signature);
 902                 }
 903             }
 904             return retType;
 905         }
 906     }
 907 
 908     private JDWP.VirtualMachine.Capabilities capabilities() {
 909         if (capabilities == null) {
 910             try {
 911                 capabilities = JDWP.VirtualMachine
 912                                  .Capabilities.process(vm);
 913             } catch (JDWPException exc) {
 914                 throw exc.toJDIException();
 915             }
 916         }
 917         return capabilities;
 918     }


1230         Reference<?> ref;
1231         //if ((traceFlags & TRACE_OBJREFS) != 0) {
1232         //    printTrace("Checking for softly reachable objects");
1233         //}
1234         while ((ref = referenceQueue.poll()) != null) {
1235             SoftObjectReference softRef = (SoftObjectReference)ref;
1236             removeObjectMirror(softRef);
1237             batchForDispose(softRef);
1238         }
1239     }
1240 
1241     synchronized ObjectReferenceImpl objectMirror(long id, int tag) {
1242 
1243         // Handle any queue elements that are not strongly reachable
1244         processQueue();
1245 
1246         if (id == 0) {
1247             return null;
1248         }
1249         ObjectReferenceImpl object = null;
1250         Long key = id;
1251 
1252         /*
1253          * Attempt to retrieve an existing object object reference
1254          */
1255         SoftObjectReference ref = objectsByID.get(key);
1256         if (ref != null) {
1257             object = ref.object();
1258         }
1259 
1260         /*
1261          * If the object wasn't in the table, or it's soft reference was
1262          * cleared, create a new instance.
1263          */
1264         if (object == null) {
1265             switch (tag) {
1266                 case JDWP.Tag.OBJECT:
1267                     object = new ObjectReferenceImpl(vm, id);
1268                     break;
1269                 case JDWP.Tag.STRING:
1270                     object = new StringReferenceImpl(vm, id);


1296              * If there was no previous entry in the table, we add one here
1297              * If the previous entry was cleared, we replace it here.
1298              */
1299             objectsByID.put(key, ref);
1300             if ((traceFlags & TRACE_OBJREFS) != 0) {
1301                 printTrace("Creating new " +
1302                            object.getClass().getName() + " (id = " + id + ")");
1303             }
1304         } else {
1305             ref.incrementCount();
1306         }
1307 
1308         return object;
1309     }
1310 
1311     synchronized void removeObjectMirror(ObjectReferenceImpl object) {
1312 
1313         // Handle any queue elements that are not strongly reachable
1314         processQueue();
1315 
1316         SoftObjectReference ref = objectsByID.remove(object.ref());
1317         if (ref != null) {
1318             batchForDispose(ref);
1319         } else {
1320             /*
1321              * If there's a live ObjectReference about, it better be part
1322              * of the cache.
1323              */
1324             throw new InternalException("ObjectReference " + object.ref() +
1325                                         " not found in object cache");
1326         }
1327     }
1328 
1329     synchronized void removeObjectMirror(SoftObjectReference ref) {
1330         /*
1331          * This will remove the soft reference if it has not been
1332          * replaced in the cache.
1333          */
1334         objectsByID.remove(ref.key());
1335     }
1336