Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Unified Diff: tools/android/findbugs_plugin/src/org/chromium/tools/findbugs/plugin/SynchronizedThisDetector.java

Issue 1841863002: Update monet. (Closed) Base URL: https://github.com/domokit/monet.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/android/findbugs_plugin/src/org/chromium/tools/findbugs/plugin/SynchronizedThisDetector.java
diff --git a/tools/android/findbugs_plugin/src/org/chromium/tools/findbugs/plugin/SynchronizedThisDetector.java b/tools/android/findbugs_plugin/src/org/chromium/tools/findbugs/plugin/SynchronizedThisDetector.java
new file mode 100644
index 0000000000000000000000000000000000000000..9a4e5e12226c769ef60fdedf165b7999fbfad2aa
--- /dev/null
+++ b/tools/android/findbugs_plugin/src/org/chromium/tools/findbugs/plugin/SynchronizedThisDetector.java
@@ -0,0 +1,73 @@
+// Copyright 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.tools.findbugs.plugin;
+
+import org.apache.bcel.classfile.Code;
+
+import edu.umd.cs.findbugs.BugInstance;
+import edu.umd.cs.findbugs.BugReporter;
+import edu.umd.cs.findbugs.bcel.OpcodeStackDetector;
+
+/**
+ * This class detects the synchronized(this).
+ *
+ * The pattern of byte code of synchronized(this) is
+ * aload_0 # Load the 'this' pointer on top of stack
+ * dup # Duplicate the 'this' pointer
+ * astore_x # Store this for late use, it might be astore.
+ * monitorenter
+ */
+public class SynchronizedThisDetector extends OpcodeStackDetector {
+ private static final int PATTERN[] = {ALOAD_0, DUP, 0xff, 0xff, MONITORENTER};
+
+ private int mStep = 0;
+ private BugReporter mBugReporter;
+
+ public SynchronizedThisDetector(BugReporter bugReporter) {
+ mBugReporter = bugReporter;
+ }
+
+ @Override
+ public void visit(Code code) {
+ mStep = 0;
+ super.visit(code);
+ }
+
+ @Override
+ public void sawOpcode(int seen) {
+ if (PATTERN[mStep] == seen) {
+ mStep++;
+ if (mStep == PATTERN.length) {
+ mBugReporter.reportBug(new BugInstance(this, "CHROMIUM_SYNCHRONIZED_THIS",
+ NORMAL_PRIORITY)
+ .addClassAndMethod(this)
+ .addSourceLine(this));
+ mStep = 0;
+ return;
+ }
+ } else if (mStep == 2) {
+ // This could be astore_x
+ switch (seen) {
+ case ASTORE_0:
+ case ASTORE_1:
+ case ASTORE_2:
+ case ASTORE_3:
+ mStep += 2;
+ break;
+ case ASTORE:
+ mStep++;
+ break;
+ default:
+ mStep = 0;
+ break;
+ }
+ } else if (mStep == 3) {
+ // Could be any byte following the ASTORE.
+ mStep++;
+ } else {
+ mStep = 0;
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698