equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 1999, 2009, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
75 public class ClassReader implements Completer { |
75 public class ClassReader implements Completer { |
76 /** The context key for the class reader. */ |
76 /** The context key for the class reader. */ |
77 protected static final Context.Key<ClassReader> classReaderKey = |
77 protected static final Context.Key<ClassReader> classReaderKey = |
78 new Context.Key<ClassReader>(); |
78 new Context.Key<ClassReader>(); |
79 |
79 |
|
80 public static final int INITIAL_BUFFER_SIZE = 0x0fff0; |
|
81 |
80 Annotate annotate; |
82 Annotate annotate; |
81 |
83 |
82 /** Switch: verbose output. |
84 /** Switch: verbose output. |
83 */ |
85 */ |
84 boolean verbose; |
86 boolean verbose; |
183 */ |
185 */ |
184 protected Symbol currentOwner = null; |
186 protected Symbol currentOwner = null; |
185 |
187 |
186 /** The buffer containing the currently read class file. |
188 /** The buffer containing the currently read class file. |
187 */ |
189 */ |
188 byte[] buf = new byte[0x0fff0]; |
190 byte[] buf = new byte[INITIAL_BUFFER_SIZE]; |
189 |
191 |
190 /** The current input pointer. |
192 /** The current input pointer. |
191 */ |
193 */ |
192 int bp; |
194 int bp; |
193 |
195 |
2417 * should be reported. |
2419 * should be reported. |
2418 */ |
2420 */ |
2419 } |
2421 } |
2420 } |
2422 } |
2421 } |
2423 } |
|
2424 /* |
|
2425 * ensureCapacity will increase the buffer as needed, taking note that |
|
2426 * the new buffer will always be greater than the needed and never |
|
2427 * exactly equal to the needed size or bp. If equal then the read (above) |
|
2428 * will infinitely loop as buf.length - bp == 0. |
|
2429 */ |
2422 private static byte[] ensureCapacity(byte[] buf, int needed) { |
2430 private static byte[] ensureCapacity(byte[] buf, int needed) { |
2423 if (buf.length < needed) { |
2431 if (buf.length <= needed) { |
2424 byte[] old = buf; |
2432 byte[] old = buf; |
2425 buf = new byte[Integer.highestOneBit(needed) << 1]; |
2433 buf = new byte[Integer.highestOneBit(needed) << 1]; |
2426 System.arraycopy(old, 0, buf, 0, old.length); |
2434 System.arraycopy(old, 0, buf, 0, old.length); |
2427 } |
2435 } |
2428 return buf; |
2436 return buf; |