< prev index next >

src/java.base/share/classes/jdk/internal/org/objectweb/asm/commons/SerialVersionUIDAdder.java

Print this page
rev 47452 : imported patch jdk-new-asmv6.patch


  63 import java.io.DataOutputStream;
  64 import java.io.IOException;
  65 import java.security.MessageDigest;
  66 import java.util.ArrayList;
  67 import java.util.Arrays;
  68 import java.util.Collection;
  69 
  70 import jdk.internal.org.objectweb.asm.ClassVisitor;
  71 import jdk.internal.org.objectweb.asm.FieldVisitor;
  72 import jdk.internal.org.objectweb.asm.MethodVisitor;
  73 import jdk.internal.org.objectweb.asm.Opcodes;
  74 
  75 /**
  76  * A {@link ClassVisitor} that adds a serial version unique identifier to a
  77  * class if missing. Here is typical usage of this class:
  78  *
  79  * <pre>
  80  *   ClassWriter cw = new ClassWriter(...);
  81  *   ClassVisitor sv = new SerialVersionUIDAdder(cw);
  82  *   ClassVisitor ca = new MyClassAdapter(sv);
  83  *   new ClassReader(originalClass).accept(ca, false);
  84  * </pre>
  85  *
  86  * The SVUID algorithm can be found <a href=
  87  * "http://java.sun.com/j2se/1.4.2/docs/guide/serialization/spec/class.html"
  88  * >http://java.sun.com/j2se/1.4.2/docs/guide/serialization/spec/class.html</a>:
  89  *
  90  * <pre>
  91  * The serialVersionUID is computed using the signature of a stream of bytes
  92  * that reflect the class definition. The National Institute of Standards and
  93  * Technology (NIST) Secure Hash Algorithm (SHA-1) is used to compute a
  94  * signature for the stream. The first two 32-bit quantities are used to form a
  95  * 64-bit hash. A java.lang.DataOutputStream is used to convert primitive data
  96  * types to a sequence of bytes. The values input to the stream are defined by
  97  * the Java Virtual Machine (VM) specification for classes.
  98  *
  99  * The sequence of items in the stream is as follows:
 100  *
 101  * 1. The class name written using UTF encoding.
 102  * 2. The class modifiers written as a 32-bit integer.
 103  * 3. The name of each interface sorted by name written using UTF encoding.


 182      */
 183     private Collection<Item> svuidConstructors;
 184 
 185     /**
 186      * Collection of non-private methods.
 187      */
 188     private Collection<Item> svuidMethods;
 189 
 190     /**
 191      * Creates a new {@link SerialVersionUIDAdder}. <i>Subclasses must not use
 192      * this constructor</i>. Instead, they must use the
 193      * {@link #SerialVersionUIDAdder(int, ClassVisitor)} version.
 194      *
 195      * @param cv
 196      *            a {@link ClassVisitor} to which this visitor will delegate
 197      *            calls.
 198      * @throws IllegalStateException
 199      *             If a subclass calls this constructor.
 200      */
 201     public SerialVersionUIDAdder(final ClassVisitor cv) {
 202         this(Opcodes.ASM5, cv);
 203         if (getClass() != SerialVersionUIDAdder.class) {
 204             throw new IllegalStateException();
 205         }
 206     }
 207 
 208     /**
 209      * Creates a new {@link SerialVersionUIDAdder}.
 210      *
 211      * @param api
 212      *            the ASM API version implemented by this visitor. Must be one
 213      *            of {@link Opcodes#ASM4} or {@link Opcodes#ASM5}.
 214      * @param cv
 215      *            a {@link ClassVisitor} to which this visitor will delegate
 216      *            calls.
 217      */
 218     protected SerialVersionUIDAdder(final int api, final ClassVisitor cv) {
 219         super(api, cv);
 220         svuidFields = new ArrayList<Item>();
 221         svuidConstructors = new ArrayList<Item>();
 222         svuidMethods = new ArrayList<Item>();
 223     }
 224 
 225     // ------------------------------------------------------------------------
 226     // Overridden methods
 227     // ------------------------------------------------------------------------
 228 
 229     /*
 230      * Visit class header and get class name, access , and interfaces
 231      * information (step 1,2, and 3) for SVUID computation.
 232      */
 233     @Override




  63 import java.io.DataOutputStream;
  64 import java.io.IOException;
  65 import java.security.MessageDigest;
  66 import java.util.ArrayList;
  67 import java.util.Arrays;
  68 import java.util.Collection;
  69 
  70 import jdk.internal.org.objectweb.asm.ClassVisitor;
  71 import jdk.internal.org.objectweb.asm.FieldVisitor;
  72 import jdk.internal.org.objectweb.asm.MethodVisitor;
  73 import jdk.internal.org.objectweb.asm.Opcodes;
  74 
  75 /**
  76  * A {@link ClassVisitor} that adds a serial version unique identifier to a
  77  * class if missing. Here is typical usage of this class:
  78  *
  79  * <pre>
  80  *   ClassWriter cw = new ClassWriter(...);
  81  *   ClassVisitor sv = new SerialVersionUIDAdder(cw);
  82  *   ClassVisitor ca = new MyClassAdapter(sv);
  83  *   new ClassReader(orginalClass).accept(ca, false);
  84  * </pre>
  85  *
  86  * The SVUID algorithm can be found <a href=
  87  * "http://java.sun.com/j2se/1.4.2/docs/guide/serialization/spec/class.html"
  88  * >http://java.sun.com/j2se/1.4.2/docs/guide/serialization/spec/class.html</a>:
  89  *
  90  * <pre>
  91  * The serialVersionUID is computed using the signature of a stream of bytes
  92  * that reflect the class definition. The National Institute of Standards and
  93  * Technology (NIST) Secure Hash Algorithm (SHA-1) is used to compute a
  94  * signature for the stream. The first two 32-bit quantities are used to form a
  95  * 64-bit hash. A java.lang.DataOutputStream is used to convert primitive data
  96  * types to a sequence of bytes. The values input to the stream are defined by
  97  * the Java Virtual Machine (VM) specification for classes.
  98  *
  99  * The sequence of items in the stream is as follows:
 100  *
 101  * 1. The class name written using UTF encoding.
 102  * 2. The class modifiers written as a 32-bit integer.
 103  * 3. The name of each interface sorted by name written using UTF encoding.


 182      */
 183     private Collection<Item> svuidConstructors;
 184 
 185     /**
 186      * Collection of non-private methods.
 187      */
 188     private Collection<Item> svuidMethods;
 189 
 190     /**
 191      * Creates a new {@link SerialVersionUIDAdder}. <i>Subclasses must not use
 192      * this constructor</i>. Instead, they must use the
 193      * {@link #SerialVersionUIDAdder(int, ClassVisitor)} version.
 194      *
 195      * @param cv
 196      *            a {@link ClassVisitor} to which this visitor will delegate
 197      *            calls.
 198      * @throws IllegalStateException
 199      *             If a subclass calls this constructor.
 200      */
 201     public SerialVersionUIDAdder(final ClassVisitor cv) {
 202         this(Opcodes.ASM6, cv);
 203         if (getClass() != SerialVersionUIDAdder.class) {
 204             throw new IllegalStateException();
 205         }
 206     }
 207 
 208     /**
 209      * Creates a new {@link SerialVersionUIDAdder}.
 210      *
 211      * @param api
 212      *            the ASM API version implemented by this visitor. Must be one
 213      *            of {@link Opcodes#ASM4}, {@link Opcodes#ASM5} or {@link Opcodes#ASM6}.
 214      * @param cv
 215      *            a {@link ClassVisitor} to which this visitor will delegate
 216      *            calls.
 217      */
 218     protected SerialVersionUIDAdder(final int api, final ClassVisitor cv) {
 219         super(api, cv);
 220         svuidFields = new ArrayList<Item>();
 221         svuidConstructors = new ArrayList<Item>();
 222         svuidMethods = new ArrayList<Item>();
 223     }
 224 
 225     // ------------------------------------------------------------------------
 226     // Overridden methods
 227     // ------------------------------------------------------------------------
 228 
 229     /*
 230      * Visit class header and get class name, access , and interfaces
 231      * information (step 1,2, and 3) for SVUID computation.
 232      */
 233     @Override


< prev index next >