You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2015/08/21 12:49:00 UTC

svn commit: r1696930 - in /commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6: Constants.java verifier/statics/Pass3aVerifier.java

Author: sebb
Date: Fri Aug 21 10:48:59 2015
New Revision: 1696930

URL: http://svn.apache.org/r1696930
Log:
Use existing constant instead of magic numbers
Update docs on MAX_CODE_SIZE

Modified:
    commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/Constants.java
    commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/verifier/statics/Pass3aVerifier.java

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/Constants.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/Constants.java?rev=1696930&r1=1696929&r2=1696930&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/Constants.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/Constants.java Fri Aug 21 10:48:59 2015
@@ -337,16 +337,28 @@ public final class Constants {
   public static final String[] INTERFACES_IMPLEMENTED_BY_ARRAYS = {"java.lang.Cloneable", "java.io.Serializable"};
 
   /**
+   * Maximum Constant Pool entries.
    * One of the limitations of the Java Virtual Machine.
-   * @see <a href="http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.11">
-   * The Java Virtual Machine Specification, Second Edition, page 152, chapter 4.10.</a>
+   * @see <a href="http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.11-100-A">
+   * The Java Virtual Machine Specification, Java SE 8 Edition, page 330, chapter 4.11.</a>
    */
   public static final int MAX_CP_ENTRIES     = 65535;
 
   /**
+   * Maximum code size (plus one; the code size must be LESS than this)
    * One of the limitations of the Java Virtual Machine.
-   * @see <a href="http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.11">
-   * The Java Virtual Machine Specification, Second Edition, page 152, chapter 4.10.</a>
+   * Note vmspec2 page 152 ("Limitations") says:
+   * "The amount of code per non-native, non-abstract method is limited to 65536 bytes by
+   * the sizes of the indices in the exception_table of the Code attribute (§4.7.3), 
+   * in the LineNumberTable attribute (§4.7.8), and in the LocalVariableTable attribute (§4.7.9)."
+   * However this should be taken as an upper limit rather than the defined maximum.
+   * On page 134 (4.8.1 Static Constants) of the same spec, it says:
+   * "The value of the code_length item must be less than 65536."
+   * The entry in the Limitations section has been removed from later versions of the spec;
+   * it is not present in the Java SE 8 edition.
+   *
+   * @see <a href="http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.3-300-E">
+   * The Java Virtual Machine Specification, Java SE 8 Edition, page 104, chapter 4.7.</a>
    */
   public static final int MAX_CODE_SIZE      = 65536; //bytes
 

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/verifier/statics/Pass3aVerifier.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/verifier/statics/Pass3aVerifier.java?rev=1696930&r1=1696929&r2=1696930&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/verifier/statics/Pass3aVerifier.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/verifier/statics/Pass3aVerifier.java Fri Aug 21 10:48:59 2015
@@ -340,9 +340,9 @@ public final class Pass3aVerifier extend
         // array in vmspec2), together with pass 1 (reading code_length bytes and
         // interpreting them as code[]). So this must not be checked again here.
 
-        if (! (code.getCode().length < 65536)){// contradicts vmspec2 page 152 ("Limitations"), but is on page 134.
+        if (code.getCode().length >= Constants.MAX_CODE_SIZE){// length must be LESS than the max
             throw new StaticCodeInstructionConstraintException(
-                "Code array in code attribute '"+code+"' too big: must be smaller than 65536 bytes.");
+                "Code array in code attribute '"+code+"' too big: must be smaller than "+Constants.MAX_CODE_SIZE+"65536 bytes.");
         }
 
         // First opcode at offset 0: okay, that's clear. Nothing to do.