Class ArrayUtil


  • public class ArrayUtil
    extends Object
    This is a generated class used internally during the writing of bytecode within the CallSiteWriter logic. This is not a class exposed to users, as is the case with almost all classes in the org.codehaus.groovy packages.

    The purpose is the reduction of the size of the bytecode. Consider creating a three element Object[] with null values:

      ANEWARRAY java/lang/Object    
      DUP
      ICONST_0
      ACONST_NULL
      AASTORE
      DUP
      ICONST_1
      ACONST_NULL
      AASTORE
      DUP
      ICONST_2
      ACONST_NULL
      AASTORE
     
    with ArrayUtils you can have it like this:
      ACONST_NULL
      ACONST_NULL
      ACONST_NULL
      INVOKESTATIC ArrayUtils.createArray(Object,Object,Object)
     
    The number of needed instructions is thus reduced from 15 to 4. For every entry we save 3 bytecode instructions. This allows better readable bytecode and it allows the JIT to see less bytecode to optimize, helping under the inlining threshold here or there.

    So even though the class is ugly, there are good reason to have this in Groovy, even if the class makes absolutely no sense in normal Java. But it is not used in normal Java, but from the bytecode.