Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

dalvik: Commit

dalvik


Commit MetaInfo

Revisionacb058bf9fe822b104acbede223b4d62aa8ce782 (tree)
Time2013-12-03 22:04:10
AuthorYohann Roussel <yroussel@goog...>
CommiterYohann Roussel

Log Message

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)

Change Summary

Incremental Difference

--- a/dx/src/com/android/dx/dex/cf/CfTranslator.java
+++ b/dx/src/com/android/dx/dex/cf/CfTranslator.java
@@ -142,20 +142,18 @@ public class CfTranslator {
142142 ConstantPool constantPool = cf.getConstantPool();
143143 int constantPoolSize = constantPool.size();
144144
145- synchronized (dexFile) {
146- for (int i = 0; i < constantPoolSize; i++) {
147- Constant constant = constantPool.getOrNull(i);
148- if (constant instanceof CstMethodRef) {
149- methodIdsSection.intern((CstBaseMethodRef) constant);
150- } else if (constant instanceof CstInterfaceMethodRef) {
151- methodIdsSection.intern(((CstInterfaceMethodRef) constant).toMethodRef());
152- } else if (constant instanceof CstFieldRef) {
153- fieldIdsSection.intern((CstFieldRef) constant);
154- } else if (constant instanceof CstEnumRef) {
155- fieldIdsSection.intern(((CstEnumRef) constant).getFieldRef());
156- } else if (constant instanceof CstType) {
157- typeIdsSection.intern((CstType) constant);
158- }
145+ for (int i = 0; i < constantPoolSize; i++) {
146+ Constant constant = constantPool.getOrNull(i);
147+ if (constant instanceof CstMethodRef) {
148+ methodIdsSection.intern((CstBaseMethodRef) constant);
149+ } else if (constant instanceof CstInterfaceMethodRef) {
150+ methodIdsSection.intern(((CstInterfaceMethodRef) constant).toMethodRef());
151+ } else if (constant instanceof CstFieldRef) {
152+ fieldIdsSection.intern((CstFieldRef) constant);
153+ } else if (constant instanceof CstEnumRef) {
154+ fieldIdsSection.intern(((CstEnumRef) constant).getFieldRef());
155+ } else if (constant instanceof CstType) {
156+ typeIdsSection.intern((CstType) constant);
159157 }
160158 }
161159
@@ -197,9 +195,7 @@ public class CfTranslator {
197195 if (annotations.size() != 0) {
198196 out.addFieldAnnotations(field, annotations);
199197 }
200- synchronized (fieldIdsSection) {
201- fieldIdsSection.intern(field);
202- }
198+ fieldIdsSection.intern(field);
203199 } catch (RuntimeException ex) {
204200 String msg = "...while processing " + one.getName().toHuman() +
205201 " " + one.getDescriptor().toHuman();
@@ -368,9 +364,7 @@ public class CfTranslator {
368364 if (list.size() != 0) {
369365 out.addParameterAnnotations(meth, list);
370366 }
371- synchronized (methodIds) {
372- methodIds.intern(meth);
373- }
367+ methodIds.intern(meth);
374368 } catch (RuntimeException ex) {
375369 String msg = "...while processing " + one.getName().toHuman() +
376370 " " + one.getDescriptor().toHuman();
--- a/dx/src/com/android/dx/dex/file/FieldIdsSection.java
+++ b/dx/src/com/android/dx/dex/file/FieldIdsSection.java
@@ -20,6 +20,7 @@ import com.android.dx.rop.cst.Constant;
2020 import com.android.dx.rop.cst.CstFieldRef;
2121 import com.android.dx.util.AnnotatedOutput;
2222 import com.android.dx.util.Hex;
23+
2324 import java.util.Collection;
2425 import java.util.TreeMap;
2526
@@ -94,7 +95,7 @@ public final class FieldIdsSection extends MemberIdsSection {
9495 * @param field {@code non-null;} the reference to intern
9596 * @return {@code non-null;} the interned reference
9697 */
97- public FieldIdItem intern(CstFieldRef field) {
98+ public synchronized FieldIdItem intern(CstFieldRef field) {
9899 if (field == null) {
99100 throw new NullPointerException("field == null");
100101 }
--- a/dx/src/com/android/dx/dex/file/MethodIdsSection.java
+++ b/dx/src/com/android/dx/dex/file/MethodIdsSection.java
@@ -20,6 +20,7 @@ import com.android.dx.rop.cst.Constant;
2020 import com.android.dx.rop.cst.CstBaseMethodRef;
2121 import com.android.dx.util.AnnotatedOutput;
2222 import com.android.dx.util.Hex;
23+
2324 import java.util.Collection;
2425 import java.util.TreeMap;
2526
@@ -94,7 +95,7 @@ public final class MethodIdsSection extends MemberIdsSection {
9495 * @param method {@code non-null;} the reference to intern
9596 * @return {@code non-null;} the interned reference
9697 */
97- public MethodIdItem intern(CstBaseMethodRef method) {
98+ public synchronized MethodIdItem intern(CstBaseMethodRef method) {
9899 if (method == null) {
99100 throw new NullPointerException("method == null");
100101 }
--- a/dx/src/com/android/dx/dex/file/TypeIdsSection.java
+++ b/dx/src/com/android/dx/dex/file/TypeIdsSection.java
@@ -128,7 +128,7 @@ public final class TypeIdsSection extends UniformItemSection {
128128 * @param type {@code non-null;} the type to intern
129129 * @return {@code non-null;} the interned reference
130130 */
131- public TypeIdItem intern(CstType type) {
131+ public synchronized TypeIdItem intern(CstType type) {
132132 if (type == null) {
133133 throw new NullPointerException("type == null");
134134 }
Show on old repository browser