7193657: provide internal ArrayUtils class to simplify common usage of arrays in javac

Tue, 25 Sep 2012 13:06:58 -0700

author
jjg
date
Tue, 25 Sep 2012 13:06:58 -0700
changeset 1339
0e5899f09dab
parent 1338
ad2ca2a4ab5e
child 1340
99d23c0ef8ee

7193657: provide internal ArrayUtils class to simplify common usage of arrays in javac
Reviewed-by: mcimadamore, jjg
Contributed-by: vicenterz@yahoo.es

src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/TagletManager.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/api/MultiTaskListener.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/comp/Flow.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/file/Locations.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/jvm/Code.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/jvm/Pool.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/parser/UnicodeReader.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/util/ArrayUtils.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/util/Bits.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/util/ByteBuffer.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/util/SharedNameTable.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javap/StackMapWriter.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/TagletManager.java	Tue Sep 25 11:56:46 2012 +0100
     1.2 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/TagletManager.java	Tue Sep 25 13:06:58 2012 -0700
     1.3 @@ -262,11 +262,7 @@
     1.4                  urls[count++] = url;
     1.5              }
     1.6          }
     1.7 -        if (urls.length != count) {
     1.8 -            URL[] tmp = new URL[count];
     1.9 -            System.arraycopy(urls, 0, tmp, 0, count);
    1.10 -            urls = tmp;
    1.11 -        }
    1.12 +        urls = Arrays.copyOf(urls, count);
    1.13          return urls;
    1.14      }
    1.15  
     2.1 --- a/src/share/classes/com/sun/tools/javac/api/MultiTaskListener.java	Tue Sep 25 11:56:46 2012 +0100
     2.2 +++ b/src/share/classes/com/sun/tools/javac/api/MultiTaskListener.java	Tue Sep 25 13:06:58 2012 -0700
     2.3 @@ -79,10 +79,8 @@
     2.4              if (ccw.unwrap(l) == listener)
     2.5                  throw new IllegalStateException();
     2.6          }
     2.7 -        TaskListener[] newListeners = new TaskListener[listeners.length + 1];
     2.8 -        System.arraycopy(listeners, 0, newListeners, 0, listeners.length);
     2.9 -        newListeners[newListeners.length - 1] = ccw.wrap(listener);
    2.10 -        listeners = newListeners;
    2.11 +        listeners = Arrays.copyOf(listeners, listeners.length + 1);
    2.12 +        listeners[listeners.length - 1] = ccw.wrap(listener);
    2.13      }
    2.14  
    2.15      public void remove(TaskListener listener) {
     3.1 --- a/src/share/classes/com/sun/tools/javac/comp/Flow.java	Tue Sep 25 11:56:46 2012 +0100
     3.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Flow.java	Tue Sep 25 13:06:58 2012 -0700
     3.3 @@ -1318,11 +1318,7 @@
     3.4           *  index into the vars array.
     3.5           */
     3.6          void newVar(VarSymbol sym) {
     3.7 -            if (nextadr == vars.length) {
     3.8 -                VarSymbol[] newvars = new VarSymbol[nextadr * 2];
     3.9 -                System.arraycopy(vars, 0, newvars, 0, nextadr);
    3.10 -                vars = newvars;
    3.11 -            }
    3.12 +            vars = ArrayUtils.ensureCapacity(vars, nextadr);
    3.13              if ((sym.flags() & FINAL) == 0) {
    3.14                  sym.flags_field |= EFFECTIVELY_FINAL;
    3.15              }
     4.1 --- a/src/share/classes/com/sun/tools/javac/file/Locations.java	Tue Sep 25 11:56:46 2012 +0100
     4.2 +++ b/src/share/classes/com/sun/tools/javac/file/Locations.java	Tue Sep 25 13:06:58 2012 -0700
     4.3 @@ -733,11 +733,7 @@
     4.4                  urls[count++] = url;
     4.5              }
     4.6          }
     4.7 -        if (urls.length != count) {
     4.8 -            URL[] tmp = new URL[count];
     4.9 -            System.arraycopy(urls, 0, tmp, 0, count);
    4.10 -            urls = tmp;
    4.11 -        }
    4.12 +        urls = Arrays.copyOf(urls, count);
    4.13          return urls;
    4.14      }
    4.15  
     5.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Code.java	Tue Sep 25 11:56:46 2012 +0100
     5.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Code.java	Tue Sep 25 13:06:58 2012 -0700
     5.3 @@ -314,11 +314,7 @@
     5.4       */
     5.5      private  void emit1(int od) {
     5.6          if (!alive) return;
     5.7 -        if (cp == code.length) {
     5.8 -            byte[] newcode = new byte[cp * 2];
     5.9 -            System.arraycopy(code, 0, newcode, 0, cp);
    5.10 -            code = newcode;
    5.11 -        }
    5.12 +        code = ArrayUtils.ensureCapacity(code, cp);
    5.13          code[cp++] = (byte)od;
    5.14      }
    5.15  
    5.16 @@ -1247,12 +1243,8 @@
    5.17  
    5.18          if (stackMapBuffer == null) {
    5.19              stackMapBuffer = new StackMapFrame[20];
    5.20 -        } else if (stackMapBuffer.length == stackMapBufferSize) {
    5.21 -            StackMapFrame[] newStackMapBuffer =
    5.22 -                new StackMapFrame[stackMapBufferSize << 1];
    5.23 -            System.arraycopy(stackMapBuffer, 0, newStackMapBuffer,
    5.24 -                             0, stackMapBufferSize);
    5.25 -            stackMapBuffer = newStackMapBuffer;
    5.26 +        } else {
    5.27 +            stackMapBuffer = ArrayUtils.ensureCapacity(stackMapBuffer, stackMapBufferSize);
    5.28          }
    5.29          StackMapFrame frame =
    5.30              stackMapBuffer[stackMapBufferSize++] = new StackMapFrame();
    5.31 @@ -1320,12 +1312,10 @@
    5.32  
    5.33          if (stackMapTableBuffer == null) {
    5.34              stackMapTableBuffer = new StackMapTableFrame[20];
    5.35 -        } else if (stackMapTableBuffer.length == stackMapBufferSize) {
    5.36 -            StackMapTableFrame[] newStackMapTableBuffer =
    5.37 -                new StackMapTableFrame[stackMapBufferSize << 1];
    5.38 -            System.arraycopy(stackMapTableBuffer, 0, newStackMapTableBuffer,
    5.39 -                             0, stackMapBufferSize);
    5.40 -            stackMapTableBuffer = newStackMapTableBuffer;
    5.41 +        } else {
    5.42 +            stackMapTableBuffer = ArrayUtils.ensureCapacity(
    5.43 +                                    stackMapTableBuffer,
    5.44 +                                    stackMapBufferSize);
    5.45          }
    5.46          stackMapTableBuffer[stackMapBufferSize++] =
    5.47                  StackMapTableFrame.getInstance(frame, lastFrame.pc, lastFrame.locals, types);
    5.48 @@ -1651,10 +1641,8 @@
    5.49          void lock(int register) {
    5.50              if (locks == null) {
    5.51                  locks = new int[20];
    5.52 -            } else if (locks.length == nlocks) {
    5.53 -                int[] newLocks = new int[locks.length << 1];
    5.54 -                System.arraycopy(locks, 0, newLocks, 0, locks.length);
    5.55 -                locks = newLocks;
    5.56 +            } else {
    5.57 +                locks = ArrayUtils.ensureCapacity(locks, nlocks);
    5.58              }
    5.59              locks[nlocks] = register;
    5.60              nlocks++;
    5.61 @@ -1680,11 +1668,7 @@
    5.62              default:
    5.63                  break;
    5.64              }
    5.65 -            if (stacksize+2 >= stack.length) {
    5.66 -                Type[] newstack = new Type[2*stack.length];
    5.67 -                System.arraycopy(stack, 0, newstack, 0, stack.length);
    5.68 -                stack = newstack;
    5.69 -            }
    5.70 +            stack = ArrayUtils.ensureCapacity(stack, stacksize+2);
    5.71              stack[stacksize++] = t;
    5.72              switch (width(t)) {
    5.73              case 1:
    5.74 @@ -1871,13 +1855,7 @@
    5.75      /** Add a new local variable. */
    5.76      private void addLocalVar(VarSymbol v) {
    5.77          int adr = v.adr;
    5.78 -        if (adr+1 >= lvar.length) {
    5.79 -            int newlength = lvar.length << 1;
    5.80 -            if (newlength <= adr) newlength = adr + 10;
    5.81 -            LocalVar[] new_lvar = new LocalVar[newlength];
    5.82 -            System.arraycopy(lvar, 0, new_lvar, 0, lvar.length);
    5.83 -            lvar = new_lvar;
    5.84 -        }
    5.85 +        lvar = ArrayUtils.ensureCapacity(lvar, adr+1);
    5.86          Assert.checkNull(lvar[adr]);
    5.87          if (pendingJumps != null) resolvePending();
    5.88          lvar[adr] = new LocalVar(v);
    5.89 @@ -1957,11 +1935,8 @@
    5.90          if ((var.sym.flags() & Flags.SYNTHETIC) != 0) return;
    5.91          if (varBuffer == null)
    5.92              varBuffer = new LocalVar[20];
    5.93 -        else if (varBufferSize >= varBuffer.length) {
    5.94 -            LocalVar[] newVarBuffer = new LocalVar[varBufferSize*2];
    5.95 -            System.arraycopy(varBuffer, 0, newVarBuffer, 0, varBuffer.length);
    5.96 -            varBuffer = newVarBuffer;
    5.97 -        }
    5.98 +        else
    5.99 +            varBuffer = ArrayUtils.ensureCapacity(varBuffer, varBufferSize);
   5.100          varBuffer[varBufferSize++] = var;
   5.101      }
   5.102  
     6.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Pool.java	Tue Sep 25 11:56:46 2012 +0100
     6.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Pool.java	Tue Sep 25 13:06:58 2012 -0700
     6.3 @@ -1,5 +1,5 @@
     6.4  /*
     6.5 - * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
     6.6 + * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
     6.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     6.8   *
     6.9   * This code is free software; you can redistribute it and/or modify it
    6.10 @@ -32,6 +32,7 @@
    6.11  import com.sun.tools.javac.code.Symbol;
    6.12  import com.sun.tools.javac.code.Symbol.*;
    6.13  import com.sun.tools.javac.code.Type;
    6.14 +import com.sun.tools.javac.util.ArrayUtils;
    6.15  import com.sun.tools.javac.util.Assert;
    6.16  import com.sun.tools.javac.util.Filter;
    6.17  import com.sun.tools.javac.util.Name;
    6.18 @@ -91,14 +92,6 @@
    6.19          indices.clear();
    6.20      }
    6.21  
    6.22 -    /** Double pool buffer in size.
    6.23 -     */
    6.24 -    private void doublePool() {
    6.25 -        Object[] newpool = new Object[pool.length * 2];
    6.26 -        System.arraycopy(pool, 0, newpool, 0, pool.length);
    6.27 -        pool = newpool;
    6.28 -    }
    6.29 -
    6.30      /** Place an object in the pool, unless it is already there.
    6.31       *  If object is a symbol also enter its owner unless the owner is a
    6.32       *  package.  Return the object's index in the pool.
    6.33 @@ -114,10 +107,10 @@
    6.34  //          System.err.println("put " + value + " " + value.getClass());//DEBUG
    6.35              index = pp;
    6.36              indices.put(value, index);
    6.37 -            if (pp == pool.length) doublePool();
    6.38 +            pool = ArrayUtils.ensureCapacity(pool, pp);
    6.39              pool[pp++] = value;
    6.40              if (value instanceof Long || value instanceof Double) {
    6.41 -                if (pp == pool.length) doublePool();
    6.42 +                pool = ArrayUtils.ensureCapacity(pool, pp);
    6.43                  pool[pp++] = null;
    6.44              }
    6.45          }
     7.1 --- a/src/share/classes/com/sun/tools/javac/parser/UnicodeReader.java	Tue Sep 25 11:56:46 2012 +0100
     7.2 +++ b/src/share/classes/com/sun/tools/javac/parser/UnicodeReader.java	Tue Sep 25 13:06:58 2012 -0700
     7.3 @@ -1,5 +1,5 @@
     7.4  /*
     7.5 - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
     7.6 + * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
     7.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     7.8   *
     7.9   * This code is free software; you can redistribute it and/or modify it
    7.10 @@ -25,13 +25,15 @@
    7.11  
    7.12  package com.sun.tools.javac.parser;
    7.13  
    7.14 +import java.nio.CharBuffer;
    7.15 +import java.util.Arrays;
    7.16 +
    7.17  import com.sun.tools.javac.file.JavacFileManager;
    7.18 +import com.sun.tools.javac.util.ArrayUtils;
    7.19  import com.sun.tools.javac.util.Log;
    7.20  import com.sun.tools.javac.util.Name;
    7.21  import com.sun.tools.javac.util.Names;
    7.22  
    7.23 -import java.nio.CharBuffer;
    7.24 -
    7.25  import static com.sun.tools.javac.util.LayoutCharacters.*;
    7.26  
    7.27  /** The char reader used by the javac lexer/tokenizer. Returns the sequence of
    7.28 @@ -91,9 +93,7 @@
    7.29              if (input.length > 0 && Character.isWhitespace(input[input.length - 1])) {
    7.30                  inputLength--;
    7.31              } else {
    7.32 -                char[] newInput = new char[inputLength + 1];
    7.33 -                System.arraycopy(input, 0, newInput, 0, input.length);
    7.34 -                input = newInput;
    7.35 +                input = Arrays.copyOf(input, inputLength + 1);
    7.36              }
    7.37          }
    7.38          buf = input;
    7.39 @@ -130,11 +130,7 @@
    7.40      /** Append a character to sbuf.
    7.41       */
    7.42      protected void putChar(char ch, boolean scan) {
    7.43 -        if (sp == sbuf.length) {
    7.44 -            char[] newsbuf = new char[sbuf.length * 2];
    7.45 -            System.arraycopy(sbuf, 0, newsbuf, 0, sbuf.length);
    7.46 -            sbuf = newsbuf;
    7.47 -        }
    7.48 +        sbuf = ArrayUtils.ensureCapacity(sbuf, sp);
    7.49          sbuf[sp++] = ch;
    7.50          if (scan)
    7.51              scanChar();
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/share/classes/com/sun/tools/javac/util/ArrayUtils.java	Tue Sep 25 13:06:58 2012 -0700
     8.3 @@ -0,0 +1,87 @@
     8.4 +/*
     8.5 + * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
     8.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     8.7 + *
     8.8 + * This code is free software; you can redistribute it and/or modify it
     8.9 + * under the terms of the GNU General Public License version 2 only, as
    8.10 + * published by the Free Software Foundation.  Oracle designates this
    8.11 + * particular file as subject to the "Classpath" exception as provided
    8.12 + * by Oracle in the LICENSE file that accompanied this code.
    8.13 + *
    8.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    8.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    8.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    8.17 + * version 2 for more details (a copy is included in the LICENSE file that
    8.18 + * accompanied this code).
    8.19 + *
    8.20 + * You should have received a copy of the GNU General Public License version
    8.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    8.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    8.23 + *
    8.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    8.25 + * or visit www.oracle.com if you need additional information or have any
    8.26 + * questions.
    8.27 + */
    8.28 +
    8.29 +package com.sun.tools.javac.util;
    8.30 +
    8.31 +import java.lang.reflect.Array;
    8.32 +
    8.33 +/** <p><b>This is NOT part of any supported API.
    8.34 + *  If you write code that depends on this, you do so at your own risk.
    8.35 + *  This code and its internal interfaces are subject to change or
    8.36 + *  deletion without notice.</b>
    8.37 + */
    8.38 +public class ArrayUtils {
    8.39 +
    8.40 +    private static int calculateNewLength(int currentLength, int maxIndex) {
    8.41 +        while (currentLength < maxIndex + 1)
    8.42 +            currentLength = currentLength * 2;
    8.43 +        return currentLength;
    8.44 +    }
    8.45 +
    8.46 +    public static <T> T[] ensureCapacity(T[] array, int maxIndex) {
    8.47 +        if (maxIndex < array.length) {
    8.48 +            return array;
    8.49 +        } else {
    8.50 +            int newLength = calculateNewLength(array.length, maxIndex);
    8.51 +            @SuppressWarnings("unchecked")
    8.52 +            T[] result = (T[]) Array.newInstance(array.getClass().getComponentType(), newLength);
    8.53 +            System.arraycopy(array, 0, result, 0, array.length);
    8.54 +            return result;
    8.55 +        }
    8.56 +    }
    8.57 +
    8.58 +    public static byte[] ensureCapacity(byte[] array, int maxIndex) {
    8.59 +        if (maxIndex < array.length) {
    8.60 +            return array;
    8.61 +        } else {
    8.62 +            int newLength = calculateNewLength(array.length, maxIndex);
    8.63 +            byte[] result = new byte[newLength];
    8.64 +            System.arraycopy(array, 0, result, 0, array.length);
    8.65 +            return result;
    8.66 +        }
    8.67 +    }
    8.68 +
    8.69 +    public static char[] ensureCapacity(char[] array, int maxIndex) {
    8.70 +        if (maxIndex < array.length) {
    8.71 +            return array;
    8.72 +        } else {
    8.73 +            int newLength = calculateNewLength(array.length, maxIndex);
    8.74 +            char[] result = new char[newLength];
    8.75 +            System.arraycopy(array, 0, result, 0, array.length);
    8.76 +            return result;
    8.77 +        }
    8.78 +    }
    8.79 +
    8.80 +    public static int[] ensureCapacity(int[] array, int maxIndex) {
    8.81 +        if (maxIndex < array.length) {
    8.82 +            return array;
    8.83 +        } else {
    8.84 +            int newLength = calculateNewLength(array.length, maxIndex);
    8.85 +            int[] result = new int[newLength];
    8.86 +            System.arraycopy(array, 0, result, 0, array.length);
    8.87 +            return result;
    8.88 +        }
    8.89 +    }
    8.90 +}
     9.1 --- a/src/share/classes/com/sun/tools/javac/util/Bits.java	Tue Sep 25 11:56:46 2012 +0100
     9.2 +++ b/src/share/classes/com/sun/tools/javac/util/Bits.java	Tue Sep 25 13:06:58 2012 -0700
     9.3 @@ -25,6 +25,8 @@
     9.4  
     9.5  package com.sun.tools.javac.util;
     9.6  
     9.7 +import java.util.Arrays;
     9.8 +
     9.9  /** A class for extensible, mutable bit sets.
    9.10   *
    9.11   *  <p><b>This is NOT part of any supported API.
    9.12 @@ -62,9 +64,7 @@
    9.13  
    9.14      private void sizeTo(int len) {
    9.15          if (bits.length < len) {
    9.16 -            int[] newbits = new int[len];
    9.17 -            System.arraycopy(bits, 0, newbits, 0, bits.length);
    9.18 -            bits = newbits;
    9.19 +            bits = Arrays.copyOf(bits, len);
    9.20          }
    9.21      }
    9.22  
    10.1 --- a/src/share/classes/com/sun/tools/javac/util/ByteBuffer.java	Tue Sep 25 11:56:46 2012 +0100
    10.2 +++ b/src/share/classes/com/sun/tools/javac/util/ByteBuffer.java	Tue Sep 25 13:06:58 2012 -0700
    10.3 @@ -1,5 +1,5 @@
    10.4  /*
    10.5 - * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
    10.6 + * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
    10.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    10.8   *
    10.9   * This code is free software; you can redistribute it and/or modify it
   10.10 @@ -60,16 +60,10 @@
   10.11          length = 0;
   10.12      }
   10.13  
   10.14 -    private void copy(int size) {
   10.15 -        byte[] newelems = new byte[size];
   10.16 -        System.arraycopy(elems, 0, newelems, 0, elems.length);
   10.17 -        elems = newelems;
   10.18 -    }
   10.19 -
   10.20      /** Append byte to this buffer.
   10.21       */
   10.22      public void appendByte(int b) {
   10.23 -        if (length >= elems.length) copy(elems.length * 2);
   10.24 +        elems = ArrayUtils.ensureCapacity(elems, length);
   10.25          elems[length++] = (byte)b;
   10.26      }
   10.27  
   10.28 @@ -77,7 +71,7 @@
   10.29       *  starting at given `start' offset.
   10.30       */
   10.31      public void appendBytes(byte[] bs, int start, int len) {
   10.32 -        while (length + len > elems.length) copy(elems.length * 2);
   10.33 +        elems = ArrayUtils.ensureCapacity(elems, length + len);
   10.34          System.arraycopy(bs, start, elems, length, len);
   10.35          length += len;
   10.36      }
   10.37 @@ -91,7 +85,7 @@
   10.38      /** Append a character as a two byte number.
   10.39       */
   10.40      public void appendChar(int x) {
   10.41 -        while (length + 1 >= elems.length) copy(elems.length * 2);
   10.42 +        elems = ArrayUtils.ensureCapacity(elems, length + 1);
   10.43          elems[length  ] = (byte)((x >>  8) & 0xFF);
   10.44          elems[length+1] = (byte)((x      ) & 0xFF);
   10.45          length = length + 2;
   10.46 @@ -100,7 +94,7 @@
   10.47      /** Append an integer as a four byte number.
   10.48       */
   10.49      public void appendInt(int x) {
   10.50 -        while (length + 3 >= elems.length) copy(elems.length * 2);
   10.51 +        elems = ArrayUtils.ensureCapacity(elems, length + 3);
   10.52          elems[length  ] = (byte)((x >> 24) & 0xFF);
   10.53          elems[length+1] = (byte)((x >> 16) & 0xFF);
   10.54          elems[length+2] = (byte)((x >>  8) & 0xFF);
    11.1 --- a/src/share/classes/com/sun/tools/javac/util/SharedNameTable.java	Tue Sep 25 11:56:46 2012 +0100
    11.2 +++ b/src/share/classes/com/sun/tools/javac/util/SharedNameTable.java	Tue Sep 25 13:06:58 2012 -0700
    11.3 @@ -1,5 +1,5 @@
    11.4  /*
    11.5 - * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
    11.6 + * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
    11.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    11.8   *
    11.9   * This code is free software; you can redistribute it and/or modify it
   11.10 @@ -93,13 +93,7 @@
   11.11      @Override
   11.12      public Name fromChars(char[] cs, int start, int len) {
   11.13          int nc = this.nc;
   11.14 -        byte[] bytes = this.bytes;
   11.15 -        while (nc + len * 3 >= bytes.length) {
   11.16 -            //          System.err.println("doubling name buffer of length " + names.length + " to fit " + len + " chars");//DEBUG
   11.17 -            byte[] newnames = new byte[bytes.length * 2];
   11.18 -            System.arraycopy(bytes, 0, newnames, 0, bytes.length);
   11.19 -            bytes = this.bytes = newnames;
   11.20 -        }
   11.21 +        byte[] bytes = this.bytes = ArrayUtils.ensureCapacity(this.bytes, nc + len * 3);
   11.22          int nbytes = Convert.chars2utf(cs, start, bytes, nc, len) - nc;
   11.23          int h = hashValue(bytes, nc, nbytes) & hashMask;
   11.24          NameImpl n = hashes[h];
   11.25 @@ -133,12 +127,7 @@
   11.26          }
   11.27          if (n == null) {
   11.28              int nc = this.nc;
   11.29 -            while (nc + len > names.length) {
   11.30 -                //              System.err.println("doubling name buffer of length + " + names.length + " to fit " + len + " bytes");//DEBUG
   11.31 -                byte[] newnames = new byte[names.length * 2];
   11.32 -                System.arraycopy(names, 0, newnames, 0, names.length);
   11.33 -                names = this.bytes = newnames;
   11.34 -            }
   11.35 +            names = this.bytes = ArrayUtils.ensureCapacity(names, nc + len);
   11.36              System.arraycopy(cs, start, names, nc, len);
   11.37              n = new NameImpl(this);
   11.38              n.index = nc;
    12.1 --- a/src/share/classes/com/sun/tools/javap/StackMapWriter.java	Tue Sep 25 11:56:46 2012 +0100
    12.2 +++ b/src/share/classes/com/sun/tools/javap/StackMapWriter.java	Tue Sep 25 13:06:58 2012 -0700
    12.3 @@ -1,5 +1,5 @@
    12.4  /*
    12.5 - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
    12.6 + * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
    12.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    12.8   *
    12.9   * This code is free software; you can redistribute it and/or modify it
   12.10 @@ -25,10 +25,11 @@
   12.11  
   12.12  package com.sun.tools.javap;
   12.13  
   12.14 -import com.sun.tools.classfile.AccessFlags;
   12.15 +import java.util.Arrays;
   12.16  import java.util.HashMap;
   12.17  import java.util.Map;
   12.18  
   12.19 +import com.sun.tools.classfile.AccessFlags;
   12.20  import com.sun.tools.classfile.Attribute;
   12.21  import com.sun.tools.classfile.Code_attribute;
   12.22  import com.sun.tools.classfile.ConstantPool;
   12.23 @@ -233,8 +234,7 @@
   12.24              StackMap prev = map.get(pc);
   12.25              assert (prev != null);
   12.26              int k = 251 - frame.frame_type;
   12.27 -            verification_type_info[] new_locals = new verification_type_info[prev.locals.length - k];
   12.28 -            System.arraycopy(prev.locals, 0, new_locals, 0, new_locals.length);
   12.29 +            verification_type_info[] new_locals = Arrays.copyOf(prev.locals, prev.locals.length - k);
   12.30              StackMap m = new StackMap(new_locals, empty);
   12.31              map.put(new_pc, m);
   12.32              return new_pc;

mercurial