Wed, 16 Oct 2013 16:33:04 -0400
8026286: Improper locking of annotation queues causes assertion failures.
8026063: Calls to annotate.flush() cause incorrect type annotations to be generated.
Summary: Fix locking in ClassReader.java
Reviewed-by: jfranck
duke@1 | 1 | /* |
jjg@1339 | 2 | * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. |
duke@1 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@1 | 4 | * |
duke@1 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@1 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@554 | 7 | * published by the Free Software Foundation. Oracle designates this |
duke@1 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@554 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
duke@1 | 10 | * |
duke@1 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@1 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@1 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@1 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@1 | 15 | * accompanied this code). |
duke@1 | 16 | * |
duke@1 | 17 | * You should have received a copy of the GNU General Public License version |
duke@1 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@1 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@1 | 20 | * |
ohair@554 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 23 | * questions. |
duke@1 | 24 | */ |
duke@1 | 25 | |
duke@1 | 26 | package com.sun.tools.javac.util; |
duke@1 | 27 | |
duke@1 | 28 | import java.io.*; |
duke@1 | 29 | |
duke@1 | 30 | /** A byte buffer is a flexible array which grows when elements are |
duke@1 | 31 | * appended. There are also methods to append names to byte buffers |
duke@1 | 32 | * and to convert byte buffers to names. |
duke@1 | 33 | * |
jjg@581 | 34 | * <p><b>This is NOT part of any supported API. |
jjg@581 | 35 | * If you write code that depends on this, you do so at your own risk. |
duke@1 | 36 | * This code and its internal interfaces are subject to change or |
duke@1 | 37 | * deletion without notice.</b> |
duke@1 | 38 | */ |
duke@1 | 39 | public class ByteBuffer { |
duke@1 | 40 | |
duke@1 | 41 | /** An array holding the bytes in this buffer; can be grown. |
duke@1 | 42 | */ |
duke@1 | 43 | public byte[] elems; |
duke@1 | 44 | |
duke@1 | 45 | /** The current number of defined bytes in this buffer. |
duke@1 | 46 | */ |
duke@1 | 47 | public int length; |
duke@1 | 48 | |
duke@1 | 49 | /** Create a new byte buffer. |
duke@1 | 50 | */ |
duke@1 | 51 | public ByteBuffer() { |
duke@1 | 52 | this(64); |
duke@1 | 53 | } |
duke@1 | 54 | |
duke@1 | 55 | /** Create a new byte buffer with an initial elements array |
duke@1 | 56 | * of given size. |
duke@1 | 57 | */ |
duke@1 | 58 | public ByteBuffer(int initialSize) { |
duke@1 | 59 | elems = new byte[initialSize]; |
duke@1 | 60 | length = 0; |
duke@1 | 61 | } |
duke@1 | 62 | |
duke@1 | 63 | /** Append byte to this buffer. |
duke@1 | 64 | */ |
duke@1 | 65 | public void appendByte(int b) { |
jjg@1339 | 66 | elems = ArrayUtils.ensureCapacity(elems, length); |
duke@1 | 67 | elems[length++] = (byte)b; |
duke@1 | 68 | } |
duke@1 | 69 | |
duke@1 | 70 | /** Append `len' bytes from byte array, |
duke@1 | 71 | * starting at given `start' offset. |
duke@1 | 72 | */ |
duke@1 | 73 | public void appendBytes(byte[] bs, int start, int len) { |
jjg@1339 | 74 | elems = ArrayUtils.ensureCapacity(elems, length + len); |
duke@1 | 75 | System.arraycopy(bs, start, elems, length, len); |
duke@1 | 76 | length += len; |
duke@1 | 77 | } |
duke@1 | 78 | |
duke@1 | 79 | /** Append all bytes from given byte array. |
duke@1 | 80 | */ |
duke@1 | 81 | public void appendBytes(byte[] bs) { |
duke@1 | 82 | appendBytes(bs, 0, bs.length); |
duke@1 | 83 | } |
duke@1 | 84 | |
duke@1 | 85 | /** Append a character as a two byte number. |
duke@1 | 86 | */ |
duke@1 | 87 | public void appendChar(int x) { |
jjg@1339 | 88 | elems = ArrayUtils.ensureCapacity(elems, length + 1); |
duke@1 | 89 | elems[length ] = (byte)((x >> 8) & 0xFF); |
duke@1 | 90 | elems[length+1] = (byte)((x ) & 0xFF); |
duke@1 | 91 | length = length + 2; |
duke@1 | 92 | } |
duke@1 | 93 | |
duke@1 | 94 | /** Append an integer as a four byte number. |
duke@1 | 95 | */ |
duke@1 | 96 | public void appendInt(int x) { |
jjg@1339 | 97 | elems = ArrayUtils.ensureCapacity(elems, length + 3); |
duke@1 | 98 | elems[length ] = (byte)((x >> 24) & 0xFF); |
duke@1 | 99 | elems[length+1] = (byte)((x >> 16) & 0xFF); |
duke@1 | 100 | elems[length+2] = (byte)((x >> 8) & 0xFF); |
duke@1 | 101 | elems[length+3] = (byte)((x ) & 0xFF); |
duke@1 | 102 | length = length + 4; |
duke@1 | 103 | } |
duke@1 | 104 | |
duke@1 | 105 | /** Append a long as an eight byte number. |
duke@1 | 106 | */ |
duke@1 | 107 | public void appendLong(long x) { |
duke@1 | 108 | ByteArrayOutputStream buffer = new ByteArrayOutputStream(8); |
duke@1 | 109 | DataOutputStream bufout = new DataOutputStream(buffer); |
duke@1 | 110 | try { |
duke@1 | 111 | bufout.writeLong(x); |
duke@1 | 112 | appendBytes(buffer.toByteArray(), 0, 8); |
duke@1 | 113 | } catch (IOException e) { |
duke@1 | 114 | throw new AssertionError("write"); |
duke@1 | 115 | } |
duke@1 | 116 | } |
duke@1 | 117 | |
duke@1 | 118 | /** Append a float as a four byte number. |
duke@1 | 119 | */ |
duke@1 | 120 | public void appendFloat(float x) { |
duke@1 | 121 | ByteArrayOutputStream buffer = new ByteArrayOutputStream(4); |
duke@1 | 122 | DataOutputStream bufout = new DataOutputStream(buffer); |
duke@1 | 123 | try { |
duke@1 | 124 | bufout.writeFloat(x); |
duke@1 | 125 | appendBytes(buffer.toByteArray(), 0, 4); |
duke@1 | 126 | } catch (IOException e) { |
duke@1 | 127 | throw new AssertionError("write"); |
duke@1 | 128 | } |
duke@1 | 129 | } |
duke@1 | 130 | |
duke@1 | 131 | /** Append a double as a eight byte number. |
duke@1 | 132 | */ |
duke@1 | 133 | public void appendDouble(double x) { |
duke@1 | 134 | ByteArrayOutputStream buffer = new ByteArrayOutputStream(8); |
duke@1 | 135 | DataOutputStream bufout = new DataOutputStream(buffer); |
duke@1 | 136 | try { |
duke@1 | 137 | bufout.writeDouble(x); |
duke@1 | 138 | appendBytes(buffer.toByteArray(), 0, 8); |
duke@1 | 139 | } catch (IOException e) { |
duke@1 | 140 | throw new AssertionError("write"); |
duke@1 | 141 | } |
duke@1 | 142 | } |
duke@1 | 143 | |
duke@1 | 144 | /** Append a name. |
duke@1 | 145 | */ |
duke@1 | 146 | public void appendName(Name name) { |
jjg@113 | 147 | appendBytes(name.getByteArray(), name.getByteOffset(), name.getByteLength()); |
duke@1 | 148 | } |
duke@1 | 149 | |
duke@1 | 150 | /** Reset to zero length. |
duke@1 | 151 | */ |
duke@1 | 152 | public void reset() { |
duke@1 | 153 | length = 0; |
duke@1 | 154 | } |
duke@1 | 155 | |
duke@1 | 156 | /** Convert contents to name. |
duke@1 | 157 | */ |
jjg@113 | 158 | public Name toName(Names names) { |
duke@1 | 159 | return names.fromUtf(elems, 0, length); |
duke@1 | 160 | } |
duke@1 | 161 | } |