Wed, 17 Jul 2013 14:19:25 +0100
8019340: varargs-related warnings are meaningless on signature-polymorphic methods such as MethodHandle.invokeExact
Summary: Disable certain varargs warnings when compiling polymorphic signature calls
Reviewed-by: jjg
jjg@113 | 1 | /* |
vromero@1772 | 2 | * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. |
jjg@113 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jjg@113 | 4 | * |
jjg@113 | 5 | * This code is free software; you can redistribute it and/or modify it |
jjg@113 | 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 |
jjg@113 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@554 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
jjg@113 | 10 | * |
jjg@113 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jjg@113 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jjg@113 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jjg@113 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
jjg@113 | 15 | * accompanied this code). |
jjg@113 | 16 | * |
jjg@113 | 17 | * You should have received a copy of the GNU General Public License version |
jjg@113 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
jjg@113 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jjg@113 | 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. |
jjg@113 | 24 | */ |
jjg@113 | 25 | |
jjg@113 | 26 | package com.sun.tools.javac.util; |
jjg@113 | 27 | |
jjg@113 | 28 | import java.lang.ref.WeakReference; |
jjg@113 | 29 | |
jjg@113 | 30 | /** |
jjg@113 | 31 | * Implementation of Name.Table that stores names in individual arrays |
jjg@113 | 32 | * using weak references. It is recommended for use when a single shared |
jjg@113 | 33 | * byte array is unsuitable. |
jjg@113 | 34 | * |
jjg@581 | 35 | * <p><b>This is NOT part of any supported API. |
jjg@581 | 36 | * If you write code that depends on this, you do so at your own risk. |
jjg@113 | 37 | * This code and its internal interfaces are subject to change or |
jjg@113 | 38 | * deletion without notice.</b> |
jjg@113 | 39 | */ |
jjg@113 | 40 | public class UnsharedNameTable extends Name.Table { |
jjg@113 | 41 | static public Name.Table create(Names names) { |
jjg@113 | 42 | return new UnsharedNameTable(names); |
jjg@113 | 43 | } |
jjg@113 | 44 | |
jjg@113 | 45 | static class HashEntry extends WeakReference<NameImpl> { |
jjg@113 | 46 | HashEntry next; |
jjg@113 | 47 | HashEntry(NameImpl referent) { |
jjg@113 | 48 | super(referent); |
jjg@113 | 49 | } |
jjg@113 | 50 | } |
jjg@113 | 51 | |
jjg@113 | 52 | /** The hash table for names. |
jjg@113 | 53 | */ |
jjg@113 | 54 | private HashEntry[] hashes = null; |
jjg@113 | 55 | |
jjg@113 | 56 | /** The mask to be used for hashing |
jjg@113 | 57 | */ |
jjg@113 | 58 | private int hashMask; |
jjg@113 | 59 | |
jjg@113 | 60 | /** Index counter for names in this table. |
jjg@113 | 61 | */ |
jjg@113 | 62 | public int index; |
jjg@113 | 63 | |
jjg@113 | 64 | /** Allocator |
jjg@113 | 65 | * @param names The main name table |
jjg@113 | 66 | * @param hashSize the (constant) size to be used for the hash table |
jjg@113 | 67 | * needs to be a power of two. |
jjg@113 | 68 | */ |
jjg@113 | 69 | public UnsharedNameTable(Names names, int hashSize) { |
jjg@113 | 70 | super(names); |
jjg@113 | 71 | hashMask = hashSize - 1; |
jjg@113 | 72 | hashes = new HashEntry[hashSize]; |
jjg@113 | 73 | } |
jjg@113 | 74 | |
jjg@113 | 75 | public UnsharedNameTable(Names names) { |
jjg@113 | 76 | this(names, 0x8000); |
jjg@113 | 77 | } |
jjg@113 | 78 | |
jjg@113 | 79 | |
jjg@113 | 80 | @Override |
jjg@113 | 81 | public Name fromChars(char[] cs, int start, int len) { |
jjg@113 | 82 | byte[] name = new byte[len * 3]; |
jjg@113 | 83 | int nbytes = Convert.chars2utf(cs, start, name, 0, len); |
jjg@113 | 84 | return fromUtf(name, 0, nbytes); |
jjg@113 | 85 | } |
jjg@113 | 86 | |
jjg@113 | 87 | @Override |
jjg@113 | 88 | public Name fromUtf(byte[] cs, int start, int len) { |
jjg@113 | 89 | int h = hashValue(cs, start, len) & hashMask; |
jjg@113 | 90 | |
jjg@113 | 91 | HashEntry element = hashes[h]; |
jjg@113 | 92 | |
jjg@113 | 93 | NameImpl n = null; |
jjg@113 | 94 | |
jjg@113 | 95 | HashEntry previousNonNullTableEntry = null; |
jjg@113 | 96 | HashEntry firstTableEntry = element; |
jjg@113 | 97 | |
jjg@113 | 98 | while (element != null) { |
jjg@113 | 99 | if (element == null) { |
jjg@113 | 100 | break; |
jjg@113 | 101 | } |
jjg@113 | 102 | |
jjg@113 | 103 | n = element.get(); |
jjg@113 | 104 | |
jjg@113 | 105 | if (n == null) { |
jjg@113 | 106 | if (firstTableEntry == element) { |
jjg@113 | 107 | hashes[h] = firstTableEntry = element.next; |
jjg@113 | 108 | } |
jjg@113 | 109 | else { |
jjg@816 | 110 | Assert.checkNonNull(previousNonNullTableEntry, "previousNonNullTableEntry cannot be null here."); |
jjg@113 | 111 | previousNonNullTableEntry.next = element.next; |
jjg@113 | 112 | } |
jjg@113 | 113 | } |
jjg@113 | 114 | else { |
jjg@113 | 115 | if (n.getByteLength() == len && equals(n.bytes, 0, cs, start, len)) { |
jjg@113 | 116 | return n; |
jjg@113 | 117 | } |
jjg@113 | 118 | previousNonNullTableEntry = element; |
jjg@113 | 119 | } |
jjg@113 | 120 | |
jjg@113 | 121 | element = element.next; |
jjg@113 | 122 | } |
jjg@113 | 123 | |
jjg@113 | 124 | byte[] bytes = new byte[len]; |
jjg@113 | 125 | System.arraycopy(cs, start, bytes, 0, len); |
jjg@113 | 126 | n = new NameImpl(this, bytes, index++); |
jjg@113 | 127 | |
jjg@113 | 128 | HashEntry newEntry = new HashEntry(n); |
jjg@113 | 129 | |
jjg@113 | 130 | if (previousNonNullTableEntry == null) { // We are not the first name with that hashCode. |
jjg@113 | 131 | hashes[h] = newEntry; |
jjg@113 | 132 | } |
jjg@113 | 133 | else { |
jjg@816 | 134 | Assert.checkNull(previousNonNullTableEntry.next, "previousNonNullTableEntry.next must be null."); |
jjg@113 | 135 | previousNonNullTableEntry.next = newEntry; |
jjg@113 | 136 | } |
jjg@113 | 137 | |
jjg@113 | 138 | return n; |
jjg@113 | 139 | } |
jjg@113 | 140 | |
jjg@113 | 141 | @Override |
jjg@113 | 142 | public void dispose() { |
jjg@113 | 143 | hashes = null; |
jjg@113 | 144 | } |
jjg@113 | 145 | |
jjg@113 | 146 | static class NameImpl extends Name { |
jjg@113 | 147 | NameImpl(UnsharedNameTable table, byte[] bytes, int index) { |
jjg@113 | 148 | super(table); |
jjg@113 | 149 | this.bytes = bytes; |
jjg@113 | 150 | this.index = index; |
jjg@113 | 151 | } |
jjg@113 | 152 | |
jjg@113 | 153 | final byte[] bytes; |
jjg@113 | 154 | final int index; |
jjg@113 | 155 | |
jjg@113 | 156 | @Override |
jjg@113 | 157 | public int getIndex() { |
jjg@113 | 158 | return index; |
jjg@113 | 159 | } |
jjg@113 | 160 | |
jjg@113 | 161 | @Override |
jjg@113 | 162 | public int getByteLength() { |
jjg@113 | 163 | return bytes.length; |
jjg@113 | 164 | } |
jjg@113 | 165 | |
jjg@113 | 166 | @Override |
jjg@113 | 167 | public byte getByteAt(int i) { |
jjg@113 | 168 | return bytes[i]; |
jjg@113 | 169 | } |
jjg@113 | 170 | |
jjg@113 | 171 | @Override |
jjg@113 | 172 | public byte[] getByteArray() { |
jjg@113 | 173 | return bytes; |
jjg@113 | 174 | } |
jjg@113 | 175 | |
jjg@113 | 176 | @Override |
jjg@113 | 177 | public int getByteOffset() { |
jjg@113 | 178 | return 0; |
jjg@113 | 179 | } |
jjg@113 | 180 | |
jjg@113 | 181 | } |
jjg@113 | 182 | |
jjg@113 | 183 | } |