ASF Bugzilla – Attachment 20294 Details for
Bug 42552
Thread safety + unbuffered writes
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bcel.patch.txt (text/plain), 32.46 KB, created by
Ken McNeil
on 2007-05-30 17:56:53 UTC
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Ken McNeil
Created:
2007-05-30 17:56:53 UTC
Size:
32.46 KB
patch
obsolete
>diff -ru v0/src/java/org/apache/bcel/classfile/Attribute.java v2a/src/java/org/apache/bcel/classfile/Attribute.java >--- v0/src/java/org/apache/bcel/classfile/Attribute.java 2006-06-02 20:48:24.000000000 -0700 >+++ v2a/src/java/org/apache/bcel/classfile/Attribute.java 2007-03-14 14:44:14.321999000 -0700 >@@ -83,7 +83,11 @@ > file.writeInt(length); > } > >- private static Map readers = new HashMap(); >+ private static ThreadLocal readers = new ThreadLocal() { >+ protected Object initialValue() { >+ return new HashMap(); >+ } >+ }; > > > /** Add an Attribute reader capable of parsing (user-defined) attributes >@@ -94,7 +98,7 @@ > * @param r the reader object > */ > public static void addAttributeReader( String name, AttributeReader r ) { >- readers.put(name, r); >+ ((Map) readers.get()).put(name, r); > } > > >@@ -103,7 +107,7 @@ > * @param name the name of the attribute as stored in the class file > */ > public static void removeAttributeReader( String name ) { >- readers.remove(name); >+ ((Map) readers.get()).remove(name); > } > > >@@ -142,7 +146,7 @@ > // Call proper constructor, depending on `tag' > switch (tag) { > case Constants.ATTR_UNKNOWN: >- AttributeReader r = (AttributeReader) readers.get(name); >+ AttributeReader r = (AttributeReader) ((Map) readers.get()).get(name); > if (r != null) { > return r.createAttribute(name_index, length, file, constant_pool); > } >diff -ru v0/src/java/org/apache/bcel/classfile/Constant.java v2a/src/java/org/apache/bcel/classfile/Constant.java >--- v0/src/java/org/apache/bcel/classfile/Constant.java 2006-06-02 20:48:24.000000000 -0700 >+++ v2a/src/java/org/apache/bcel/classfile/Constant.java 2007-03-14 14:44:14.410997000 -0700 >@@ -33,7 +33,7 @@ > */ > public abstract class Constant implements Cloneable, Node, Serializable { > >- private static BCELComparator _cmp = new BCELComparator() { >+ private static final BCELComparator DEFAULT_CMP = new BCELComparator() { > > public boolean equals( Object o1, Object o2 ) { > Constant THIS = (Constant) o1; >@@ -47,6 +47,14 @@ > return THIS.toString().hashCode(); > } > }; >+ >+ >+ private static ThreadLocal _cmp = new ThreadLocal() { >+ protected Object initialValue() { >+ return DEFAULT_CMP; >+ } >+ }; >+ > /* In fact this tag is redundant since we can distinguish different > * `Constant' objects by their type, i.e., via `instanceof'. In some > * places we will use the tag for switch()es anyway. >@@ -152,7 +160,7 @@ > * @return Comparison strategy object > */ > public static BCELComparator getComparator() { >- return _cmp; >+ return (BCELComparator) _cmp.get(); > } > > >@@ -160,7 +168,7 @@ > * @param comparator Comparison strategy object > */ > public static void setComparator( BCELComparator comparator ) { >- _cmp = comparator; >+ _cmp.set(comparator); > } > > >@@ -172,7 +180,7 @@ > * @see java.lang.Object#equals(java.lang.Object) > */ > public boolean equals( Object obj ) { >- return _cmp.equals(this, obj); >+ return getComparator().equals(this, obj); > } > > >@@ -183,6 +191,6 @@ > * @see java.lang.Object#hashCode() > */ > public int hashCode() { >- return _cmp.hashCode(this); >+ return getComparator().hashCode(this); > } > } >diff -ru v0/src/java/org/apache/bcel/classfile/Field.java v2a/src/java/org/apache/bcel/classfile/Field.java >--- v0/src/java/org/apache/bcel/classfile/Field.java 2006-06-02 20:48:24.000000000 -0700 >+++ v2a/src/java/org/apache/bcel/classfile/Field.java 2007-03-14 14:44:14.536004000 -0700 >@@ -31,7 +31,7 @@ > */ > public final class Field extends FieldOrMethod { > >- private static BCELComparator _cmp = new BCELComparator() { >+ private static final BCELComparator DEFAULT_CMP = new BCELComparator() { > > public boolean equals( Object o1, Object o2 ) { > Field THIS = (Field) o1; >@@ -47,6 +47,12 @@ > } > }; > >+ private static ThreadLocal _cmp = new ThreadLocal() { >+ protected Object initialValue() { >+ return DEFAULT_CMP; >+ } >+ }; >+ > > /** > * Initialize from another object. Note that both objects use the same >@@ -154,7 +160,7 @@ > * @return Comparison strategy object > */ > public static BCELComparator getComparator() { >- return _cmp; >+ return (BCELComparator) _cmp.get(); > } > > >@@ -162,7 +168,7 @@ > * @param comparator Comparison strategy object > */ > public static void setComparator( BCELComparator comparator ) { >- _cmp = comparator; >+ _cmp.set(comparator); > } > > >@@ -174,7 +180,7 @@ > * @see java.lang.Object#equals(java.lang.Object) > */ > public boolean equals( Object obj ) { >- return _cmp.equals(this, obj); >+ return getComparator().equals(this, obj); > } > > >@@ -185,6 +191,6 @@ > * @see java.lang.Object#hashCode() > */ > public int hashCode() { >- return _cmp.hashCode(this); >+ return getComparator().hashCode(this); > } > } >diff -ru v0/src/java/org/apache/bcel/classfile/JavaClass.java v2a/src/java/org/apache/bcel/classfile/JavaClass.java >--- v0/src/java/org/apache/bcel/classfile/JavaClass.java 2006-06-02 20:48:24.000000000 -0700 >+++ v2a/src/java/org/apache/bcel/classfile/JavaClass.java 2007-03-14 14:46:54.283787000 -0700 >@@ -16,6 +16,7 @@ > */ > package org.apache.bcel.classfile; > >+import java.io.BufferedOutputStream; > import java.io.ByteArrayOutputStream; > import java.io.DataOutputStream; > import java.io.File; >@@ -67,7 +68,8 @@ > public static final byte ZIP = 3; > static boolean debug = false; // Debugging on/off > static char sep = '/'; // directory separator >- private static BCELComparator _cmp = new BCELComparator() { >+ >+ private static final BCELComparator DEFAULT_CMP = new BCELComparator() { > > public boolean equals( Object o1, Object o2 ) { > JavaClass THIS = (JavaClass) o1; >@@ -81,6 +83,14 @@ > return THIS.getClassName().hashCode(); > } > }; >+ >+ >+ private static ThreadLocal _cmp = new ThreadLocal() { >+ protected Object initialValue() { >+ return DEFAULT_CMP; >+ } >+ }; >+ > /** > * In cases where we go ahead and create something, > * use the default SyntheticRepository, because we >@@ -228,7 +238,9 @@ > } > DataOutputStream dos = null; > try { >- dos = new DataOutputStream(new FileOutputStream(file)); >+ dos = new DataOutputStream( >+ new BufferedOutputStream( >+ new FileOutputStream(file))); > dump(dos); > } finally { > if (dos != null) { >@@ -821,7 +833,7 @@ > * @return Comparison strategy object > */ > public static BCELComparator getComparator() { >- return _cmp; >+ return (BCELComparator) _cmp.get(); > } > > >@@ -829,7 +841,7 @@ > * @param comparator Comparison strategy object > */ > public static void setComparator( BCELComparator comparator ) { >- _cmp = comparator; >+ _cmp.set(comparator); > } > > >@@ -841,7 +853,7 @@ > * @see java.lang.Object#equals(java.lang.Object) > */ > public boolean equals( Object obj ) { >- return _cmp.equals(this, obj); >+ return getComparator().equals(this, obj); > } > > >@@ -861,6 +873,6 @@ > * @see java.lang.Object#hashCode() > */ > public int hashCode() { >- return _cmp.hashCode(this); >+ return getComparator().hashCode(this); > } > } >diff -ru v0/src/java/org/apache/bcel/classfile/Method.java v2a/src/java/org/apache/bcel/classfile/Method.java >--- v0/src/java/org/apache/bcel/classfile/Method.java 2006-06-02 20:48:24.000000000 -0700 >+++ v2a/src/java/org/apache/bcel/classfile/Method.java 2007-03-14 14:44:14.614997000 -0700 >@@ -32,7 +32,7 @@ > */ > public final class Method extends FieldOrMethod { > >- private static BCELComparator _cmp = new BCELComparator() { >+ private static final BCELComparator DEFAULT_CMP = new BCELComparator() { > > public boolean equals( Object o1, Object o2 ) { > Method THIS = (Method) o1; >@@ -48,6 +48,11 @@ > } > }; > >+ private static ThreadLocal _cmp = new ThreadLocal() { >+ protected Object initialValue() { >+ return DEFAULT_CMP; >+ } >+ }; > > /** > * Empty constructor, all attributes have to be defined via `setXXX' >@@ -218,7 +223,7 @@ > * @return Comparison strategy object > */ > public static BCELComparator getComparator() { >- return _cmp; >+ return (BCELComparator) _cmp.get(); > } > > >@@ -226,7 +231,7 @@ > * @param comparator Comparison strategy object > */ > public static void setComparator( BCELComparator comparator ) { >- _cmp = comparator; >+ _cmp.set(comparator); > } > > >@@ -238,7 +243,7 @@ > * @see java.lang.Object#equals(java.lang.Object) > */ > public boolean equals( Object obj ) { >- return _cmp.equals(this, obj); >+ return getComparator().equals(this, obj); > } > > >@@ -249,6 +254,6 @@ > * @see java.lang.Object#hashCode() > */ > public int hashCode() { >- return _cmp.hashCode(this); >+ return getComparator().hashCode(this); > } > } >diff -ru v0/src/java/org/apache/bcel/classfile/Unknown.java v2a/src/java/org/apache/bcel/classfile/Unknown.java >--- v0/src/java/org/apache/bcel/classfile/Unknown.java 2006-06-02 20:48:24.000000000 -0700 >+++ v2a/src/java/org/apache/bcel/classfile/Unknown.java 2007-03-14 14:44:14.676005000 -0700 >@@ -44,18 +44,23 @@ > > private byte[] bytes; > private String name; >- private static Map unknown_attributes = new HashMap(); >+ private static ThreadLocal unknown_attributes = new ThreadLocal() { >+ protected Object initialValue() { >+ return new HashMap(); >+ } >+ }; > > > /** @return array of unknown attributes, but just one for each kind. > */ > static Unknown[] getUnknownAttributes() { >- Unknown[] unknowns = new Unknown[unknown_attributes.size()]; >- Iterator entries = unknown_attributes.values().iterator(); >+ Map map = (Map) unknown_attributes.get(); >+ Unknown[] unknowns = new Unknown[map.size()]; >+ Iterator entries = map.values().iterator(); > for (int i = 0; entries.hasNext(); i++) { > unknowns[i] = (Unknown) entries.next(); > } >- unknown_attributes.clear(); >+ map.clear(); > return unknowns; > } > >@@ -82,7 +87,7 @@ > this.bytes = bytes; > name = ((ConstantUtf8) constant_pool.getConstant(name_index, Constants.CONSTANT_Utf8)) > .getBytes(); >- unknown_attributes.put(name, this); >+ ((Map) unknown_attributes.get()).put(name, this); > } > > >diff -ru v0/src/java/org/apache/bcel/classfile/Utility.java v2a/src/java/org/apache/bcel/classfile/Utility.java >--- v0/src/java/org/apache/bcel/classfile/Utility.java 2006-06-02 20:48:24.000000000 -0700 >+++ v2a/src/java/org/apache/bcel/classfile/Utility.java 2007-03-14 14:44:14.693027000 -0700 >@@ -62,7 +62,8 @@ > * Read by methodSignatureToString(). > * Set by side effect,but only internally. > */ >- private static boolean wide = false; /* The `WIDE' instruction is used in the >+ private static ThreadLocal wide = new ThreadLocal(); >+ /* The `WIDE' instruction is used in the > * byte code to allow 16-bit wide indices > * for local variables. This opcode > * precedes an `ILOAD', e.g.. The opcode >@@ -285,9 +286,9 @@ > case Constants.LLOAD: > case Constants.LSTORE: > case Constants.RET: >- if (wide) { >+ if (wide.get() != null) { > vindex = bytes.readUnsignedShort(); >- wide = false; // Clear flag >+ wide.set(null); // Clear flag > } else { > vindex = bytes.readUnsignedByte(); > } >@@ -299,7 +300,7 @@ > * the following opcode. > */ > case Constants.WIDE: >- wide = true; >+ wide.set(Boolean.TRUE); > buf.append("\t(wide)"); > break; > /* Array of basic type. >@@ -386,10 +387,10 @@ > /* Increment local variable. > */ > case Constants.IINC: >- if (wide) { >+ if (wide.get() != null) { > vindex = bytes.readUnsignedShort(); > constant = bytes.readShort(); >- wide = false; >+ wide.set(null); > } else { > vindex = bytes.readUnsignedByte(); > constant = bytes.readByte(); >diff -ru v0/src/java/org/apache/bcel/generic/BranchHandle.java v2a/src/java/org/apache/bcel/generic/BranchHandle.java >--- v0/src/java/org/apache/bcel/generic/BranchHandle.java 2006-06-02 20:48:24.000000000 -0700 >+++ v2a/src/java/org/apache/bcel/generic/BranchHandle.java 2007-03-14 14:44:14.871200000 -0700 >@@ -40,15 +40,15 @@ > > /** Factory methods. > */ >- private static BranchHandle bh_list = null; // List of reusable handles >+ private static ThreadLocal bh_list = new ThreadLocal(); // List of reusable handles > > > static final BranchHandle getBranchHandle( BranchInstruction i ) { >- if (bh_list == null) { >+ if (bh_list.get() == null) { > return new BranchHandle(i); > } >- BranchHandle bh = bh_list; >- bh_list = (BranchHandle) bh.next; >+ BranchHandle bh = (BranchHandle) bh_list.get(); >+ bh_list.set(bh.next); > bh.setInstruction(i); > return bh; > } >@@ -57,8 +57,8 @@ > /** Handle adds itself to the list of resuable handles. > */ > protected void addHandle() { >- next = bh_list; >- bh_list = this; >+ next = (BranchHandle) bh_list.get(); >+ bh_list.set(this); > } > > >diff -ru v0/src/java/org/apache/bcel/generic/ClassGen.java v2a/src/java/org/apache/bcel/generic/ClassGen.java >--- v0/src/java/org/apache/bcel/generic/ClassGen.java 2006-06-02 20:48:23.000000000 -0700 >+++ v2a/src/java/org/apache/bcel/generic/ClassGen.java 2007-03-14 14:44:14.908198000 -0700 >@@ -50,7 +50,8 @@ > private List method_vec = new ArrayList(); > private List attribute_vec = new ArrayList(); > private List interface_vec = new ArrayList(); >- private static BCELComparator _cmp = new BCELComparator() { >+ >+ private static final BCELComparator DEFAULT_CMP = new BCELComparator() { > > public boolean equals( Object o1, Object o2 ) { > ClassGen THIS = (ClassGen) o1; >@@ -65,6 +66,12 @@ > } > }; > >+ private static ThreadLocal _cmp = new ThreadLocal() { >+ protected Object initialValue() { >+ return DEFAULT_CMP; >+ } >+ }; >+ > > /** Convenience constructor to set up some important values initially. > * >@@ -505,7 +512,7 @@ > * @return Comparison strategy object > */ > public static BCELComparator getComparator() { >- return _cmp; >+ return (BCELComparator) _cmp.get(); > } > > >@@ -513,7 +520,7 @@ > * @param comparator Comparison strategy object > */ > public static void setComparator( BCELComparator comparator ) { >- _cmp = comparator; >+ _cmp.set(comparator); > } > > >@@ -525,7 +532,7 @@ > * @see java.lang.Object#equals(java.lang.Object) > */ > public boolean equals( Object obj ) { >- return _cmp.equals(this, obj); >+ return getComparator().equals(this, obj); > } > > >@@ -536,6 +543,6 @@ > * @see java.lang.Object#hashCode() > */ > public int hashCode() { >- return _cmp.hashCode(this); >+ return getComparator().hashCode(this); > } > } >diff -ru v0/src/java/org/apache/bcel/generic/FieldGen.java v2a/src/java/org/apache/bcel/generic/FieldGen.java >--- v0/src/java/org/apache/bcel/generic/FieldGen.java 2006-06-02 20:48:24.000000000 -0700 >+++ v2a/src/java/org/apache/bcel/generic/FieldGen.java 2007-03-14 14:44:15.027195000 -0700 >@@ -41,7 +41,7 @@ > public class FieldGen extends FieldGenOrMethodGen { > > private Object value = null; >- private static BCELComparator _cmp = new BCELComparator() { >+ private static final BCELComparator DEFAULT_CMP = new BCELComparator() { > > public boolean equals( Object o1, Object o2 ) { > FieldGen THIS = (FieldGen) o1; >@@ -57,6 +57,11 @@ > } > }; > >+ private static ThreadLocal _cmp = new ThreadLocal() { >+ protected Object initialValue() { >+ return DEFAULT_CMP; >+ } >+ }; > > /** > * Declare a field. If it is static (isStatic() == true) and has a >@@ -321,7 +326,7 @@ > * @return Comparison strategy object > */ > public static BCELComparator getComparator() { >- return _cmp; >+ return (BCELComparator) _cmp.get(); > } > > >@@ -329,7 +334,7 @@ > * @param comparator Comparison strategy object > */ > public static void setComparator( BCELComparator comparator ) { >- _cmp = comparator; >+ _cmp.set(comparator); > } > > >@@ -341,7 +346,7 @@ > * @see java.lang.Object#equals(java.lang.Object) > */ > public boolean equals( Object obj ) { >- return _cmp.equals(this, obj); >+ return getComparator().equals(this, obj); > } > > >@@ -352,6 +357,6 @@ > * @see java.lang.Object#hashCode() > */ > public int hashCode() { >- return _cmp.hashCode(this); >+ return getComparator().hashCode(this); > } > } >diff -ru v0/src/java/org/apache/bcel/generic/InstructionHandle.java v2a/src/java/org/apache/bcel/generic/InstructionHandle.java >--- v0/src/java/org/apache/bcel/generic/InstructionHandle.java 2006-06-02 20:48:24.000000000 -0700 >+++ v2a/src/java/org/apache/bcel/generic/InstructionHandle.java 2007-03-14 14:44:15.224189000 -0700 >@@ -99,17 +99,17 @@ > setInstruction(i); > } > >- private static InstructionHandle ih_list = null; // List of reusable handles >+ private static ThreadLocal ih_list = new ThreadLocal(); // List of reusable handles > > > /** Factory method. > */ > static final InstructionHandle getInstructionHandle( Instruction i ) { >- if (ih_list == null) { >+ if (ih_list.get() == null) { > return new InstructionHandle(i); > } else { >- InstructionHandle ih = ih_list; >- ih_list = ih.next; >+ InstructionHandle ih = (InstructionHandle) ih_list.get(); >+ ih_list.set(ih.next); > ih.setInstruction(i); > return ih; > } >@@ -152,8 +152,8 @@ > /** Overridden in BranchHandle > */ > protected void addHandle() { >- next = ih_list; >- ih_list = this; >+ next = (InstructionHandle) ih_list.get(); >+ ih_list.set(this); > } > > >diff -ru v0/src/java/org/apache/bcel/generic/Instruction.java v2a/src/java/org/apache/bcel/generic/Instruction.java >--- v0/src/java/org/apache/bcel/generic/Instruction.java 2006-06-02 20:48:24.000000000 -0700 >+++ v2a/src/java/org/apache/bcel/generic/Instruction.java 2007-03-14 14:44:15.205189000 -0700 >@@ -34,7 +34,11 @@ > > protected short length = 1; // Length of instruction in bytes > protected short opcode = -1; // Opcode number >- private static InstructionComparator cmp = InstructionComparator.DEFAULT; >+ private static ThreadLocal cmp = new ThreadLocal() { >+ protected Object initialValue() { >+ return InstructionComparator.DEFAULT; >+ } >+ }; > > > /** >@@ -272,14 +276,14 @@ > * @return currently used comparator for equals() > */ > public static InstructionComparator getComparator() { >- return cmp; >+ return (InstructionComparator) cmp.get(); > } > > > /** Set comparator to be used for equals(). > */ > public static void setComparator( InstructionComparator c ) { >- cmp = c; >+ cmp.set(c); > } > > >@@ -287,6 +291,6 @@ > * @return true if that is an Instruction and has the same opcode > */ > public boolean equals( Object that ) { >- return (that instanceof Instruction) ? cmp.equals(this, (Instruction) that) : false; >+ return (that instanceof Instruction) ? getComparator().equals(this, (Instruction) that) : false; > } > } >diff -ru v0/src/java/org/apache/bcel/generic/MethodGen.java v2a/src/java/org/apache/bcel/generic/MethodGen.java >--- v0/src/java/org/apache/bcel/generic/MethodGen.java 2006-06-02 20:48:24.000000000 -0700 >+++ v2a/src/java/org/apache/bcel/generic/MethodGen.java 2007-03-14 14:44:15.470197000 -0700 >@@ -64,7 +64,8 @@ > private List exception_vec = new ArrayList(); > private List throws_vec = new ArrayList(); > private List code_attrs_vec = new ArrayList(); >- private static BCELComparator _cmp = new BCELComparator() { >+ >+ private static final BCELComparator DEFAULT_CMP = new BCELComparator() { > > public boolean equals( Object o1, Object o2 ) { > MethodGen THIS = (MethodGen) o1; >@@ -80,6 +81,11 @@ > } > }; > >+ private static ThreadLocal _cmp = new ThreadLocal() { >+ protected Object initialValue() { >+ return DEFAULT_CMP; >+ } >+ }; > > /** > * Declare method. If the method is non-static the constructor >@@ -1050,7 +1056,7 @@ > * @return Comparison strategy object > */ > public static BCELComparator getComparator() { >- return _cmp; >+ return (BCELComparator) _cmp.get(); > } > > >@@ -1058,7 +1064,7 @@ > * @param comparator Comparison strategy object > */ > public static void setComparator( BCELComparator comparator ) { >- _cmp = comparator; >+ _cmp.set(comparator); > } > > >@@ -1070,7 +1076,7 @@ > * @see java.lang.Object#equals(java.lang.Object) > */ > public boolean equals( Object obj ) { >- return _cmp.equals(this, obj); >+ return getComparator().equals(this, obj); > } > > >@@ -1081,6 +1087,6 @@ > * @see java.lang.Object#hashCode() > */ > public int hashCode() { >- return _cmp.hashCode(this); >+ return getComparator().hashCode(this); > } > } >diff -ru v0/src/java/org/apache/bcel/Repository.java v2a/src/java/org/apache/bcel/Repository.java >--- v0/src/java/org/apache/bcel/Repository.java 2006-06-02 20:48:24.000000000 -0700 >+++ v2a/src/java/org/apache/bcel/Repository.java 2007-03-14 14:44:16.209382000 -0700 >@@ -34,20 +34,25 @@ > */ > public abstract class Repository { > >- private static org.apache.bcel.util.Repository _repository = SyntheticRepository.getInstance(); >+ private static ThreadLocal _repository = >+ new ThreadLocal() { >+ protected Object initialValue() { >+ return SyntheticRepository.getInstance(); >+ } >+ }; > > > /** @return currently used repository instance > */ > public static org.apache.bcel.util.Repository getRepository() { >- return _repository; >+ return (org.apache.bcel.util.Repository) _repository.get(); > } > > > /** Set repository instance to be used for class loading > */ > public static void setRepository( org.apache.bcel.util.Repository rep ) { >- _repository = rep; >+ _repository.set(rep); > } > > >@@ -59,7 +64,7 @@ > * parsed correctly > */ > public static JavaClass lookupClass( String class_name ) throws ClassNotFoundException { >- return _repository.loadClass(class_name); >+ return getRepository().loadClass(class_name); > } > > >@@ -71,7 +76,7 @@ > * parsed correctly > */ > public static JavaClass lookupClass( Class clazz ) throws ClassNotFoundException { >- return _repository.loadClass(clazz); >+ return getRepository().loadClass(clazz); > } > > >@@ -82,7 +87,7 @@ > */ > public static ClassPath.ClassFile lookupClassFile( String class_name ) { > try { >- ClassPath path = _repository.getClassPath(); >+ ClassPath path = getRepository().getClassPath(); > if (path == null) { > return null; > } >@@ -96,7 +101,7 @@ > /** Clear the repository. > */ > public static void clearCache() { >- _repository.clear(); >+ getRepository().clear(); > } > > >@@ -106,8 +111,8 @@ > * @return old entry in repository > */ > public static JavaClass addClass( JavaClass clazz ) { >- JavaClass old = _repository.findClass(clazz.getClassName()); >- _repository.storeClass(clazz); >+ JavaClass old = getRepository().findClass(clazz.getClassName()); >+ getRepository().storeClass(clazz); > return old; > } > >@@ -116,7 +121,7 @@ > * Remove class with given (fully qualified) name from repository. > */ > public static void removeClass( String clazz ) { >- _repository.removeClass(_repository.findClass(clazz)); >+ getRepository().removeClass(getRepository().findClass(clazz)); > } > > >@@ -124,7 +129,7 @@ > * Remove given class from repository. > */ > public static void removeClass( JavaClass clazz ) { >- _repository.removeClass(clazz); >+ getRepository().removeClass(clazz); > } > > >diff -ru v0/src/java/org/apache/bcel/util/SyntheticRepository.java v2a/src/java/org/apache/bcel/util/SyntheticRepository.java >--- v0/src/java/org/apache/bcel/util/SyntheticRepository.java 2006-06-02 20:48:24.000000000 -0700 >+++ v2a/src/java/org/apache/bcel/util/SyntheticRepository.java 2007-03-14 14:44:15.715238000 -0700 >@@ -48,7 +48,11 @@ > public class SyntheticRepository implements Repository { > > private static final String DEFAULT_PATH = ClassPath.getClassPath(); >- private static Map _instances = new HashMap(); // CLASSPATH X REPOSITORY >+ private static ThreadLocal _instances = new ThreadLocal() { >+ protected Object initialValue() { >+ return new HashMap(); >+ } >+ }; > private ClassPath _path = null; > private Map _loadedClasses = new HashMap(); // CLASSNAME X JAVACLASS > >@@ -64,10 +68,11 @@ > > > public static SyntheticRepository getInstance( ClassPath classPath ) { >- SyntheticRepository rep = (SyntheticRepository) _instances.get(classPath); >+ Map map = (Map) _instances.get(); >+ SyntheticRepository rep = (SyntheticRepository) map.get(classPath); > if (rep == null) { > rep = new SyntheticRepository(classPath); >- _instances.put(classPath, rep); >+ map.put(classPath, rep); > } > return rep; > } >diff -ru v0/src/java/org/apache/bcel/verifier/structurals/ExecutionVisitor.java v2a/src/java/org/apache/bcel/verifier/structurals/ExecutionVisitor.java >--- v0/src/java/org/apache/bcel/verifier/structurals/ExecutionVisitor.java 2006-06-02 20:48:24.000000000 -0700 >+++ v2a/src/java/org/apache/bcel/verifier/structurals/ExecutionVisitor.java 2007-03-14 14:44:16.002381000 -0700 >@@ -715,8 +715,8 @@ > public void visitINVOKESPECIAL(INVOKESPECIAL o){ > if (o.getMethodName(cpg).equals(Constants.CONSTRUCTOR_NAME)){ > UninitializedObjectType t = (UninitializedObjectType) stack().peek(o.getArgumentTypes(cpg).length); >- if (t == Frame._this){ >- Frame._this = null; >+ if (t == Frame._this.get()){ >+ Frame._this.set(null); > } > stack().initializeObject(t); > locals().initializeObject(t); >diff -ru v0/src/java/org/apache/bcel/verifier/structurals/Frame.java v2a/src/java/org/apache/bcel/verifier/structurals/Frame.java >--- v0/src/java/org/apache/bcel/verifier/structurals/Frame.java 2006-06-02 20:48:24.000000000 -0700 >+++ v2a/src/java/org/apache/bcel/verifier/structurals/Frame.java 2007-03-14 14:44:16.012385000 -0700 >@@ -34,7 +34,7 @@ > * initialized invoking another constructor later. > * NULL means the instance already *is* initialized. > */ >- protected static UninitializedObjectType _this; >+ protected static ThreadLocal _this = new ThreadLocal(); > > /** > * >diff -ru v0/src/java/org/apache/bcel/verifier/structurals/InstConstraintVisitor.java v2a/src/java/org/apache/bcel/verifier/structurals/InstConstraintVisitor.java >--- v0/src/java/org/apache/bcel/verifier/structurals/InstConstraintVisitor.java 2006-06-02 20:48:24.000000000 -0700 >+++ v2a/src/java/org/apache/bcel/verifier/structurals/InstConstraintVisitor.java 2007-03-14 14:44:16.038383000 -0700 >@@ -2644,7 +2644,8 @@ > */ > public void visitRETURN(RETURN o){ > if (mg.getName().equals(Constants.CONSTRUCTOR_NAME)){// If we leave an <init> method >- if ((Frame._this != null) && (!(mg.getClassName().equals(Type.OBJECT.getClassName()))) ) { >+ UninitializedObjectType _this = (UninitializedObjectType) Frame._this.get(); >+ if ((_this != null) && (!(mg.getClassName().equals(Type.OBJECT.getClassName()))) ) { > constraintViolated(o, "Leaving a constructor that itself did not call a constructor."); > } > } >diff -ru v0/src/java/org/apache/bcel/verifier/structurals/Pass3bVerifier.java v2a/src/java/org/apache/bcel/verifier/structurals/Pass3bVerifier.java >--- v0/src/java/org/apache/bcel/verifier/structurals/Pass3bVerifier.java 2006-06-02 20:48:23.000000000 -0700 >+++ v2a/src/java/org/apache/bcel/verifier/structurals/Pass3bVerifier.java 2007-03-14 14:44:16.071389000 -0700 >@@ -301,11 +301,12 @@ > Frame f = new Frame(mg.getMaxLocals(),mg.getMaxStack()); > if ( !mg.isStatic() ){ > if (mg.getName().equals(Constants.CONSTRUCTOR_NAME)){ >- Frame._this = new UninitializedObjectType(new ObjectType(jc.getClassName())); >- f.getLocals().set(0, Frame._this); >+ UninitializedObjectType _this = new UninitializedObjectType(new ObjectType(jc.getClassName())); >+ Frame._this.set(_this); >+ f.getLocals().set(0, _this); > } > else{ >- Frame._this = null; >+ Frame._this.set(null); > f.getLocals().set(0, new ObjectType(jc.getClassName())); > } > } >diff -ru v0/src/java/org/apache/bcel/verifier/VerifierFactory.java v2a/src/java/org/apache/bcel/verifier/VerifierFactory.java >--- v0/src/java/org/apache/bcel/verifier/VerifierFactory.java 2006-06-02 20:48:24.000000000 -0700 >+++ v2a/src/java/org/apache/bcel/verifier/VerifierFactory.java 2007-03-14 14:44:16.147389000 -0700 >@@ -37,12 +37,20 @@ > /** > * The HashMap that holds the data about the already-constructed Verifier instances. > */ >- private static Map hashMap = new HashMap(); >+ private static ThreadLocal hashMap = new ThreadLocal() { >+ protected Object initialValue() { >+ return new HashMap(); >+ } >+ }; >+ > /** > * The VerifierFactoryObserver instances that observe the VerifierFactory. > */ >- private static List observers = new Vector(); >- >+ private static ThreadLocal observers = new ThreadLocal() { >+ protected Object initialValue() { >+ return new Vector(); >+ } >+ }; > > /** > * The VerifierFactory is not instantiable. >@@ -57,10 +65,11 @@ > * @return the (only) verifier responsible for the class with the given name. > */ > public static Verifier getVerifier( String fully_qualified_classname ) { >- Verifier v = (Verifier) (hashMap.get(fully_qualified_classname)); >+ HashMap map = (HashMap) hashMap.get(); >+ Verifier v = (Verifier) (map.get(fully_qualified_classname)); > if (v == null) { > v = new Verifier(fully_qualified_classname); >- hashMap.put(fully_qualified_classname, v); >+ map.put(fully_qualified_classname, v); > notify(fully_qualified_classname); > } > return v; >@@ -72,7 +81,7 @@ > */ > private static void notify( String fully_qualified_classname ) { > // notify the observers >- Iterator i = observers.iterator(); >+ Iterator i = ((Vector) observers.get()).iterator(); > while (i.hasNext()) { > VerifierFactoryObserver vfo = (VerifierFactoryObserver) i.next(); > vfo.update(fully_qualified_classname); >@@ -88,8 +97,9 @@ > * referenced class files. > */ > public static Verifier[] getVerifiers() { >- Verifier[] vs = new Verifier[hashMap.values().size()]; >- return (Verifier[]) (hashMap.values().toArray(vs)); // Because vs is big enough, vs is used to store the values into and returned! >+ HashMap map = (HashMap) hashMap.get(); >+ Verifier[] vs = new Verifier[map.values().size()]; >+ return (Verifier[]) (map.values().toArray(vs)); // Because vs is big enough, vs is used to store the values into and returned! > } > > >@@ -97,7 +107,7 @@ > * Adds the VerifierFactoryObserver o to the list of observers. > */ > public static void attach( VerifierFactoryObserver o ) { >- observers.add(o); >+ ((Vector) observers.get()).add(o); > } > > >@@ -105,6 +115,6 @@ > * Removes the VerifierFactoryObserver o from the list of observers. > */ > public static void detach( VerifierFactoryObserver o ) { >- observers.remove(o); >+ ((Vector) observers.get()).remove(o); > } > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 42552
: 20294