[Fb-contrib-commit] SF.net SVN: fb-contrib: [403] trunk/fb-contrib/samples
Brought to you by:
dbrosius
From: <dbr...@us...> - 2006-04-07 01:25:31
|
Revision: 403 Author: dbrosius Date: 2006-04-06 18:25:23 -0700 (Thu, 06 Apr 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=403&view=rev Log Message: ----------- better detection of when their is a possibility that a variable is owned, or at least may be owned. Modified Paths: -------------- trunk/fb-contrib/samples/NOS_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonOwnedSynchronization.java Modified: trunk/fb-contrib/samples/NOS_Sample.java =================================================================== --- trunk/fb-contrib/samples/NOS_Sample.java 2006-04-06 14:26:33 UTC (rev 402) +++ trunk/fb-contrib/samples/NOS_Sample.java 2006-04-07 01:25:23 UTC (rev 403) @@ -1,8 +1,30 @@ +import java.util.Map; public class NOS_Sample { + private Object lock = new Object(); + public String test(Object o) { synchronized(o) { return o.toString(); } } + + public String test2(Object o) { + synchronized(this) { + return o.toString(); + } + } + + public String test3(Map m) { + String v = (String)m.get("boo"); + synchronized (v) { + return v.substring(0,1); + } + } + + public String test4(Object o) { + synchronized(lock) { + return o.toString(); + } + } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonOwnedSynchronization.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonOwnedSynchronization.java 2006-04-06 14:26:33 UTC (rev 402) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonOwnedSynchronization.java 2006-04-07 01:25:23 UTC (rev 403) @@ -67,12 +67,15 @@ */ @Override public void visitCode(Code obj) { - if (prescreen(getMethod())) { + Method method = getMethod(); + if (prescreen(method)) { stack.resetForMethodEntry(this); regPriorities.clear(); - int[] parmRegs = RegisterUtils.getParameterRegisters(getMethod()); + int[] parmRegs = RegisterUtils.getParameterRegisters(method); for (int reg : parmRegs) regPriorities.put(new Integer(reg), NORMAL); + if (!method.isStatic()) + regPriorities.put(new Integer(0), LOW); super.visitCode(obj); } } @@ -122,16 +125,23 @@ break; case INVOKEVIRTUAL: - case INVOKEINTERFACE: - case INVOKESPECIAL: { + case INVOKEINTERFACE: { String sig = getSigConstantOperand(); Type t = Type.getReturnType(sig); if (t.getSignature().startsWith("L")) { int parmCnt = Type.getArgumentTypes(sig).length; if (stack.getStackDepth() >= parmCnt) { OpcodeStack.Item itm = stack.getStackItem(parmCnt); - if (itm.getRegisterNumber() != 0) - tosIsPriority = NORMAL; + Integer priority = (Integer)itm.getUserValue(); + if ((priority != null) && OWNED.equals(priority)) { + tosIsPriority = OWNED; + } else { + int reg = itm.getRegisterNumber(); + if (reg > 0) + tosIsPriority = regPriorities.get(new Integer(reg)); + else + tosIsPriority = OWNED; + } } } } @@ -140,8 +150,15 @@ case INVOKESTATIC: { String sig = getSigConstantOperand(); Type t = Type.getReturnType(sig); - if (t.getSignature().startsWith("L")) { - tosIsPriority = NORMAL; + if (t.getSignature().startsWith("L")) + tosIsPriority = OWNED; // can't be sure + } + break; + + case INVOKESPECIAL: { + String name = getNameConstantOperand(); + if ("<init>".equals(name)) { + tosIsPriority = OWNED; } } break; @@ -150,7 +167,7 @@ if (stack.getStackDepth() > 0) { OpcodeStack.Item itm = stack.getStackItem(0); Integer priority = (Integer)itm.getUserValue(); - if (priority != null) { + if ((priority != null) && (!priority.equals(OWNED))) { bugReporter.reportBug(new BugInstance(this, "NOS_NON_OWNED_SYNCHRONIZATION", priority.intValue()) .addClass(this) .addMethod(this) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |