matthiasblaesing commented on code in PR #5317:
URL: https://github.com/apache/netbeans/pull/5317#discussion_r1080572328
##########
harness/o.n.insane/src/org/netbeans/insane/scanner/SimpleXmlVisitor.java:
##########
@@ -61,7 +61,7 @@ public void close() throws IOException {
// ignore for this xml format
- public void visitClass(Class cls) {}
+ public void visitClass(Class<?> cls) {}
Review Comment:
Please don't introduce generics into exported methods in a pure cleanup PR.
##########
harness/o.n.insane/src/org/netbeans/insane/scanner/ScannerUtils.java:
##########
@@ -169,7 +172,7 @@ public static int sizeOf(Object o) {
* @return the size of all objects in the filtered transitive closure
* of the roots collection.
*/
- public static int recursiveSizeOf(Collection roots, Filter f) throws
Exception {
+ public static int recursiveSizeOf(Collection<?> roots, Filter f) throws
Exception {
Review Comment:
If this is exported, please don't add generics for general cleanup.
##########
harness/o.n.insane/src/org/netbeans/insane/model/ObjectSet.java:
##########
@@ -90,7 +90,7 @@ public boolean contains(Object key) {
return get(key) != null;
}
- public Iterator iterator() {
+ public Iterator<Object> iterator() {
return new Iterator() {
Review Comment:
Isn't this missing the generic here?
##########
harness/o.n.insane/src/org/netbeans/insane/impl/InsaneEngine.java:
##########
@@ -51,23 +52,23 @@ public InsaneEngine(Filter f, Visitor v, boolean
analyzeStatic) {
public InsaneEngine(ObjectMap backend, Filter f, Visitor v, boolean
analyzeStatic) {
objects = backend;
- filter = f == null ? ScannerUtils.noFilter() : f;
+ filter = (f != null ? f : ScannerUtils.noFilter());
visitor = v;
analyzeStaticData = analyzeStatic;
}
// normal set is enough, java.lang.Class have identity-based equals()
- private Set<Class> knownClasses = new HashSet<Class>();
+ private final Set<Class<?>> knownClasses = new HashSet<>();
// The queue for BFS scan of the heap.
// each thing, before added to the queue, is added
// to the known* structures and reported to the visitor
- private Queue<Object> queue = new Queue<Object>();
+ private final Queue<Object> queue = new Queue<>();
- public void traverse(Collection roots) throws Exception {
+ public void traverse(Collection<?> roots) throws Exception {
Review Comment:
If this is exported, please don't add generics for general cleanup.
##########
harness/o.n.insane/src/org/netbeans/insane/scanner/ScannerUtils.java:
##########
@@ -233,58 +231,22 @@ public void run() {
if (ret[0] != null) throw ret[0];
}
- private static Thread[] getAllThreads() {
- ThreadGroup act = Thread.currentThread().getThreadGroup();
- while (act.getParent() != null) act = act.getParent();
- Thread[] all = new Thread[2*act.activeCount()+5];
- int cnt = act.enumerate(all);
- Thread[] ret = new Thread[cnt];
- System.arraycopy(all, 0, ret, 0, cnt);
- return ret;
- }
-
- @SuppressWarnings("deprecation")
- private static void suspendAllThreads(Set<Thread> except) {
- Thread[] threads = getAllThreads();
-
- for (int i=0; i<threads.length; i++) {
- if (!except.contains(threads[i])) {
- if ((threads[i].getName().indexOf("VM") == -1) &&
- (threads[i].getName().indexOf("CompilerTh") == -1) &&
- (threads[i].getName().indexOf("Signal") == -1)) {
- System.out.println("suspending " + threads[i]);
- threads[i].suspend();
- }
- }
- }
- }
-
- @SuppressWarnings("deprecation")
- private static void resumeAllThreads() {
- Thread[] threads = getAllThreads();
-
- for (int i=0; i<threads.length; i++) {
- threads[i].resume();
- }
- }
-
private static class ClassInfo {
- private static Map<Class, ClassInfo> classInfoRegistry = new
WeakHashMap<Class, ClassInfo>();
- private int size;
+ private static final Map<Class<?>, ClassInfo> classInfoRegistry = new
WeakHashMap<>();
+ private final int size;
- private ClassInfo(Class cls) {
-// this.cls = cls;
+ private ClassInfo(Class<?> cls) {
if (cls.isArray()) {
- Class base = cls.getComponentType();
+ Class<?> base = cls.getComponentType();
size = -getSize(base, true);
} else {
// iterate all fields and sum the sizes
int sum = 0;
- for (Class act = cls; act != null; act = act.getSuperclass()) {
- Field[] flds = act.getDeclaredFields();
- for (int i=0; i<flds.length; i++) { // count all nonstatic
fields
- if ((flds[i].getModifiers() & Modifier.STATIC) == 0) {
- sum += getSize(flds[i].getType(), false);
+ for (Class<?> act = cls; act != null; act =
act.getSuperclass()) {
+ // count all nonstatic fields
Review Comment:
this is not correct, the comment in line 281 says it: It created the sum,
not the count. In this case comment is duplicated and the name of the variable
`sum` is already a dead give away.
##########
harness/o.n.insane/src/org/netbeans/insane/scanner/CountingVisitor.java:
##########
@@ -59,22 +61,25 @@ public void visitObject(ObjectMap map, Object obj) {
size += objSize;
}
+ @Override
public void visitStaticReference(ObjectMap map, Object to,
java.lang.reflect.Field ref) {}
+ @Override
public void visitObjectReference(ObjectMap map, Object from, Object to,
java.lang.reflect.Field ref) {}
+ @Override
public void visitArrayReference(ObjectMap map, Object from, Object to, int
index) {}
public Set<Class<?>> getClasses() {
return Collections.unmodifiableSet(infoMap.keySet());
}
- public int getCountForClass(Class cls) {
+ public int getCountForClass(Class<?> cls) {
Review Comment:
If this is exported, please don't add generics for general cleanup.
##########
harness/o.n.insane/src/org/netbeans/insane/scanner/ScannerUtils.java:
##########
@@ -210,19 +213,14 @@ public static Set<Object> interestingRoots() {
* @param v a Visitor to be notified on all found objects and references.
* @param roots a Collection of objects to be evaluated.
*/
- public static void scanExclusivelyInAWT(final Filter f, final Visitor v,
final Set roots) throws Exception {
+ public static void scanExclusivelyInAWT(final Filter f, final Visitor v,
final Set<?> roots) throws Exception {
Review Comment:
If this is exported, please don't add generics for general cleanup.
##########
harness/o.n.insane/src/org/netbeans/insane/scanner/CountingVisitor.java:
##########
@@ -59,22 +61,25 @@ public void visitObject(ObjectMap map, Object obj) {
size += objSize;
}
+ @Override
public void visitStaticReference(ObjectMap map, Object to,
java.lang.reflect.Field ref) {}
+ @Override
public void visitObjectReference(ObjectMap map, Object from, Object to,
java.lang.reflect.Field ref) {}
+ @Override
public void visitArrayReference(ObjectMap map, Object from, Object to, int
index) {}
public Set<Class<?>> getClasses() {
return Collections.unmodifiableSet(infoMap.keySet());
}
- public int getCountForClass(Class cls) {
+ public int getCountForClass(Class<?> cls) {
Info info = infoMap.get(cls);
if (info == null) throw new IllegalArgumentException("Unknown class");
return info.count;
}
- public int getSizeForClass(Class cls) {
+ public int getSizeForClass(Class<?> cls) {
Review Comment:
If this is exported, please don't add generics for general cleanup.
##########
harness/o.n.insane/src/org/netbeans/insane/impl/LiveEngine.java:
##########
@@ -98,7 +105,8 @@ private void visitRef(Object from, Object to, Field field) {
addIncommingRef(to, from, field);
if (rest.containsKey(to)) {
rest.remove(to);
- if (rest.size() == 0) throw new ObjectFoundException();
+ if (rest.isEmpty())
+ throw new ObjectFoundException();
Review Comment:
Please add braces
##########
harness/o.n.insane/src/org/netbeans/insane/model/InsaneConverter.java:
##########
@@ -351,8 +351,8 @@ private void compute() {
objsOffset = currentOffset;
// compute offsets of instances
- for (Iterator<InstanceInfo> it = instanceInfo.iterator();
it.hasNext(); ) {
- InstanceInfo info = it.next();
+ for (Iterator it = instanceInfo.iterator(); it.hasNext(); ) {
+ InstanceInfo info = (InstanceInfo)it.next();
Review Comment:
How does this help?
##########
harness/o.n.insane/src/org/netbeans/insane/impl/InsaneEngine.java:
##########
@@ -51,23 +52,23 @@ public InsaneEngine(Filter f, Visitor v, boolean
analyzeStatic) {
public InsaneEngine(ObjectMap backend, Filter f, Visitor v, boolean
analyzeStatic) {
objects = backend;
- filter = f == null ? ScannerUtils.noFilter() : f;
+ filter = (f != null ? f : ScannerUtils.noFilter());
Review Comment:
I don't see the improvement, on the contrary, the new form introduces noise.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists