summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYohann Roussel <yroussel@google.com>2013-11-18 17:38:03 +0100
committerYohann Roussel <yroussel@google.com>2013-12-03 13:04:10 +0000
commitacb058bf9fe822b104acbede223b4d62aa8ce782 (patch)
treed053e8a0e20fcab081ebcd7eabec01c1b9cdde72
parent6e21232cf2bca0e73bd418413564cb140ab9ccbd (diff)
downloadandroid_dalvik-acb058bf9fe822b104acbede223b4d62aa8ce782.tar.gz
android_dalvik-acb058bf9fe822b104acbede223b4d62aa8ce782.tar.bz2
android_dalvik-acb058bf9fe822b104acbede223b4d62aa8ce782.zip
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)
-rw-r--r--dx/src/com/android/dx/dex/cf/CfTranslator.java34
-rw-r--r--dx/src/com/android/dx/dex/file/FieldIdsSection.java3
-rw-r--r--dx/src/com/android/dx/dex/file/MethodIdsSection.java3
-rw-r--r--dx/src/com/android/dx/dex/file/TypeIdsSection.java2
4 files changed, 19 insertions, 23 deletions
diff --git a/dx/src/com/android/dx/dex/cf/CfTranslator.java b/dx/src/com/android/dx/dex/cf/CfTranslator.java
index 8ab1c8426..92ea0f7a0 100644
--- 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 {
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);
}
}
@@ -197,9 +195,7 @@ public class CfTranslator {
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();
@@ -368,9 +364,7 @@ public class CfTranslator {
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();
diff --git a/dx/src/com/android/dx/dex/file/FieldIdsSection.java b/dx/src/com/android/dx/dex/file/FieldIdsSection.java
index 27d946d64..f422bab04 100644
--- 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;
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;
@@ -94,7 +95,7 @@ public final class FieldIdsSection extends MemberIdsSection {
* @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");
}
diff --git a/dx/src/com/android/dx/dex/file/MethodIdsSection.java b/dx/src/com/android/dx/dex/file/MethodIdsSection.java
index d99198b24..254d7fe43 100644
--- 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;
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;
@@ -94,7 +95,7 @@ public final class MethodIdsSection extends MemberIdsSection {
* @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");
}
diff --git a/dx/src/com/android/dx/dex/file/TypeIdsSection.java b/dx/src/com/android/dx/dex/file/TypeIdsSection.java
index ef47262a5..d9ab274d8 100644
--- 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 {
* @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");
}