@Override public Collection<IField> getAllFields() { return realType.getAllFields(); }
@Override public Collection<IField> getAllFields() { return realType.getAllFields(); }
Collection<IField> lookupFields(IClassLoader cl) { Collection<IField> matching = new LinkedList<>(); IClass c = cl.lookupClass(TypeName.findOrCreate(className)); if(c == null) return matching; Atom atom = Atom.findOrCreateUnicodeAtom(memberName); Collection<IField> allFields = c.getAllFields(); for(IField f: allFields) { if(f.getName().equals(atom)) { matching.add(f); } } return matching; } }
private Map<PointerKey, Object> computePointerKeys(IClass klass) { Map<PointerKey, Object> result = HashMapFactory.make(); if (klass.isArrayClass()) { ArrayClass a = (ArrayClass) klass; if (a.getElementClass() != null && a.getElementClass().isReferenceType()) { PointerKey p = pointerKeys.getPointerKeyForArrayContents(new ConcreteTypeKey(a)); result.put(p, p); } } else { for (IField f : klass.getAllFields()) { if (!f.getFieldTypeReference().isPrimitiveType()) { if (f.isStatic()) { PointerKey p = pointerKeys.getPointerKeyForStaticField(f); result.put(p, p); } else { PointerKey p = pointerKeys.getPointerKeyForInstanceField(new ConcreteTypeKey(klass), f); result.put(p, p); } } } } return result; }
private Map<PointerKey, Object> computePointerKeys(IClass klass) { Map<PointerKey, Object> result = HashMapFactory.make(); if (klass.isArrayClass()) { ArrayClass a = (ArrayClass) klass; if (a.getElementClass() != null && a.getElementClass().isReferenceType()) { PointerKey p = pointerKeys.getPointerKeyForArrayContents(new ConcreteTypeKey(a)); result.put(p, p); } } else { for (IField f : klass.getAllFields()) { if (!f.getFieldTypeReference().isPrimitiveType()) { if (f.isStatic()) { PointerKey p = pointerKeys.getPointerKeyForStaticField(f); result.put(p, p); } else { PointerKey p = pointerKeys.getPointerKeyForInstanceField(new ConcreteTypeKey(klass), f); result.put(p, p); } } } } return result; }
/** * This main program shows one example use of thread escape analysis: producing a set of fields to be monitored for a * dynamic race detector. The idea is that any field might have a race with two exceptions: final fields do not have * races since there are no writes to them, and volatile fields have atomic read and write semantics provided by the * VM. Hence, this piece of code produces a list of all other fields. */ public static void main(String[] args) throws IOException, IllegalArgumentException, CancelException { String mainClassName = args[0]; Set<JarFile> jars = HashSetFactory.make(); for (int i = 1; i < args.length; i++) { jars.add(new JarFile(args[i], false)); } Set<IClass> escapingTypes = (new SimpleThreadEscapeAnalysis(jars, mainClassName)).gatherThreadEscapingClasses(); for (IClass cls : escapingTypes) { if (!cls.isArrayClass()) { for (IField f : cls.getAllFields()) { if (!f.isVolatile() && !f.isFinal()) { System.err.println(f.getReference()); } } } } } }