Mon, 28 Feb 2011 11:48:53 +0000
7015430: Incorrect thrown type determined for unchecked invocations
Summary: Thrown types do not get updated after 15.12.2.8, and do not get erased as per 15.12.2.6
Reviewed-by: jjg, dlsmith
duke@1 | 1 | /* |
ohair@554 | 2 | * Copyright (c) 1999, 2008, 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.jvm; |
duke@1 | 27 | |
duke@1 | 28 | import java.util.*; |
duke@1 | 29 | |
duke@1 | 30 | import com.sun.tools.javac.code.Symbol.*; |
duke@1 | 31 | |
duke@1 | 32 | /** An internal structure that corresponds to the constant pool of a classfile. |
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 Pool { |
duke@1 | 40 | |
duke@1 | 41 | public static final int MAX_ENTRIES = 0xFFFF; |
duke@1 | 42 | public static final int MAX_STRING_LENGTH = 0xFFFF; |
duke@1 | 43 | |
duke@1 | 44 | /** Index of next constant to be entered. |
duke@1 | 45 | */ |
duke@1 | 46 | int pp; |
duke@1 | 47 | |
duke@1 | 48 | /** The initial pool buffer. |
duke@1 | 49 | */ |
duke@1 | 50 | Object[] pool; |
duke@1 | 51 | |
duke@1 | 52 | /** A hashtable containing all constants in the pool. |
duke@1 | 53 | */ |
duke@1 | 54 | Map<Object,Integer> indices; |
duke@1 | 55 | |
duke@1 | 56 | /** Construct a pool with given number of elements and element array. |
duke@1 | 57 | */ |
duke@1 | 58 | public Pool(int pp, Object[] pool) { |
duke@1 | 59 | this.pp = pp; |
duke@1 | 60 | this.pool = pool; |
duke@1 | 61 | this.indices = new HashMap<Object,Integer>(pool.length); |
duke@1 | 62 | for (int i = 1; i < pp; i++) { |
duke@1 | 63 | if (pool[i] != null) indices.put(pool[i], i); |
duke@1 | 64 | } |
duke@1 | 65 | } |
duke@1 | 66 | |
duke@1 | 67 | /** Construct an empty pool. |
duke@1 | 68 | */ |
duke@1 | 69 | public Pool() { |
duke@1 | 70 | this(1, new Object[64]); |
duke@1 | 71 | } |
duke@1 | 72 | |
duke@1 | 73 | /** Return the number of entries in the constant pool. |
duke@1 | 74 | */ |
duke@1 | 75 | public int numEntries() { |
duke@1 | 76 | return pp; |
duke@1 | 77 | } |
duke@1 | 78 | |
duke@1 | 79 | /** Remove everything from this pool. |
duke@1 | 80 | */ |
duke@1 | 81 | public void reset() { |
duke@1 | 82 | pp = 1; |
duke@1 | 83 | indices.clear(); |
duke@1 | 84 | } |
duke@1 | 85 | |
duke@1 | 86 | /** Double pool buffer in size. |
duke@1 | 87 | */ |
duke@1 | 88 | private void doublePool() { |
duke@1 | 89 | Object[] newpool = new Object[pool.length * 2]; |
duke@1 | 90 | System.arraycopy(pool, 0, newpool, 0, pool.length); |
duke@1 | 91 | pool = newpool; |
duke@1 | 92 | } |
duke@1 | 93 | |
duke@1 | 94 | /** Place an object in the pool, unless it is already there. |
duke@1 | 95 | * If object is a symbol also enter its owner unless the owner is a |
duke@1 | 96 | * package. Return the object's index in the pool. |
duke@1 | 97 | */ |
duke@1 | 98 | public int put(Object value) { |
duke@1 | 99 | if (value instanceof MethodSymbol) |
duke@1 | 100 | value = new Method((MethodSymbol)value); |
duke@1 | 101 | else if (value instanceof VarSymbol) |
duke@1 | 102 | value = new Variable((VarSymbol)value); |
duke@1 | 103 | // assert !(value instanceof Type.TypeVar); |
duke@1 | 104 | Integer index = indices.get(value); |
duke@1 | 105 | if (index == null) { |
duke@1 | 106 | // System.err.println("put " + value + " " + value.getClass());//DEBUG |
duke@1 | 107 | index = pp; |
duke@1 | 108 | indices.put(value, index); |
duke@1 | 109 | if (pp == pool.length) doublePool(); |
duke@1 | 110 | pool[pp++] = value; |
duke@1 | 111 | if (value instanceof Long || value instanceof Double) { |
duke@1 | 112 | if (pp == pool.length) doublePool(); |
duke@1 | 113 | pool[pp++] = null; |
duke@1 | 114 | } |
duke@1 | 115 | } |
duke@1 | 116 | return index.intValue(); |
duke@1 | 117 | } |
duke@1 | 118 | |
duke@1 | 119 | /** Return the given object's index in the pool, |
duke@1 | 120 | * or -1 if object is not in there. |
duke@1 | 121 | */ |
duke@1 | 122 | public int get(Object o) { |
duke@1 | 123 | Integer n = indices.get(o); |
duke@1 | 124 | return n == null ? -1 : n.intValue(); |
duke@1 | 125 | } |
duke@1 | 126 | |
duke@1 | 127 | static class Method extends DelegatedSymbol { |
duke@1 | 128 | MethodSymbol m; |
duke@1 | 129 | Method(MethodSymbol m) { |
duke@1 | 130 | super(m); |
duke@1 | 131 | this.m = m; |
duke@1 | 132 | } |
duke@1 | 133 | public boolean equals(Object other) { |
duke@1 | 134 | if (!(other instanceof Method)) return false; |
duke@1 | 135 | MethodSymbol o = ((Method)other).m; |
duke@1 | 136 | return |
duke@1 | 137 | o.name == m.name && |
duke@1 | 138 | o.owner == m.owner && |
duke@1 | 139 | o.type.equals(m.type); |
duke@1 | 140 | } |
duke@1 | 141 | public int hashCode() { |
duke@1 | 142 | return |
duke@1 | 143 | m.name.hashCode() * 33 + |
duke@1 | 144 | m.owner.hashCode() * 9 + |
duke@1 | 145 | m.type.hashCode(); |
duke@1 | 146 | } |
duke@1 | 147 | } |
duke@1 | 148 | |
duke@1 | 149 | static class Variable extends DelegatedSymbol { |
duke@1 | 150 | VarSymbol v; |
duke@1 | 151 | Variable(VarSymbol v) { |
duke@1 | 152 | super(v); |
duke@1 | 153 | this.v = v; |
duke@1 | 154 | } |
duke@1 | 155 | public boolean equals(Object other) { |
duke@1 | 156 | if (!(other instanceof Variable)) return false; |
duke@1 | 157 | VarSymbol o = ((Variable)other).v; |
duke@1 | 158 | return |
duke@1 | 159 | o.name == v.name && |
duke@1 | 160 | o.owner == v.owner && |
duke@1 | 161 | o.type.equals(v.type); |
duke@1 | 162 | } |
duke@1 | 163 | public int hashCode() { |
duke@1 | 164 | return |
duke@1 | 165 | v.name.hashCode() * 33 + |
duke@1 | 166 | v.owner.hashCode() * 9 + |
duke@1 | 167 | v.type.hashCode(); |
duke@1 | 168 | } |
duke@1 | 169 | } |
duke@1 | 170 | } |