Commits

Anonymous committed acb058b

Fix synchronization when preparing ids.

Synchronized blocks were using different locks.
Replaced by a safer version: marking intern method synchronized.
This means synchronizing more than necessary but it had no
mesurable perfomance impact.

Bug 11744785

Change-Id: I35e691232cd6971d13735be9b72969739ef71e09
(cherry picked from commit 5c4883e75b26a002c67bfa1c0053c50e17dbac90)

Comments (0)

Files changed (4)

dx/src/com/android/dx/dex/cf/CfTranslator.java

         ConstantPool constantPool = cf.getConstantPool();
         int constantPoolSize = constantPool.size();
 
-        synchronized (dexFile) {
-            for (int i = 0; i < constantPoolSize; i++) {
-                Constant constant = constantPool.getOrNull(i);
-                if (constant instanceof CstMethodRef) {
-                    methodIdsSection.intern((CstBaseMethodRef) constant);
-                } else if (constant instanceof CstInterfaceMethodRef) {
-                    methodIdsSection.intern(((CstInterfaceMethodRef) constant).toMethodRef());
-                } else if (constant instanceof CstFieldRef) {
-                    fieldIdsSection.intern((CstFieldRef) constant);
-                } else if (constant instanceof CstEnumRef) {
-                    fieldIdsSection.intern(((CstEnumRef) constant).getFieldRef());
-                } else if (constant instanceof CstType) {
-                    typeIdsSection.intern((CstType) constant);
-                }
+        for (int i = 0; i < constantPoolSize; i++) {
+            Constant constant = constantPool.getOrNull(i);
+            if (constant instanceof CstMethodRef) {
+                methodIdsSection.intern((CstBaseMethodRef) constant);
+            } else if (constant instanceof CstInterfaceMethodRef) {
+                methodIdsSection.intern(((CstInterfaceMethodRef) constant).toMethodRef());
+            } else if (constant instanceof CstFieldRef) {
+                fieldIdsSection.intern((CstFieldRef) constant);
+            } else if (constant instanceof CstEnumRef) {
+                fieldIdsSection.intern(((CstEnumRef) constant).getFieldRef());
+            } else if (constant instanceof CstType) {
+                typeIdsSection.intern((CstType) constant);
             }
         }
 
                 if (annotations.size() != 0) {
                     out.addFieldAnnotations(field, annotations);
                 }
-                synchronized (fieldIdsSection) {
-                    fieldIdsSection.intern(field);
-                }
+                fieldIdsSection.intern(field);
             } catch (RuntimeException ex) {
                 String msg = "...while processing " + one.getName().toHuman() +
                     " " + one.getDescriptor().toHuman();
                 if (list.size() != 0) {
                     out.addParameterAnnotations(meth, list);
                 }
-                synchronized (methodIds) {
-                  methodIds.intern(meth);
-                }
+                methodIds.intern(meth);
             } catch (RuntimeException ex) {
                 String msg = "...while processing " + one.getName().toHuman() +
                     " " + one.getDescriptor().toHuman();

dx/src/com/android/dx/dex/file/FieldIdsSection.java

 import com.android.dx.rop.cst.CstFieldRef;
 import com.android.dx.util.AnnotatedOutput;
 import com.android.dx.util.Hex;
+
 import java.util.Collection;
 import java.util.TreeMap;
 
      * @param field {@code non-null;} the reference to intern
      * @return {@code non-null;} the interned reference
      */
-    public FieldIdItem intern(CstFieldRef field) {
+    public synchronized FieldIdItem intern(CstFieldRef field) {
         if (field == null) {
             throw new NullPointerException("field == null");
         }

dx/src/com/android/dx/dex/file/MethodIdsSection.java

 import com.android.dx.rop.cst.CstBaseMethodRef;
 import com.android.dx.util.AnnotatedOutput;
 import com.android.dx.util.Hex;
+
 import java.util.Collection;
 import java.util.TreeMap;
 
      * @param method {@code non-null;} the reference to intern
      * @return {@code non-null;} the interned reference
      */
-    public MethodIdItem intern(CstBaseMethodRef method) {
+    public synchronized MethodIdItem intern(CstBaseMethodRef method) {
         if (method == null) {
             throw new NullPointerException("method == null");
         }

dx/src/com/android/dx/dex/file/TypeIdsSection.java

      * @param type {@code non-null;} the type to intern
      * @return {@code non-null;} the interned reference
      */
-    public TypeIdItem intern(CstType type) {
+    public synchronized TypeIdItem intern(CstType type) {
         if (type == null) {
             throw new NullPointerException("type == null");
         }