fb-contrib-commit Mailing List for fb-contrib (Page 60)
Brought to you by:
dbrosius
You can subscribe to this list here.
2005 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(56) |
Oct
(60) |
Nov
(58) |
Dec
(89) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2006 |
Jan
(66) |
Feb
(55) |
Mar
(85) |
Apr
(115) |
May
(35) |
Jun
(28) |
Jul
(3) |
Aug
(48) |
Sep
(37) |
Oct
(22) |
Nov
(14) |
Dec
(66) |
2007 |
Jan
(45) |
Feb
(63) |
Mar
(10) |
Apr
(1) |
May
(1) |
Jun
(12) |
Jul
|
Aug
|
Sep
(25) |
Oct
(21) |
Nov
(39) |
Dec
|
2008 |
Jan
(7) |
Feb
|
Mar
(26) |
Apr
(5) |
May
(2) |
Jun
(32) |
Jul
(9) |
Aug
(10) |
Sep
|
Oct
(3) |
Nov
(1) |
Dec
|
2009 |
Jan
(10) |
Feb
(31) |
Mar
(32) |
Apr
(35) |
May
(25) |
Jun
|
Jul
(31) |
Aug
(10) |
Sep
(95) |
Oct
(35) |
Nov
(10) |
Dec
(34) |
2010 |
Jan
(90) |
Feb
(4) |
Mar
(7) |
Apr
(20) |
May
(20) |
Jun
(13) |
Jul
(7) |
Aug
(18) |
Sep
(25) |
Oct
(4) |
Nov
(16) |
Dec
(2) |
2011 |
Jan
(1) |
Feb
|
Mar
(11) |
Apr
(3) |
May
(2) |
Jun
(26) |
Jul
(10) |
Aug
(2) |
Sep
|
Oct
(1) |
Nov
(1) |
Dec
(1) |
2012 |
Jan
(3) |
Feb
(4) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
(14) |
Nov
(3) |
Dec
(4) |
2013 |
Jan
(3) |
Feb
(2) |
Mar
(1) |
Apr
(4) |
May
|
Jun
(1) |
Jul
(3) |
Aug
|
Sep
|
Oct
(4) |
Nov
(3) |
Dec
(3) |
2014 |
Jan
(4) |
Feb
(2) |
Mar
(4) |
Apr
(1) |
May
(2) |
Jun
|
Jul
(2) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2015 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(4) |
Jun
|
Jul
|
Aug
(3) |
Sep
|
Oct
|
Nov
(3) |
Dec
(3) |
2016 |
Jan
(2) |
Feb
|
Mar
|
Apr
(2) |
May
|
Jun
|
Jul
(1) |
Aug
(2) |
Sep
(4) |
Oct
(2) |
Nov
(7) |
Dec
|
2017 |
Jan
(1) |
Feb
|
Mar
(4) |
Apr
(5) |
May
(2) |
Jun
|
Jul
(2) |
Aug
|
Sep
(4) |
Oct
|
Nov
|
Dec
(3) |
2018 |
Jan
|
Feb
|
Mar
(2) |
Apr
|
May
(5) |
Jun
(2) |
Jul
(2) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Dave B. <dbr...@us...> - 2006-03-13 06:47:42
|
Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30845/src/com/mebigfatguy/fbcontrib/detect Modified Files: JDBCVendorReliance.java LocalSynchronizedCollection.java Log Message: more more impl to RegisterUtils Index: JDBCVendorReliance.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/JDBCVendorReliance.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- JDBCVendorReliance.java 13 Mar 2006 06:13:42 -0000 1.8 +++ JDBCVendorReliance.java 13 Mar 2006 06:47:39 -0000 1.9 @@ -53,14 +53,15 @@ stack.resetForMethodEntry(this); jdbcLocals.clear(); + int[] parmRegs = RegisterUtils.getParameterRegisters(obj); Type[] argTypes = obj.getArgumentTypes(); - int reg = obj.isStatic() ? 0 : 1; - for (Type arg : argTypes) { - String sig = arg.getSignature(); - if (isJDBCClass(sig)) - jdbcLocals.put(new Integer(reg), new Integer(RegisterUtils.getLocalVariableEndRange(obj.getLocalVariableTable(), reg, 0))); - - reg += (sig.equals("J") || sig.equals("D")) ? 2 : 1; + + for (int t = 0; t < argTypes.length; t++) { + String sig = argTypes[t].getSignature(); + if (isJDBCClass(sig)) { + jdbcLocals.put(new Integer(parmRegs[t]), + new Integer(RegisterUtils.getLocalVariableEndRange(obj.getLocalVariableTable(), parmRegs[t], 0))); + } } } Index: LocalSynchronizedCollection.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LocalSynchronizedCollection.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- LocalSynchronizedCollection.java 13 Mar 2006 06:02:11 -0000 1.9 +++ LocalSynchronizedCollection.java 13 Mar 2006 06:47:39 -0000 1.10 @@ -25,8 +25,6 @@ import java.util.Set; import org.apache.bcel.classfile.Code; -import org.apache.bcel.classfile.LocalVariable; -import org.apache.bcel.classfile.LocalVariableTable; import org.apache.bcel.classfile.Method; import org.apache.bcel.generic.Type; @@ -89,16 +87,10 @@ @Override public void visitMethod(Method obj) { syncRegs.clear(); - String sig = obj.getSignature(); - Type[] argTypes = Type.getArgumentTypes(sig); - int curReg = obj.isStatic() ? 0 : 1; - for (Type t : argTypes) { - sig = t.getSignature(); - syncRegs.put(new Integer(curReg), new CollectionRegInfo(RegisterUtils.getLocalVariableEndRange(obj.getLocalVariableTable(), curReg, 0))); - if ("J".equals(sig) || "D".equals(sig)) { - curReg++; - } - curReg++; + int[] parmRegs = RegisterUtils.getParameterRegisters(obj); + for (int pr : parmRegs) { + syncRegs.put(new Integer(pr), + new CollectionRegInfo(RegisterUtils.getLocalVariableEndRange(obj.getLocalVariableTable(), pr, 0))); } } @@ -135,21 +127,6 @@ try { stack.mergeJumps(this); - int curPC = getPC(); - Iterator<CollectionRegInfo> it = syncRegs.values().iterator(); - while (it.hasNext()) { - CollectionRegInfo cri = it.next(); - if (cri.getEndPCRange() < curPC) { - if (!cri.getIgnore()) { - bugReporter.reportBug(new BugInstance(this, "LSYC_LOCAL_SYNCHRONIZED_COLLECTION", cri.getPriority()) - .addClass(this) - .addMethod(this) - .addSourceLine(cri.getSourceLineAnnotation())); - } - it.remove(); - } - } - if (seen == INVOKESPECIAL) { if ("<init>".equals(getNameConstantOperand())) { if (syncCtors.contains(getClassConstantOperand())) { @@ -218,6 +195,21 @@ } } } + + int curPC = getPC(); + Iterator<CollectionRegInfo> it = syncRegs.values().iterator(); + while (it.hasNext()) { + CollectionRegInfo cri = it.next(); + if (cri.getEndPCRange() < curPC) { + if (!cri.getIgnore()) { + bugReporter.reportBug(new BugInstance(this, "LSYC_LOCAL_SYNCHRONIZED_COLLECTION", cri.getPriority()) + .addClass(this) + .addMethod(this) + .addSourceLine(cri.getSourceLineAnnotation())); + } + it.remove(); + } + } } finally { stack.sawOpcode(this, seen); if (tosIsSyncColReg != null) { |
From: Dave B. <dbr...@us...> - 2006-03-13 06:13:46
|
Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/utils In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17673/src/com/mebigfatguy/fbcontrib/utils Modified Files: RegisterUtils.java Log Message: refactor to use RegisterUtils Index: RegisterUtils.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/RegisterUtils.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- RegisterUtils.java 13 Mar 2006 06:02:12 -0000 1.2 +++ RegisterUtils.java 13 Mar 2006 06:13:42 -0000 1.3 @@ -1,3 +1,21 @@ +/* + * fb-contrib - Auxilliary detectors for Java programs + * Copyright (C) 2005-2006 Dave Brosius + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ package com.mebigfatguy.fbcontrib.utils; import org.apache.bcel.Constants; @@ -27,7 +45,9 @@ public static int getAStoreReg(DismantleBytecode dbc, int seen) { if (seen == Constants.ASTORE) return dbc.getRegisterOperand(); - return seen - Constants.ASTORE_0; + if ((seen >= Constants.ALOAD_0) && (seen <= Constants.ALOAD_3)) + return seen - Constants.ASTORE_0; + return -1; } /** @@ -40,7 +60,9 @@ public static int getALoadReg(DismantleBytecode dbc, int seen) { if (seen == Constants.ALOAD) return dbc.getRegisterOperand(); - return seen - Constants.ALOAD_0; + if ((seen >= Constants.ALOAD_0) && (seen <= Constants.ALOAD_3)) + return seen - Constants.ALOAD_0; + return -1; } /** |
Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17673/src/com/mebigfatguy/fbcontrib/detect Modified Files: BloatedSynchronizedBlock.java FinalParameters.java JDBCVendorReliance.java UnrelatedCollectionContents.java Log Message: refactor to use RegisterUtils Index: UnrelatedCollectionContents.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedCollectionContents.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- UnrelatedCollectionContents.java 12 Mar 2006 06:27:17 -0000 1.15 +++ UnrelatedCollectionContents.java 13 Mar 2006 06:13:42 -0000 1.16 @@ -26,8 +26,8 @@ import org.apache.bcel.classfile.Code; import org.apache.bcel.classfile.JavaClass; -import org.apache.bcel.classfile.LocalVariable; -import org.apache.bcel.classfile.LocalVariableTable; + +import com.mebigfatguy.fbcontrib.utils.RegisterUtils; import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; @@ -163,7 +163,7 @@ commonSupers = new HashSet<String>(); localCollections.put(new Integer(reg), commonSupers); addNewItem(commonSupers, addItm); - Integer scopeEnd = getRegisterScopeEnd(reg); + Integer scopeEnd = RegisterUtils.getLocalVariableEndRange(getMethod().getLocalVariableTable(), reg, getNextPC()); if (scopeEnd != null) { Set<Integer> regs = localScopeEnds.get(scopeEnd); if (regs == null) { @@ -261,15 +261,4 @@ it.remove(); } } - - private Integer getRegisterScopeEnd(final int reg) { - LocalVariableTable lvt = getMethod().getLocalVariableTable(); - if (lvt == null) - return null; - LocalVariable lv = lvt.getLocalVariable(reg, getPC()); - if (lv == null) - return null; - - return new Integer(lv.getStartPC() + lv.getLength()); - } } Index: JDBCVendorReliance.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/JDBCVendorReliance.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- JDBCVendorReliance.java 13 Mar 2006 06:02:11 -0000 1.7 +++ JDBCVendorReliance.java 13 Mar 2006 06:13:42 -0000 1.8 @@ -4,8 +4,6 @@ import java.util.Iterator; import java.util.Map; -import org.apache.bcel.classfile.LocalVariable; -import org.apache.bcel.classfile.LocalVariableTable; import org.apache.bcel.classfile.Method; import org.apache.bcel.generic.Type; Index: BloatedSynchronizedBlock.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedSynchronizedBlock.java,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- BloatedSynchronizedBlock.java 12 Mar 2006 06:27:17 -0000 1.18 +++ BloatedSynchronizedBlock.java 13 Mar 2006 06:13:42 -0000 1.19 @@ -26,6 +26,8 @@ import org.apache.bcel.classfile.Method; import org.apache.bcel.generic.Type; +import com.mebigfatguy.fbcontrib.utils.RegisterUtils; + import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; @@ -100,7 +102,7 @@ stack.mergeJumps(this); if (unsafeCallOccurred && ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3)))) { - int storeReg = astoreReg(seen); + int storeReg = RegisterUtils.getAStoreReg(this, seen); if (storeReg >= 0) unsafeAliases.add(new Integer(storeReg)); } @@ -150,7 +152,7 @@ boolean unsafe = unsafeCallOccurred; unsafe |= ((seen == PUTFIELD) || (seen == GETFIELD) || (seen == GETSTATIC) || (seen == PUTSTATIC)); unsafe |= (!isStatic) && ((seen == ALOAD_0) || (seen == ASTORE_0)); - int aloadReg = aloadReg(seen); + int aloadReg = RegisterUtils.getALoadReg(this, seen); unsafe |= (aloadReg >= 0) && unsafeAliases.contains(new Integer(aloadReg)); if (unsafe) { //If a branch exists in the safe code, make sure the entire branch @@ -180,34 +182,4 @@ stack.sawOpcode(this, seen); } } - - /** - * return the register number used in this ALOAD method, if it is an aload instruction - * - * @param seen the currently visited opcode - * - * @return the register used if it's an aload instruction, or -1 otherwise - */ - public int aloadReg(int seen) { - if (seen == ALOAD) - return getRegisterOperand(); - if ((seen >= ALOAD_0) && (seen <= ALOAD_3)) - return seen - ALOAD_0; - return -1; - } - - /** - * return the register number used in this ASTORE method, if it is an astore instruction - * - * @param seen the currently visited opcode - * - * @return the register used if it's an astore instruction, or -1 otherwise - */ - public int astoreReg(int seen) { - if (seen == ASTORE) - return getRegisterOperand(); - if ((seen >= ASTORE_0) && (seen <= ASTORE_3)) - return seen - ASTORE_0; - return -1; - } } Index: FinalParameters.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FinalParameters.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- FinalParameters.java 6 Feb 2006 01:36:23 -0000 1.12 +++ FinalParameters.java 13 Mar 2006 06:13:42 -0000 1.13 @@ -33,6 +33,8 @@ import org.apache.bcel.classfile.Method; import org.apache.bcel.generic.Type; +import com.mebigfatguy.fbcontrib.utils.RegisterUtils; + import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; @@ -256,11 +258,7 @@ * @return the register number being stored */ private int getAStoreParameter(final int seen) { - int reg; - if (seen == ASTORE) - reg = getRegisterOperand(); - else - reg = seen - ASTORE_0; + int reg = RegisterUtils.getAStoreReg(this, seen); if (!isStatic) reg--; |
From: Dave B. <dbr...@us...> - 2006-03-13 06:02:15
|
Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12759/src/com/mebigfatguy/fbcontrib/detect Modified Files: JDBCVendorReliance.java LocalSynchronizedCollection.java Log Message: more getLocalVariableEndRange to registerutils Index: JDBCVendorReliance.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/JDBCVendorReliance.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- JDBCVendorReliance.java 13 Mar 2006 05:57:54 -0000 1.6 +++ JDBCVendorReliance.java 13 Mar 2006 06:02:11 -0000 1.7 @@ -60,7 +60,7 @@ for (Type arg : argTypes) { String sig = arg.getSignature(); if (isJDBCClass(sig)) - jdbcLocals.put(new Integer(reg), new Integer(getLocalVariableEndRange(reg, 0))); + jdbcLocals.put(new Integer(reg), new Integer(RegisterUtils.getLocalVariableEndRange(obj.getLocalVariableTable(), reg, 0))); reg += (sig.equals("J") || sig.equals("D")) ? 2 : 1; } @@ -112,7 +112,7 @@ OpcodeStack.Item itm = stack.getStackItem(0); if (itm.getUserValue() != null) { int reg = RegisterUtils.getAStoreReg(this, seen); - jdbcLocals.put(new Integer(reg), new Integer(getLocalVariableEndRange(reg, getNextPC()))); + jdbcLocals.put(new Integer(reg), new Integer(RegisterUtils.getLocalVariableEndRange(getMethod().getLocalVariableTable(), reg, getNextPC()))); } } @@ -131,25 +131,7 @@ } } } - - /** - * returns the end pc of the visible range of this register at this pc - * - * @param reg the register to examine - * @param curPC the pc of the current instruction - * @return the endpc - */ - private int getLocalVariableEndRange(int reg, int curPC) { - int endRange = Integer.MAX_VALUE; - LocalVariableTable lvt = this.getMethod().getLocalVariableTable(); - if (lvt != null) { - LocalVariable lv = lvt.getLocalVariable(reg, curPC); - if (lv != null) - endRange = lv.getStartPC() + lv.getLength(); - } - return endRange; - } - + /** * returns whether the class is a jdbc class * Index: LocalSynchronizedCollection.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LocalSynchronizedCollection.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- LocalSynchronizedCollection.java 13 Mar 2006 05:57:54 -0000 1.8 +++ LocalSynchronizedCollection.java 13 Mar 2006 06:02:11 -0000 1.9 @@ -94,7 +94,7 @@ int curReg = obj.isStatic() ? 0 : 1; for (Type t : argTypes) { sig = t.getSignature(); - syncRegs.put(new Integer(curReg), new CollectionRegInfo(getLocalVariableEndRange(curReg, 0))); + syncRegs.put(new Integer(curReg), new CollectionRegInfo(RegisterUtils.getLocalVariableEndRange(obj.getLocalVariableTable(), curReg, 0))); if ("J".equals(sig) || "D".equals(sig)) { curReg++; } @@ -168,14 +168,14 @@ int reg = RegisterUtils.getAStoreReg(this, seen); if (item.getUserValue() != null) { if (!syncRegs.containsKey(new Integer(reg))) { - CollectionRegInfo cri = new CollectionRegInfo(SourceLineAnnotation.fromVisitedInstruction(this), getLocalVariableEndRange(reg, getNextPC())); + CollectionRegInfo cri = new CollectionRegInfo(SourceLineAnnotation.fromVisitedInstruction(this), RegisterUtils.getLocalVariableEndRange(getMethod().getLocalVariableTable(), reg, getNextPC())); syncRegs.put(new Integer(reg), cri); } } else { CollectionRegInfo cri = syncRegs.get(new Integer(reg)); if (cri == null) { - cri = new CollectionRegInfo(getLocalVariableEndRange(reg, getNextPC())); + cri = new CollectionRegInfo(RegisterUtils.getLocalVariableEndRange(getMethod().getLocalVariableTable(), reg, getNextPC())); syncRegs.put(new Integer(reg), cri); } cri.setIgnore(); @@ -228,25 +228,7 @@ } } } - - /** - * returns the end pc of the visible range of this register at this pc - * - * @param reg the register to examine - * @param curPC the pc of the current instruction - * @return the endpc - */ - private int getLocalVariableEndRange(int reg, int curPC) { - int endRange = Integer.MAX_VALUE; - LocalVariableTable lvt = this.getMethod().getLocalVariableTable(); - if (lvt != null) { - LocalVariable lv = lvt.getLocalVariable(reg, curPC); - if (lv != null) - endRange = lv.getStartPC() + lv.getLength(); - } - return endRange; - } - + static class CollectionRegInfo { private SourceLineAnnotation slAnnotation; |
From: Dave B. <dbr...@us...> - 2006-03-13 06:02:15
|
Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/utils In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12759/src/com/mebigfatguy/fbcontrib/utils Modified Files: RegisterUtils.java Log Message: more getLocalVariableEndRange to registerutils Index: RegisterUtils.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/utils/RegisterUtils.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- RegisterUtils.java 13 Mar 2006 05:57:54 -0000 1.1 +++ RegisterUtils.java 13 Mar 2006 06:02:12 -0000 1.2 @@ -1,6 +1,8 @@ package com.mebigfatguy.fbcontrib.utils; import org.apache.bcel.Constants; +import org.apache.bcel.classfile.LocalVariable; +import org.apache.bcel.classfile.LocalVariableTable; import edu.umd.cs.findbugs.visitclass.DismantleBytecode; @@ -90,4 +92,22 @@ return seen - Constants.DLOAD_0; return seen - Constants.ALOAD_0; } + + /** + * returns the end pc of the visible range of this register at this pc + * + * @param lvt the local variable table for this method + * @param reg the register to examine + * @param curPC the pc of the current instruction + * @return the endpc + */ + public static int getLocalVariableEndRange(LocalVariableTable lvt, int reg, int curPC) { + int endRange = Integer.MAX_VALUE; + if (lvt != null) { + LocalVariable lv = lvt.getLocalVariable(reg, curPC); + if (lv != null) + endRange = lv.getStartPC() + lv.getLength(); + } + return endRange; + } } |
From: Dave B. <dbr...@us...> - 2006-03-13 05:57:57
|
Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10713/src/com/mebigfatguy/fbcontrib/detect Modified Files: ArrayWrappedCallByReference.java JDBCVendorReliance.java LocalSynchronizedCollection.java Log Message: Break out simple reg utilities Index: JDBCVendorReliance.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/JDBCVendorReliance.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- JDBCVendorReliance.java 13 Mar 2006 05:43:46 -0000 1.5 +++ JDBCVendorReliance.java 13 Mar 2006 05:57:54 -0000 1.6 @@ -9,6 +9,8 @@ import org.apache.bcel.classfile.Method; import org.apache.bcel.generic.Type; +import com.mebigfatguy.fbcontrib.utils.RegisterUtils; + import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; @@ -109,13 +111,13 @@ if (stack.getStackDepth() > 0) { OpcodeStack.Item itm = stack.getStackItem(0); if (itm.getUserValue() != null) { - int reg = getAStoreReg(seen); + int reg = RegisterUtils.getAStoreReg(this, seen); jdbcLocals.put(new Integer(reg), new Integer(getLocalVariableEndRange(reg, getNextPC()))); } } } else if ((seen == ALOAD) || ((seen >= ALOAD_0) && (seen <= ALOAD_3))) { - int reg = getALoadReg(seen); + int reg = RegisterUtils.getALoadReg(this, seen); if (jdbcLocals.containsKey(new Integer(reg))) tosIsJDBC = true; } @@ -129,31 +131,7 @@ } } } - - /** - * returns the register used to store a reference - * - * @param seen the opcode of the store - * @return the register stored into - */ - private int getAStoreReg(int seen) { - if (seen == ASTORE) - return getRegisterOperand(); - return seen - ASTORE_0; - } - - /** - * returns the register used to load a reference - * - * @param seen the opcode of the load - * @return the register loaded from - */ - private int getALoadReg(int seen) { - if (seen == ALOAD) - return getRegisterOperand(); - return seen - ALOAD_0; - } - + /** * returns the end pc of the visible range of this register at this pc * Index: ArrayWrappedCallByReference.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ArrayWrappedCallByReference.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- ArrayWrappedCallByReference.java 12 Mar 2006 06:27:17 -0000 1.6 +++ ArrayWrappedCallByReference.java 13 Mar 2006 05:57:54 -0000 1.7 @@ -24,6 +24,8 @@ import org.apache.bcel.classfile.Code; import org.apache.bcel.generic.Type; +import com.mebigfatguy.fbcontrib.utils.RegisterUtils; + import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; @@ -122,14 +124,14 @@ OpcodeStack.Item itm = stack.getStackItem(0); String sig = itm.getSignature(); if ((sig.length() > 0) && (itm.getSignature().charAt(0) == '[')) { - int reg = getAStoreReg(seen); + int reg = RegisterUtils.getAStoreReg(this, seen); Integer elReg = (Integer)itm.getUserValue(); if (elReg != null) wrappers.put(new Integer(reg), new WrapperInfo(elReg.intValue())); } else { Integer elReg = (Integer)itm.getUserValue(); if (elReg != null) { - int reg = getAStoreReg(seen); + int reg = RegisterUtils.getAStoreReg(this, seen); if (elReg.intValue() == reg) { bugReporter.reportBug(new BugInstance(this, "AWCBR_ARRAY_WRAPPED_CALL_BY_REFERENCE", NORMAL_PRIORITY ) .addClass(this) @@ -168,7 +170,7 @@ } } } else if ((seen == ALOAD) || ((seen >= ALOAD_0) && (seen <= ALOAD_3))) { - int reg = getALoadReg(seen); + int reg = RegisterUtils.getALoadReg(this, seen); WrapperInfo wi = wrappers.get(new Integer(reg)); if (wi != null) userValue = new Integer(wi.wrappedReg); @@ -180,7 +182,7 @@ OpcodeStack.Item itm = stack.getStackItem(0); Integer elReg = (Integer)itm.getUserValue(); if (elReg != null) { - int reg = getStoreReg(seen); + int reg = RegisterUtils.getStoreReg(this, seen); if (elReg.intValue() == reg) { bugReporter.reportBug(new BugInstance(this, "AWCBR_ARRAY_WRAPPED_CALL_BY_REFERENCE", NORMAL_PRIORITY ) .addClass(this) @@ -199,31 +201,5 @@ } } } - } - - private int getAStoreReg(int seen) { - if (seen == ASTORE) - return getRegisterOperand(); - return seen - ASTORE_0; - } - - private int getALoadReg(int seen) { - if (seen == ALOAD) - return getRegisterOperand(); - return seen - ALOAD_0; - } - - private int getStoreReg(int seen) { - if ((seen == ASTORE) || (seen == ISTORE) || (seen == LSTORE) || (seen == FSTORE) || (seen == DSTORE)) - return getRegisterOperand(); - if (seen <= ISTORE_3) - return seen - ISTORE_0; - else if (seen <= LSTORE_3) - return seen - LSTORE_0; - else if (seen <= FSTORE_3) - return seen - FSTORE_0; - else if (seen <= DSTORE_3) - return seen - DSTORE_0; - return seen - ASTORE_0; } } Index: LocalSynchronizedCollection.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LocalSynchronizedCollection.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- LocalSynchronizedCollection.java 13 Mar 2006 05:44:45 -0000 1.7 +++ LocalSynchronizedCollection.java 13 Mar 2006 05:57:54 -0000 1.8 @@ -30,6 +30,8 @@ import org.apache.bcel.classfile.Method; import org.apache.bcel.generic.Type; +import com.mebigfatguy.fbcontrib.utils.RegisterUtils; + import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; @@ -163,7 +165,7 @@ } else if ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3))) { if (stack.getStackDepth() > 0) { OpcodeStack.Item item = stack.getStackItem(0); - int reg = getAStoreReg(seen); + int reg = RegisterUtils.getAStoreReg(this, seen); if (item.getUserValue() != null) { if (!syncRegs.containsKey(new Integer(reg))) { CollectionRegInfo cri = new CollectionRegInfo(SourceLineAnnotation.fromVisitedInstruction(this), getLocalVariableEndRange(reg, getNextPC())); @@ -180,7 +182,7 @@ } } } else if ((seen == ALOAD) || ((seen >= ALOAD_0) && (seen <= ALOAD_3))) { - int reg = getALoadReg(seen); + int reg = RegisterUtils.getALoadReg(this, seen); CollectionRegInfo cri = syncRegs.get(new Integer(reg)); if ((cri != null) && !cri.getIgnore()) tosIsSyncColReg = new Integer(reg); @@ -226,30 +228,6 @@ } } } - - /** - * returns the register used to store a reference - * - * @param seen the opcode of the store - * @return the register stored into - */ - private int getAStoreReg(int seen) { - if (seen == ASTORE) - return getRegisterOperand(); - return seen - ASTORE_0; - } - - /** - * returns the register used to load a reference - * - * @param seen the opcode of the load - * @return the register loaded from - */ - private int getALoadReg(int seen) { - if (seen == ALOAD) - return getRegisterOperand(); - return seen - ALOAD_0; - } /** * returns the end pc of the visible range of this register at this pc |
From: Dave B. <dbr...@us...> - 2006-03-13 05:57:57
|
Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/utils In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10713/src/com/mebigfatguy/fbcontrib/utils Added Files: RegisterUtils.java Log Message: Break out simple reg utilities --- NEW FILE: RegisterUtils.java --- package com.mebigfatguy.fbcontrib.utils; import org.apache.bcel.Constants; import edu.umd.cs.findbugs.visitclass.DismantleBytecode; /** * a auxillary class for managing and manipulating registers */ public class RegisterUtils { /** * private to reinforce the helper status of the class */ private RegisterUtils() { } /** * returns the register used to store a reference * * @param dbc the dismantle byte code parsing the class * @param seen the opcode of the store * @return the register stored into */ public static int getAStoreReg(DismantleBytecode dbc, int seen) { if (seen == Constants.ASTORE) return dbc.getRegisterOperand(); return seen - Constants.ASTORE_0; } /** * returns the register used to load a reference * * @param dbc the dismantle byte code parsing the class * @param seen the opcode of the load * @return the register loaded from */ public static int getALoadReg(DismantleBytecode dbc, int seen) { if (seen == Constants.ALOAD) return dbc.getRegisterOperand(); return seen - Constants.ALOAD_0; } /** * returns the register used in a store operation * * @param dbc the dismantle byte code parsing the class * @param seen the opcode of the store * @return the register stored into */ public static int getStoreReg(DismantleBytecode dbc, int seen) { if ((seen == Constants.ASTORE) || (seen == Constants.ISTORE) || (seen == Constants.LSTORE) || (seen == Constants.FSTORE) || (seen == Constants.DSTORE)) return dbc.getRegisterOperand(); if (seen <= Constants.ISTORE_3) return seen - Constants.ISTORE_0; else if (seen <= Constants.LSTORE_3) return seen - Constants.LSTORE_0; else if (seen <= Constants.FSTORE_3) return seen - Constants.FSTORE_0; else if (seen <= Constants.DSTORE_3) return seen - Constants.DSTORE_0; return seen - Constants.ASTORE_0; } /** * returns the register used in a load operation * * @param dbc the dismantle byte code parsing the class * @param seen the opcode of the load * @return the register stored into */ public static int getLoadReg(DismantleBytecode dbc, int seen) { if ((seen == Constants.ALOAD) || (seen == Constants.ILOAD) || (seen == Constants.LLOAD) || (seen == Constants.FLOAD) || (seen == Constants.DLOAD)) return dbc.getRegisterOperand(); if (seen <= Constants.ILOAD_3) return seen - Constants.ILOAD_0; else if (seen <= Constants.LLOAD_3) return seen - Constants.LLOAD_0; else if (seen <= Constants.FLOAD_3) return seen - Constants.FLOAD_0; else if (seen <= Constants.DLOAD_3) return seen - Constants.DLOAD_0; return seen - Constants.ALOAD_0; } } |
From: Dave B. <dbr...@us...> - 2006-03-13 05:57:22
|
Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/utils In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10533/utils Log Message: Directory /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/utils added to the repository |
From: Dave B. <dbr...@us...> - 2006-03-13 05:44:49
|
Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4186/src/com/mebigfatguy/fbcontrib/detect Modified Files: LocalSynchronizedCollection.java Log Message: honor variable ranges, and don't report collections that are assigned to from other unknown sources. Index: LocalSynchronizedCollection.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LocalSynchronizedCollection.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- LocalSynchronizedCollection.java 12 Mar 2006 15:19:07 -0000 1.6 +++ LocalSynchronizedCollection.java 13 Mar 2006 05:44:45 -0000 1.7 @@ -20,10 +20,14 @@ import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.Map; import java.util.Set; import org.apache.bcel.classfile.Code; +import org.apache.bcel.classfile.LocalVariable; +import org.apache.bcel.classfile.LocalVariableTable; +import org.apache.bcel.classfile.Method; import org.apache.bcel.generic.Type; import edu.umd.cs.findbugs.BugInstance; @@ -39,191 +43,275 @@ * thread safe, using synchronized collections in this context makes no sense. */ public class LocalSynchronizedCollection extends BytecodeScanningDetector implements StatelessDetector { - private static Set<String> syncCtors = new HashSet<String>(); - static { - syncCtors.add("java/util/Vector"); - syncCtors.add("java/util/Hashtable"); - } - private static Set<String> syncMethods = new HashSet<String>(); - static { - syncMethods.add("synchronizedCollection"); - syncMethods.add("synchronizedList"); - syncMethods.add("synchronizedMap"); - syncMethods.add("synchronizedSet"); - syncMethods.add("synchronizedSortedMap"); - syncMethods.add("synchronizedSortedSet"); - } - - private BugReporter bugReporter; - private OpcodeStack stack = new OpcodeStack(); - private Map<Integer, CollectionRegInfo> syncRegs = new HashMap<Integer, CollectionRegInfo>(); - - /** + private static Set<String> syncCtors = new HashSet<String>(); + static { + syncCtors.add("java/util/Vector"); + syncCtors.add("java/util/Hashtable"); + } + private static Set<String> syncMethods = new HashSet<String>(); + static { + syncMethods.add("synchronizedCollection"); + syncMethods.add("synchronizedList"); + syncMethods.add("synchronizedMap"); + syncMethods.add("synchronizedSet"); + syncMethods.add("synchronizedSortedMap"); + syncMethods.add("synchronizedSortedSet"); + } + + private BugReporter bugReporter; + private OpcodeStack stack = new OpcodeStack(); + private Map<Integer, CollectionRegInfo> syncRegs = new HashMap<Integer, CollectionRegInfo>(); + /** * constructs a LSYC detector given the reporter to report bugs on * @param bugReporter the sync of bug reports - */ - public LocalSynchronizedCollection(BugReporter bugReporter) { - this.bugReporter = bugReporter; - } - - /** - * clone this detector so that it can be a StatelessDetector - * - * @return a clone of this object - */ - @Override - public Object clone() throws CloneNotSupportedException { - return super.clone(); - } - - /** - * implements the visitor to reset the stack - * - * @param obj the context object of the currently parsed code block - */ - @Override - public void visitCode(Code obj) { - stack.resetForMethodEntry(this); - syncRegs.clear(); - super.visitCode(obj); - - for (Map.Entry<Integer, CollectionRegInfo> entry : syncRegs.entrySet()) { - CollectionRegInfo cri = entry.getValue(); - bugReporter.reportBug(new BugInstance(this, "LSYC_LOCAL_SYNCHRONIZED_COLLECTION", cri.getPriority()) - .addClass(this) - .addMethod(this) - .addSourceLine(cri.getSourceLineAnnotation())); - - } - } - - /** - * implements the visitor to find stores to locals of synchronized collections - * - * @param seen the opcode of the currently parsed instruction - */ - @Override - public void sawOpcode(int seen) { - //TODO: Keep track of local variable scope - //TODO: If a store into a variable, other than above, remove from consideration - Integer tosIsSyncColReg = null; - try { - stack.mergeJumps(this); - - if (seen == INVOKESPECIAL) { - if ("<init>".equals(getNameConstantOperand())) { - if (syncCtors.contains(getClassConstantOperand())) { - tosIsSyncColReg = new Integer(-1); - } - } - } else if (seen == INVOKESTATIC) { - if ("java/util/Collections".equals(getClassConstantOperand())) { - if (syncMethods.contains(getNameConstantOperand())) { - tosIsSyncColReg = new Integer(-1); - } - } - } else if ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3))) { - if (stack.getStackDepth() > 0) { - OpcodeStack.Item item = stack.getStackItem(0); - if (item.getUserValue() != null) { - int reg = getAStoreReg(seen); - if (!syncRegs.containsKey(new Integer(reg))) { - CollectionRegInfo cri = new CollectionRegInfo(SourceLineAnnotation.fromVisitedInstruction(this)); - syncRegs.put(new Integer(reg), cri); - - } - } - } - } else if ((seen == ALOAD) || ((seen >= ALOAD_0) && (seen <= ALOAD_3))) { - int reg = getALoadReg(seen); - if (syncRegs.containsKey(new Integer(reg))) - tosIsSyncColReg = new Integer(reg); - } else if ((seen == PUTFIELD) || (seen == ARETURN)) { - if (stack.getStackDepth() > 0) { - OpcodeStack.Item item = stack.getStackItem(0); - syncRegs.remove(item.getUserValue()); - } - } - - if (syncRegs.size() > 0) { - if ((seen == INVOKESPECIAL) - || (seen == INVOKEINTERFACE) - || (seen == INVOKEVIRTUAL) - || (seen == INVOKESTATIC)) { - String sig = getSigConstantOperand(); - int argCount = Type.getArgumentTypes(sig).length; - if (stack.getStackDepth() >= argCount) { - for (int i = 0; i < argCount; i++) { - OpcodeStack.Item item = stack.getStackItem(i); - CollectionRegInfo cri = syncRegs.get(item.getUserValue()); - if (cri != null) - cri.setPriority(LOW_PRIORITY); - } - } - } else if (seen == MONITORENTER) { - //Assume if synchronized blocks are used then something tricky is going on. - //There is really no valid reason for this, other than folks who use - //synchronized blocks tend to know what's going on. - if (stack.getStackDepth() > 0) { - OpcodeStack.Item item = stack.getStackItem(0); - syncRegs.remove(item.getUserValue()); - } - } - } - } finally { - stack.sawOpcode(this, seen); - if (tosIsSyncColReg != null) { - if (stack.getStackDepth() > 0) { - OpcodeStack.Item item = stack.getStackItem(0); - item.setUserValue(tosIsSyncColReg); - } - } - } - } + */ + public LocalSynchronizedCollection(BugReporter bugReporter) { + this.bugReporter = bugReporter; + } + + /** + * clone this detector so that it can be a StatelessDetector + * + * @return a clone of this object + */ + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + /** + * implements the visitor to collect parameter registers + * + * @param obj the context object of the currently parsed method + */ + @Override + public void visitMethod(Method obj) { + syncRegs.clear(); + String sig = obj.getSignature(); + Type[] argTypes = Type.getArgumentTypes(sig); + int curReg = obj.isStatic() ? 0 : 1; + for (Type t : argTypes) { + sig = t.getSignature(); + syncRegs.put(new Integer(curReg), new CollectionRegInfo(getLocalVariableEndRange(curReg, 0))); + if ("J".equals(sig) || "D".equals(sig)) { + curReg++; + } + curReg++; + } + } + + /** + * implements the visitor to reset the stack + * + * @param obj the context object of the currently parsed code block + */ + @Override + public void visitCode(Code obj) { + stack.resetForMethodEntry(this); + super.visitCode(obj); + + for (Map.Entry<Integer, CollectionRegInfo> entry : syncRegs.entrySet()) { + CollectionRegInfo cri = entry.getValue(); + if (!cri.getIgnore()) { + bugReporter.reportBug(new BugInstance(this, "LSYC_LOCAL_SYNCHRONIZED_COLLECTION", cri.getPriority()) + .addClass(this) + .addMethod(this) + .addSourceLine(cri.getSourceLineAnnotation())); + } + + } + } + + /** + * implements the visitor to find stores to locals of synchronized collections + * + * @param seen the opcode of the currently parsed instruction + */ + @Override + public void sawOpcode(int seen) { + Integer tosIsSyncColReg = null; + try { + stack.mergeJumps(this); + + int curPC = getPC(); + Iterator<CollectionRegInfo> it = syncRegs.values().iterator(); + while (it.hasNext()) { + CollectionRegInfo cri = it.next(); + if (cri.getEndPCRange() < curPC) { + if (!cri.getIgnore()) { + bugReporter.reportBug(new BugInstance(this, "LSYC_LOCAL_SYNCHRONIZED_COLLECTION", cri.getPriority()) + .addClass(this) + .addMethod(this) + .addSourceLine(cri.getSourceLineAnnotation())); + } + it.remove(); + } + } + + if (seen == INVOKESPECIAL) { + if ("<init>".equals(getNameConstantOperand())) { + if (syncCtors.contains(getClassConstantOperand())) { + tosIsSyncColReg = new Integer(-1); + } + } + } else if (seen == INVOKESTATIC) { + if ("java/util/Collections".equals(getClassConstantOperand())) { + if (syncMethods.contains(getNameConstantOperand())) { + tosIsSyncColReg = new Integer(-1); + } + } + } else if ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3))) { + if (stack.getStackDepth() > 0) { + OpcodeStack.Item item = stack.getStackItem(0); + int reg = getAStoreReg(seen); + if (item.getUserValue() != null) { + if (!syncRegs.containsKey(new Integer(reg))) { + CollectionRegInfo cri = new CollectionRegInfo(SourceLineAnnotation.fromVisitedInstruction(this), getLocalVariableEndRange(reg, getNextPC())); + syncRegs.put(new Integer(reg), cri); + + } + } else { + CollectionRegInfo cri = syncRegs.get(new Integer(reg)); + if (cri == null) { + cri = new CollectionRegInfo(getLocalVariableEndRange(reg, getNextPC())); + syncRegs.put(new Integer(reg), cri); + } + cri.setIgnore(); + } + } + } else if ((seen == ALOAD) || ((seen >= ALOAD_0) && (seen <= ALOAD_3))) { + int reg = getALoadReg(seen); + CollectionRegInfo cri = syncRegs.get(new Integer(reg)); + if ((cri != null) && !cri.getIgnore()) + tosIsSyncColReg = new Integer(reg); + } else if ((seen == PUTFIELD) || (seen == ARETURN)) { + if (stack.getStackDepth() > 0) { + OpcodeStack.Item item = stack.getStackItem(0); + syncRegs.remove(item.getUserValue()); + } + } + + if (syncRegs.size() > 0) { + if ((seen == INVOKESPECIAL) + || (seen == INVOKEINTERFACE) + || (seen == INVOKEVIRTUAL) + || (seen == INVOKESTATIC)) { + String sig = getSigConstantOperand(); + int argCount = Type.getArgumentTypes(sig).length; + if (stack.getStackDepth() >= argCount) { + for (int i = 0; i < argCount; i++) { + OpcodeStack.Item item = stack.getStackItem(i); + CollectionRegInfo cri = syncRegs.get(item.getUserValue()); + if (cri != null) + cri.setPriority(LOW_PRIORITY); + } + } + } else if (seen == MONITORENTER) { + //Assume if synchronized blocks are used then something tricky is going on. + //There is really no valid reason for this, other than folks who use + //synchronized blocks tend to know what's going on. + if (stack.getStackDepth() > 0) { + OpcodeStack.Item item = stack.getStackItem(0); + syncRegs.remove(item.getUserValue()); + } + } + } + } finally { + stack.sawOpcode(this, seen); + if (tosIsSyncColReg != null) { + if (stack.getStackDepth() > 0) { + OpcodeStack.Item item = stack.getStackItem(0); + item.setUserValue(tosIsSyncColReg); + } + } + } + } - /** - * returns the register used to store a reference - * - * @param seen the opcode of the store - * @return the register stored into - */ - private int getAStoreReg(int seen) { - if (seen == ASTORE) - return getRegisterOperand(); - return seen - ASTORE_0; - } - - /** - * returns the register used to load a reference - * - * @param seen the opcode of the load - * @return the register loaded from - */ - private int getALoadReg(int seen) { - if (seen == ALOAD) - return getRegisterOperand(); - return seen - ALOAD_0; - } - - static class CollectionRegInfo - { - private SourceLineAnnotation slAnnotation; - private int priority = HIGH_PRIORITY; - - public CollectionRegInfo(SourceLineAnnotation sla) { - slAnnotation = sla; - } - public SourceLineAnnotation getSourceLineAnnotation() { - return slAnnotation; - } - - public void setPriority(int newPriority) { - if (newPriority > priority) - priority = newPriority; - } - - public int getPriority() { - return priority; - } - } + /** + * returns the register used to store a reference + * + * @param seen the opcode of the store + * @return the register stored into + */ + private int getAStoreReg(int seen) { + if (seen == ASTORE) + return getRegisterOperand(); + return seen - ASTORE_0; + } + + /** + * returns the register used to load a reference + * + * @param seen the opcode of the load + * @return the register loaded from + */ + private int getALoadReg(int seen) { + if (seen == ALOAD) + return getRegisterOperand(); + return seen - ALOAD_0; + } + + /** + * returns the end pc of the visible range of this register at this pc + * + * @param reg the register to examine + * @param curPC the pc of the current instruction + * @return the endpc + */ + private int getLocalVariableEndRange(int reg, int curPC) { + int endRange = Integer.MAX_VALUE; + LocalVariableTable lvt = this.getMethod().getLocalVariableTable(); + if (lvt != null) { + LocalVariable lv = lvt.getLocalVariable(reg, curPC); + if (lv != null) + endRange = lv.getStartPC() + lv.getLength(); + } + return endRange; + } + + static class CollectionRegInfo + { + private SourceLineAnnotation slAnnotation; + private int priority = HIGH_PRIORITY; + private int endPCRange = Integer.MAX_VALUE; + + public CollectionRegInfo(SourceLineAnnotation sla, int endPC) { + slAnnotation = sla; + endPCRange = endPC; + } + + public CollectionRegInfo(int endPC) { + slAnnotation = null; + endPCRange = endPC; + } + + public SourceLineAnnotation getSourceLineAnnotation() { + return slAnnotation; + } + + public void setEndPCRange(int pc) { + endPCRange = pc; + } + + public int getEndPCRange() { + return endPCRange; + } + + public void setIgnore() { + slAnnotation = null; + } + + public boolean getIgnore() { + return slAnnotation == null; + } + + public void setPriority(int newPriority) { + if (newPriority > priority) + priority = newPriority; + } + + public int getPriority() { + return priority; + } + } } |
From: Dave B. <dbr...@us...> - 2006-03-13 05:43:50
|
Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3586/src/com/mebigfatguy/fbcontrib/detect Modified Files: JDBCVendorReliance.java Log Message: LONG is "J" not "L" Index: JDBCVendorReliance.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/JDBCVendorReliance.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- JDBCVendorReliance.java 12 Mar 2006 06:27:17 -0000 1.4 +++ JDBCVendorReliance.java 13 Mar 2006 05:43:46 -0000 1.5 @@ -60,7 +60,7 @@ if (isJDBCClass(sig)) jdbcLocals.put(new Integer(reg), new Integer(getLocalVariableEndRange(reg, 0))); - reg += (sig.equals("L") || sig.equals("D")) ? 2 : 1; + reg += (sig.equals("J") || sig.equals("D")) ? 2 : 1; } } |
From: Dave B. <dbr...@us...> - 2006-03-12 15:19:13
|
Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9523/src/com/mebigfatguy/fbcontrib/detect Modified Files: LocalSynchronizedCollection.java Log Message: doc some work todo Index: LocalSynchronizedCollection.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LocalSynchronizedCollection.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- LocalSynchronizedCollection.java 12 Mar 2006 06:27:17 -0000 1.5 +++ LocalSynchronizedCollection.java 12 Mar 2006 15:19:07 -0000 1.6 @@ -104,6 +104,8 @@ */ @Override public void sawOpcode(int seen) { + //TODO: Keep track of local variable scope + //TODO: If a store into a variable, other than above, remove from consideration Integer tosIsSyncColReg = null; try { stack.mergeJumps(this); |
From: Dave B. <dbr...@us...> - 2006-03-12 06:27:21
|
Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11942/src/com/mebigfatguy/fbcontrib/detect Modified Files: ArrayWrappedCallByReference.java BloatedSynchronizedBlock.java ClassEnvy.java ConstantListIndex.java CustomBuiltXML.java JDBCVendorReliance.java LocalSynchronizedCollection.java OrphanedDOMNode.java OverlyConcreteParameter.java SloppyClassReflection.java UnrelatedCollectionContents.java Log Message: simple cleanups Index: SloppyClassReflection.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SloppyClassReflection.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- SloppyClassReflection.java 12 Mar 2006 02:55:34 -0000 1.5 +++ SloppyClassReflection.java 12 Mar 2006 06:27:17 -0000 1.6 @@ -103,8 +103,7 @@ if (lvt != null) { LocalVariable[] lvs = lvt.getLocalVariableTable(); if (lvs != null) { - for (int l = 0; l < lvs.length; l++) { - LocalVariable lv = lvs[l]; + for (LocalVariable lv : lvs) { if (lv != null) { Type t = Type.getType(lv.getSignature()); addType(t); Index: BloatedSynchronizedBlock.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedSynchronizedBlock.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- BloatedSynchronizedBlock.java 1 Mar 2006 04:52:03 -0000 1.17 +++ BloatedSynchronizedBlock.java 12 Mar 2006 06:27:17 -0000 1.18 @@ -114,7 +114,7 @@ int parmCount = Type.getArgumentTypes(methodSig).length; if (stack.getStackDepth() > parmCount) { OpcodeStack.Item itm = stack.getStackItem(parmCount); - unsafeCallOccurred = unsafeAliases.contains(itm.getRegisterNumber()); + unsafeCallOccurred = unsafeAliases.contains(new Integer(itm.getRegisterNumber())); } else unsafeCallOccurred = false; } else Index: UnrelatedCollectionContents.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedCollectionContents.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- UnrelatedCollectionContents.java 1 Mar 2006 05:09:01 -0000 1.14 +++ UnrelatedCollectionContents.java 12 Mar 2006 06:27:17 -0000 1.15 @@ -105,7 +105,7 @@ try { stack.mergeJumps(this); - Set<Integer> regs = localScopeEnds.remove(getPC()); + Set<Integer> regs = localScopeEnds.remove(new Integer(getPC())); if (regs != null) { for (Integer i : regs) { localCollections.remove(i); @@ -170,7 +170,7 @@ regs = new HashSet<Integer>(); localScopeEnds.put(scopeEnd, regs); } - regs.add(reg); + regs.add(new Integer(reg)); } } } else { Index: CustomBuiltXML.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CustomBuiltXML.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- CustomBuiltXML.java 6 Feb 2006 01:36:22 -0000 1.8 +++ CustomBuiltXML.java 12 Mar 2006 06:27:17 -0000 1.9 @@ -70,7 +70,7 @@ public CustomBuiltXML(BugReporter bugReporter) { this.bugReporter = bugReporter; - lowReportingThreshold = Integer.getInteger(CBX_MIN_REPORTABLE_ITEMS, 5); + lowReportingThreshold = Integer.getInteger(CBX_MIN_REPORTABLE_ITEMS, 5).intValue(); midReportingThreshold = lowReportingThreshold << 1; highReportingThreshold = lowReportingThreshold << 2; } Index: ConstantListIndex.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConstantListIndex.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- ConstantListIndex.java 6 Feb 2006 01:36:22 -0000 1.8 +++ ConstantListIndex.java 12 Mar 2006 06:27:17 -0000 1.9 @@ -54,7 +54,7 @@ */ public ConstantListIndex(BugReporter bugReporter) { this.bugReporter = bugReporter; - max_iConst0LoopDistance = Integer.getInteger(MAX_ICONST0_LOOP_DISTANCE_PROPERTY, 30); + max_iConst0LoopDistance = Integer.getInteger(MAX_ICONST0_LOOP_DISTANCE_PROPERTY, 30).intValue(); } /** Index: ClassEnvy.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ClassEnvy.java,v retrieving revision 1.20 retrieving revision 1.21 diff -u -d -r1.20 -r1.21 --- ClassEnvy.java 1 Mar 2006 05:09:01 -0000 1.20 +++ ClassEnvy.java 12 Mar 2006 06:27:17 -0000 1.21 @@ -74,7 +74,7 @@ String percent = System.getProperty(ENVY_PERCENT_PROPERTY); if (percent != null) { try { - envyPercent = Double.valueOf(percent); + envyPercent = Double.valueOf(percent).doubleValue(); } catch (NumberFormatException nfe) { //Stick with original } Index: JDBCVendorReliance.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/JDBCVendorReliance.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- JDBCVendorReliance.java 7 Mar 2006 04:58:42 -0000 1.3 +++ JDBCVendorReliance.java 12 Mar 2006 06:27:17 -0000 1.4 @@ -175,7 +175,7 @@ /** * returns whether the class is a jdbc class * - * @param a class name or signature of a class + * @param clsName class name or signature of a class * * @return if the class name is a jdbc one */ Index: ArrayWrappedCallByReference.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ArrayWrappedCallByReference.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- ArrayWrappedCallByReference.java 6 Feb 2006 01:36:22 -0000 1.5 +++ ArrayWrappedCallByReference.java 12 Mar 2006 06:27:17 -0000 1.6 @@ -125,7 +125,7 @@ int reg = getAStoreReg(seen); Integer elReg = (Integer)itm.getUserValue(); if (elReg != null) - wrappers.put(new Integer(reg), new WrapperInfo(elReg)); + wrappers.put(new Integer(reg), new WrapperInfo(elReg.intValue())); } else { Integer elReg = (Integer)itm.getUserValue(); if (elReg != null) { @@ -164,7 +164,7 @@ int arReg = arItm.getRegisterNumber(); WrapperInfo wi = wrappers.get(new Integer(arReg)); if ((wi != null) && wi.wasArg) { - userValue = wi.wrappedReg; + userValue = new Integer(wi.wrappedReg); } } } else if ((seen == ALOAD) || ((seen >= ALOAD_0) && (seen <= ALOAD_3))) { Index: LocalSynchronizedCollection.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LocalSynchronizedCollection.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- LocalSynchronizedCollection.java 12 Mar 2006 04:14:53 -0000 1.4 +++ LocalSynchronizedCollection.java 12 Mar 2006 06:27:17 -0000 1.5 @@ -125,7 +125,7 @@ OpcodeStack.Item item = stack.getStackItem(0); if (item.getUserValue() != null) { int reg = getAStoreReg(seen); - if (!syncRegs.containsKey(reg)) { + if (!syncRegs.containsKey(new Integer(reg))) { CollectionRegInfo cri = new CollectionRegInfo(SourceLineAnnotation.fromVisitedInstruction(this)); syncRegs.put(new Integer(reg), cri); @@ -139,7 +139,7 @@ } else if ((seen == PUTFIELD) || (seen == ARETURN)) { if (stack.getStackDepth() > 0) { OpcodeStack.Item item = stack.getStackItem(0); - syncRegs.remove((Integer)item.getUserValue()); + syncRegs.remove(item.getUserValue()); } } Index: OverlyConcreteParameter.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java,v retrieving revision 1.28 retrieving revision 1.29 diff -u -d -r1.28 -r1.29 --- OverlyConcreteParameter.java 6 Feb 2006 01:36:23 -0000 1.28 +++ OverlyConcreteParameter.java 12 Mar 2006 06:27:17 -0000 1.29 @@ -193,7 +193,7 @@ if (!methodIsStatic) parm--; if ((parm >= 0) && (parm < parmCount)) - parameterDefiners.remove(reg); + parameterDefiners.remove(new Integer(reg)); } else { parameterDefiners.clear(); } @@ -206,7 +206,7 @@ if (!methodIsStatic) parm--; if ((parm >= 0) && (parm < parmCount)) - parameterDefiners.remove(reg); + parameterDefiners.remove(new Integer(reg)); } else { parameterDefiners.clear(); } @@ -333,9 +333,9 @@ while (it.hasNext()) { boolean methodDefined = false; List<String> methodSigs = it.next(); - Iterator<String> mit = methodSigs.iterator(); - while (mit.hasNext()) { - if (methodInfo.equals(mit.next())) { + + for (String mi : methodSigs) { + if (methodInfo.equals(mi)) { methodDefined = true; break; } Index: OrphanedDOMNode.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OrphanedDOMNode.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- OrphanedDOMNode.java 6 Feb 2006 01:36:23 -0000 1.6 +++ OrphanedDOMNode.java 12 Mar 2006 06:27:17 -0000 1.7 @@ -174,7 +174,7 @@ if (nodeCreations.containsKey(itm)) { int reg = itm.getRegisterNumber(); nodeCreations.remove(itm); - nodeStores.remove(reg); + nodeStores.remove(new Integer(reg)); } } } |
From: Dave B. <dbr...@us...> - 2006-03-12 04:14:58
|
Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7744/src/com/mebigfatguy/fbcontrib/detect Modified Files: LocalSynchronizedCollection.java Log Message: don't report on locals if they synchronized on. Index: LocalSynchronizedCollection.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LocalSynchronizedCollection.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- LocalSynchronizedCollection.java 11 Mar 2006 15:15:19 -0000 1.3 +++ LocalSynchronizedCollection.java 12 Mar 2006 04:14:53 -0000 1.4 @@ -158,6 +158,14 @@ cri.setPriority(LOW_PRIORITY); } } + } else if (seen == MONITORENTER) { + //Assume if synchronized blocks are used then something tricky is going on. + //There is really no valid reason for this, other than folks who use + //synchronized blocks tend to know what's going on. + if (stack.getStackDepth() > 0) { + OpcodeStack.Item item = stack.getStackItem(0); + syncRegs.remove(item.getUserValue()); + } } } } finally { |
From: Dave B. <dbr...@us...> - 2006-03-12 02:55:37
|
Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31674/src/com/mebigfatguy/fbcontrib/detect Modified Files: SloppyClassReflection.java Log Message: don't use deprecated apis, they are that way for a reason. Index: SloppyClassReflection.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SloppyClassReflection.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- SloppyClassReflection.java 1 Mar 2006 05:09:01 -0000 1.4 +++ SloppyClassReflection.java 12 Mar 2006 02:55:34 -0000 1.5 @@ -101,11 +101,14 @@ addType(resultType); LocalVariableTable lvt = obj.getLocalVariableTable(); if (lvt != null) { - for (int l = 0; l < lvt.getLength(); l++) { - LocalVariable lv = lvt.getLocalVariable(l); - if (lv != null) { - Type t = Type.getType(lv.getSignature()); - addType(t); + LocalVariable[] lvs = lvt.getLocalVariableTable(); + if (lvs != null) { + for (int l = 0; l < lvs.length; l++) { + LocalVariable lv = lvs[l]; + if (lv != null) { + Type t = Type.getType(lv.getSignature()); + addType(t); + } } } } |
From: Dave B. <dbr...@us...> - 2006-03-12 02:48:03
|
Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27576/src/com/mebigfatguy/fbcontrib/detect Modified Files: SuspiciousWaitOnConcurrentObject.java Log Message: guard against npe's Index: SuspiciousWaitOnConcurrentObject.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousWaitOnConcurrentObject.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- SuspiciousWaitOnConcurrentObject.java 5 Mar 2006 04:37:15 -0000 1.1 +++ SuspiciousWaitOnConcurrentObject.java 12 Mar 2006 02:48:00 -0000 1.2 @@ -88,12 +88,14 @@ if (stack.getStackDepth() > 0) { OpcodeStack.Item itm = stack.getStackItem(0); JavaClass cls = itm.getJavaClass(); - String clsName = cls.getClassName(); - if (concurrentAwaitClasses.contains(clsName)) { - bugReporter.reportBug(new BugInstance(this, "SWCO_SUSPICIOUS_WAIT_ON_CONCURRENT_OBJECT", NORMAL_PRIORITY) - .addClass(this) - .addMethod(this) - .addSourceLine(this)); + if (cls != null) { + String clsName = cls.getClassName(); + if (concurrentAwaitClasses.contains(clsName)) { + bugReporter.reportBug(new BugInstance(this, "SWCO_SUSPICIOUS_WAIT_ON_CONCURRENT_OBJECT", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } } } } |
From: Dave B. <dbr...@us...> - 2006-03-11 15:15:22
|
Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11819/src/com/mebigfatguy/fbcontrib/detect Modified Files: LocalSynchronizedCollection.java Log Message: mark LSYC bugs where the collection is never passed as a parameter as high, otherwise low. Index: LocalSynchronizedCollection.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LocalSynchronizedCollection.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- LocalSynchronizedCollection.java 11 Mar 2006 06:25:40 -0000 1.2 +++ LocalSynchronizedCollection.java 11 Mar 2006 15:15:19 -0000 1.3 @@ -24,6 +24,7 @@ import java.util.Set; import org.apache.bcel.classfile.Code; +import org.apache.bcel.generic.Type; import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; @@ -55,7 +56,7 @@ private BugReporter bugReporter; private OpcodeStack stack = new OpcodeStack(); - private Map<Integer, SourceLineAnnotation> syncRegs = new HashMap<Integer, SourceLineAnnotation>(); + private Map<Integer, CollectionRegInfo> syncRegs = new HashMap<Integer, CollectionRegInfo>(); /** * constructs a LSYC detector given the reporter to report bugs on @@ -86,11 +87,12 @@ syncRegs.clear(); super.visitCode(obj); - for (Map.Entry<Integer, SourceLineAnnotation> entry : syncRegs.entrySet()) { - bugReporter.reportBug(new BugInstance(this, "LSYC_LOCAL_SYNCHRONIZED_COLLECTION", NORMAL_PRIORITY) + for (Map.Entry<Integer, CollectionRegInfo> entry : syncRegs.entrySet()) { + CollectionRegInfo cri = entry.getValue(); + bugReporter.reportBug(new BugInstance(this, "LSYC_LOCAL_SYNCHRONIZED_COLLECTION", cri.getPriority()) .addClass(this) .addMethod(this) - .addSourceLine(entry.getValue())); + .addSourceLine(cri.getSourceLineAnnotation())); } } @@ -123,8 +125,11 @@ OpcodeStack.Item item = stack.getStackItem(0); if (item.getUserValue() != null) { int reg = getAStoreReg(seen); - if (!syncRegs.containsKey(reg)) - syncRegs.put(new Integer(reg), SourceLineAnnotation.fromVisitedInstruction(this)); + if (!syncRegs.containsKey(reg)) { + CollectionRegInfo cri = new CollectionRegInfo(SourceLineAnnotation.fromVisitedInstruction(this)); + syncRegs.put(new Integer(reg), cri); + + } } } } else if ((seen == ALOAD) || ((seen >= ALOAD_0) && (seen <= ALOAD_3))) { @@ -136,7 +141,25 @@ OpcodeStack.Item item = stack.getStackItem(0); syncRegs.remove((Integer)item.getUserValue()); } - } + } + + if (syncRegs.size() > 0) { + if ((seen == INVOKESPECIAL) + || (seen == INVOKEINTERFACE) + || (seen == INVOKEVIRTUAL) + || (seen == INVOKESTATIC)) { + String sig = getSigConstantOperand(); + int argCount = Type.getArgumentTypes(sig).length; + if (stack.getStackDepth() >= argCount) { + for (int i = 0; i < argCount; i++) { + OpcodeStack.Item item = stack.getStackItem(i); + CollectionRegInfo cri = syncRegs.get(item.getUserValue()); + if (cri != null) + cri.setPriority(LOW_PRIORITY); + } + } + } + } } finally { stack.sawOpcode(this, seen); if (tosIsSyncColReg != null) { @@ -171,4 +194,26 @@ return getRegisterOperand(); return seen - ALOAD_0; } + + static class CollectionRegInfo + { + private SourceLineAnnotation slAnnotation; + private int priority = HIGH_PRIORITY; + + public CollectionRegInfo(SourceLineAnnotation sla) { + slAnnotation = sla; + } + public SourceLineAnnotation getSourceLineAnnotation() { + return slAnnotation; + } + + public void setPriority(int newPriority) { + if (newPriority > priority) + priority = newPriority; + } + + public int getPriority() { + return priority; + } + } } |
From: Dave B. <dbr...@us...> - 2006-03-11 15:15:22
|
Update of /cvsroot/fb-contrib/fb-contrib/samples In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11819/samples Modified Files: LSYC_Sample.java Log Message: mark LSYC bugs where the collection is never passed as a parameter as high, otherwise low. Index: LSYC_Sample.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/samples/LSYC_Sample.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- LSYC_Sample.java 11 Mar 2006 05:01:35 -0000 1.1 +++ LSYC_Sample.java 11 Mar 2006 15:15:19 -0000 1.2 @@ -1,6 +1,8 @@ import java.util.Arrays; import java.util.Collections; +import java.util.Hashtable; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.Vector; @@ -24,7 +26,20 @@ } public void test3(List<String> ls) { + //don't report List<String> a = Collections.synchronizedList(ls); syncfield = a; } + + public Map<String, Map<String, String>> test4() { + //report as low + Map<String, Map<String, String>> main = new Hashtable<String, Map<String, String>>(); + + Map<String, String> m = new Hashtable<String, String>(); + m.put("Hello", "there"); + main.put("First", m); + + return main; + + } } |
From: Dave B. <dbr...@us...> - 2006-03-11 14:31:31
|
Update of /cvsroot/fb-contrib/fb-contrib/htdocs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15364/htdocs Modified Files: index.html Log Message: add <b> Index: index.html =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/htdocs/index.html,v retrieving revision 1.72 retrieving revision 1.73 diff -u -d -r1.72 -r1.73 --- index.html 11 Mar 2006 14:28:55 -0000 1.72 +++ index.html 11 Mar 2006 14:31:26 -0000 1.73 @@ -65,7 +65,7 @@ Looks for classes that maintain collections or StringBuffer/StringBuilders in static member variables, and that do not appear to provide a way to clear or remove items from these members. Such class fields are likely causes of memory bloat.</li> - <li>[LSYC] Local Synchronized Collection</b><br/> + <li><b>[LSYC] Local Synchronized Collection</b><br/> looks for allocations of synchronized collections that are stored in local variables, and never stored in fields or returned from methods. As local variables are by definition thread safe, using synchronized collections in this context makes no sense.</li> |
From: Dave B. <dbr...@us...> - 2006-03-11 14:28:58
|
Update of /cvsroot/fb-contrib/fb-contrib/htdocs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13530/htdocs Modified Files: index.html Log Message: doc LSYC Index: index.html =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/htdocs/index.html,v retrieving revision 1.71 retrieving revision 1.72 diff -u -d -r1.71 -r1.72 --- index.html 8 Mar 2006 04:45:17 -0000 1.71 +++ index.html 11 Mar 2006 14:28:55 -0000 1.72 @@ -65,6 +65,10 @@ Looks for classes that maintain collections or StringBuffer/StringBuilders in static member variables, and that do not appear to provide a way to clear or remove items from these members. Such class fields are likely causes of memory bloat.</li> + <li>[LSYC] Local Synchronized Collection</b><br/> + looks for allocations of synchronized collections that are stored in local variables, and + never stored in fields or returned from methods. As local variables are by definition + thread safe, using synchronized collections in this context makes no sense.</li> </ul> </div> |
From: Dave B. <dbr...@us...> - 2006-03-11 06:35:28
|
Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29544/src/com/mebigfatguy/fbcontrib/detect Modified Files: AbnormalFinallyBlockReturn.java AbstractOverriddenMethod.java Log Message: javadoc Index: AbstractOverriddenMethod.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbstractOverriddenMethod.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- AbstractOverriddenMethod.java 4 Jan 2006 02:40:42 -0000 1.2 +++ AbstractOverriddenMethod.java 11 Mar 2006 06:35:25 -0000 1.3 @@ -29,7 +29,7 @@ import edu.umd.cs.findbugs.visitclass.PreorderVisitor; /** - * finds methods that are declared abstract but override concrete methods in a superclass + * finds methods that are declared abstract but override concrete methods in a superclass. */ public class AbstractOverriddenMethod extends PreorderVisitor implements Detector, StatelessDetector { private BugReporter bugReporter; Index: AbnormalFinallyBlockReturn.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbnormalFinallyBlockReturn.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- AbnormalFinallyBlockReturn.java 1 Mar 2006 04:52:03 -0000 1.9 +++ AbnormalFinallyBlockReturn.java 11 Mar 2006 06:35:25 -0000 1.10 @@ -40,7 +40,7 @@ private int loadedReg; /** - * constructs a AFBR detector given the reporter to report bugs on + * constructs a AFBR detector given the reporter to report bugs on. * @param bugReporter the sync of bug reports */ @@ -49,9 +49,10 @@ } /** - * clone this detector so that it can be a StatelessDetector + * clone this detector so that it can be a StatelessDetector. * * @return a clone of this object + * @throws CloneNotSupportedException should not happen */ @Override public Object clone() throws CloneNotSupportedException { @@ -71,7 +72,7 @@ } /** - * overrides the visitor to collect finally block info + * overrides the visitor to collect finally block info. * * @param obj the code object to scan for finally blocks */ @@ -95,7 +96,7 @@ } /** - * overrides the visitor to find return/exceptions from the finally block + * overrides the visitor to find return/exceptions from the finally block. * * @param seen the opcode that is being visited */ @@ -155,7 +156,7 @@ } /** - * holds the finally block information for a particular method + * holds the finally block information for a particular method. */ public static class FinallyBlockInfo { |
From: Dave B. <dbr...@us...> - 2006-03-11 06:25:43
|
Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23783/src/com/mebigfatguy/fbcontrib/detect Modified Files: LocalSynchronizedCollection.java Log Message: explicit cast for remove call Index: LocalSynchronizedCollection.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LocalSynchronizedCollection.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- LocalSynchronizedCollection.java 11 Mar 2006 05:01:35 -0000 1.1 +++ LocalSynchronizedCollection.java 11 Mar 2006 06:25:40 -0000 1.2 @@ -134,7 +134,7 @@ } else if ((seen == PUTFIELD) || (seen == ARETURN)) { if (stack.getStackDepth() > 0) { OpcodeStack.Item item = stack.getStackItem(0); - syncRegs.remove(item.getUserValue()); + syncRegs.remove((Integer)item.getUserValue()); } } } finally { |
From: Dave B. <dbr...@us...> - 2006-03-11 06:22:59
|
Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22169/src/com/mebigfatguy/fbcontrib/detect Modified Files: PossibleMemoryBloat.java Log Message: javadoc fixes Index: PossibleMemoryBloat.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossibleMemoryBloat.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- PossibleMemoryBloat.java 11 Mar 2006 03:35:46 -0000 1.7 +++ PossibleMemoryBloat.java 11 Mar 2006 06:22:55 -0000 1.8 @@ -181,7 +181,7 @@ * implements the visitor to look for methods that empty a bloatable field * if found, remove these fields from the current list * - * @param obj the context object of the currently parsed instruction + * @param seen the opcode of the currently parsed instruction */ @Override public void sawOpcode(int seen) { |
From: Dave B. <dbr...@us...> - 2006-03-11 05:01:39
|
Update of /cvsroot/fb-contrib/fb-contrib/etc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9538/etc Modified Files: findbugs.xml messages.xml Log Message: intial checkin - new LSYC detector Index: messages.xml =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/etc/messages.xml,v retrieving revision 1.61 retrieving revision 1.62 diff -u -d -r1.61 -r1.62 --- messages.xml 8 Mar 2006 04:45:16 -0000 1.61 +++ messages.xml 11 Mar 2006 05:01:35 -0000 1.62 @@ -481,6 +481,18 @@ </Details> </Detector> + <Detector class="com.mebigfatguy.fbcontrib.detect.LocalSynchronizedCollection"> + <Details> + <![CDATA[ + <p>looks for allocations of synchronized collections that are stored in local + variables, and never stored in fields or returned from methods. As local variables + are by definition thread safe, using synchronized collections in this context + makes no sense.</p> + <p>It is a fast detector</p> + ]]> + </Details> + </Detector> + <!-- BugPattern --> <BugPattern type="ISB_INEFFICIENT_STRING_BUFFERING"> @@ -980,6 +992,18 @@ </Details> </BugPattern> + <BugPattern type="LSYC_LOCAL_SYNCHRONIZED_COLLECTION"> + <ShortDescription>method creates local variable-based synchronized collection</ShortDescription> + <LongDescription>method {1} creates local variable-based synchronized collection</LongDescription> + <Details> + <![CDATA[ + <p>This method creates a synchronized collection and store the reference to it + in a local variable. As local variables are by definition threadsafe, it seems + questionable that this collection needs to be synchronized.</p> + ]]> + </Details> + </BugPattern> + <!-- BugCode --> <BugCode abbrev="ISB">Inefficient String Buffering</BugCode> @@ -1020,4 +1044,5 @@ <BugCode abbrev="SWCO">Suspicious Wait on Concurrent Object</BugCode> <BugCode abbrev="JVR">JDBC Vendor Reliance</BugCode> <BugCode abbrev="PMB">Possible Memory Bloat</BugCode> + <BugCode abbrev="LSYC">Local Synchronized Collection</BugCode> </MessageCollection> \ No newline at end of file Index: findbugs.xml =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/etc/findbugs.xml,v retrieving revision 1.68 retrieving revision 1.69 diff -u -d -r1.68 -r1.69 --- findbugs.xml 7 Mar 2006 06:17:24 -0000 1.68 +++ findbugs.xml 11 Mar 2006 05:01:35 -0000 1.69 @@ -129,7 +129,7 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.BloatedSynchronizedBlock" speed="fast" reports="BSB_BLOATED_SYNCHRONIZED_BLOCK" - disabled="true" /> + hidden="true" /> <Detector class="com.mebigfatguy.fbcontrib.detect.ConstantListIndex" speed="fast" @@ -167,7 +167,10 @@ speed="fast" reports="PMB_POSSIBLE_MEMORY_BLOAT" /> - + <Detector class="com.mebigfatguy.fbcontrib.detect.LocalSynchronizedCollection" + speed="fast" + reports="LSYC_LOCAL_SYNCHRONIZED_COLLECTION" /> + <!-- BugPattern --> <BugPattern abbrev="ISB" type="ISB_INEFFICIENT_STRING_BUFFERING" category="PERFORMANCE" /> @@ -208,4 +211,5 @@ <BugPattern abbrev="SWCO" type="SWCO_SUSPICIOUS_WAIT_ON_CONCURRENT_OBJECT" category="CORRECTNESS" experimental="true" /> <BugPattern abbrev="JVR" type="JVR_JDBC_VENDOR_RELIANCE" category="CORRECTNESS" experimental="true" /> <BugPattern abbrev="PMB" type="PMB_POSSIBLE_MEMORY_BLOAT" category="CORRECTNESS" experimental="true" /> + <BugPattern abbrev="LSYC" type="LSYC_LOCAL_SYNCHRONIZED_COLLECTION" category="CORRECTNESS" experimental="true" /> </FindbugsPlugin> \ No newline at end of file |
From: Dave B. <dbr...@us...> - 2006-03-11 05:01:39
|
Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9538/src/com/mebigfatguy/fbcontrib/detect Added Files: LocalSynchronizedCollection.java Log Message: intial checkin - new LSYC detector --- NEW FILE: LocalSynchronizedCollection.java --- /* * fb-contrib - Auxilliary detectors for Java programs * Copyright (C) 2005-2006 Dave Brosius * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package com.mebigfatguy.fbcontrib.detect; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import org.apache.bcel.classfile.Code; import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; import edu.umd.cs.findbugs.OpcodeStack; import edu.umd.cs.findbugs.SourceLineAnnotation; import edu.umd.cs.findbugs.StatelessDetector; /** * looks for allocations of synchronized collections that are stored in local variables, and * never stored in fields or returned from methods. As local variables are by definition * thread safe, using synchronized collections in this context makes no sense. */ public class LocalSynchronizedCollection extends BytecodeScanningDetector implements StatelessDetector { private static Set<String> syncCtors = new HashSet<String>(); static { syncCtors.add("java/util/Vector"); syncCtors.add("java/util/Hashtable"); } private static Set<String> syncMethods = new HashSet<String>(); static { syncMethods.add("synchronizedCollection"); syncMethods.add("synchronizedList"); syncMethods.add("synchronizedMap"); syncMethods.add("synchronizedSet"); syncMethods.add("synchronizedSortedMap"); syncMethods.add("synchronizedSortedSet"); } private BugReporter bugReporter; private OpcodeStack stack = new OpcodeStack(); private Map<Integer, SourceLineAnnotation> syncRegs = new HashMap<Integer, SourceLineAnnotation>(); /** * constructs a LSYC detector given the reporter to report bugs on * @param bugReporter the sync of bug reports */ public LocalSynchronizedCollection(BugReporter bugReporter) { this.bugReporter = bugReporter; } /** * clone this detector so that it can be a StatelessDetector * * @return a clone of this object */ @Override public Object clone() throws CloneNotSupportedException { return super.clone(); } /** * implements the visitor to reset the stack * * @param obj the context object of the currently parsed code block */ @Override public void visitCode(Code obj) { stack.resetForMethodEntry(this); syncRegs.clear(); super.visitCode(obj); for (Map.Entry<Integer, SourceLineAnnotation> entry : syncRegs.entrySet()) { bugReporter.reportBug(new BugInstance(this, "LSYC_LOCAL_SYNCHRONIZED_COLLECTION", NORMAL_PRIORITY) .addClass(this) .addMethod(this) .addSourceLine(entry.getValue())); } } /** * implements the visitor to find stores to locals of synchronized collections * * @param seen the opcode of the currently parsed instruction */ @Override public void sawOpcode(int seen) { Integer tosIsSyncColReg = null; try { stack.mergeJumps(this); if (seen == INVOKESPECIAL) { if ("<init>".equals(getNameConstantOperand())) { if (syncCtors.contains(getClassConstantOperand())) { tosIsSyncColReg = new Integer(-1); } } } else if (seen == INVOKESTATIC) { if ("java/util/Collections".equals(getClassConstantOperand())) { if (syncMethods.contains(getNameConstantOperand())) { tosIsSyncColReg = new Integer(-1); } } } else if ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3))) { if (stack.getStackDepth() > 0) { OpcodeStack.Item item = stack.getStackItem(0); if (item.getUserValue() != null) { int reg = getAStoreReg(seen); if (!syncRegs.containsKey(reg)) syncRegs.put(new Integer(reg), SourceLineAnnotation.fromVisitedInstruction(this)); } } } else if ((seen == ALOAD) || ((seen >= ALOAD_0) && (seen <= ALOAD_3))) { int reg = getALoadReg(seen); if (syncRegs.containsKey(new Integer(reg))) tosIsSyncColReg = new Integer(reg); } else if ((seen == PUTFIELD) || (seen == ARETURN)) { if (stack.getStackDepth() > 0) { OpcodeStack.Item item = stack.getStackItem(0); syncRegs.remove(item.getUserValue()); } } } finally { stack.sawOpcode(this, seen); if (tosIsSyncColReg != null) { if (stack.getStackDepth() > 0) { OpcodeStack.Item item = stack.getStackItem(0); item.setUserValue(tosIsSyncColReg); } } } } /** * returns the register used to store a reference * * @param seen the opcode of the store * @return the register stored into */ private int getAStoreReg(int seen) { if (seen == ASTORE) return getRegisterOperand(); return seen - ASTORE_0; } /** * returns the register used to load a reference * * @param seen the opcode of the load * @return the register loaded from */ private int getALoadReg(int seen) { if (seen == ALOAD) return getRegisterOperand(); return seen - ALOAD_0; } } |
From: Dave B. <dbr...@us...> - 2006-03-11 05:01:39
|
Update of /cvsroot/fb-contrib/fb-contrib/samples In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9538/samples Added Files: LSYC_Sample.java Log Message: intial checkin - new LSYC detector --- NEW FILE: LSYC_Sample.java --- import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Set; import java.util.Vector; public class LSYC_Sample { List<String> syncfield; public Object[] test1(String[] s) { Vector<String> v = new Vector<String>(); v.addAll(Arrays.asList(s)); Collections.sort(v); return v.toArray(); } public void test2(Set<String> s) { Set<String> ss = Collections.<String>synchronizedSet(s); for (String st : ss) { System.out.println(st); } } public void test3(List<String> ls) { List<String> a = Collections.synchronizedList(ls); syncfield = a; } } |