Thu, 12 Jan 2012 15:28:34 +0000
7123100: javac fails with java.lang.StackOverflowError
Summary: Inference of under-constrained type-variables creates erroneous recursive wildcard types
Reviewed-by: jjg
ksrini@826 | 1 | /* |
ksrini@826 | 2 | * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
ksrini@826 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ksrini@826 | 4 | * |
ksrini@826 | 5 | * This code is free software; you can redistribute it and/or modify it |
ksrini@826 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ksrini@826 | 7 | * published by the Free Software Foundation. Oracle designates this |
ksrini@826 | 8 | * particular file as subject to the "Classpath" exception as provided |
ksrini@826 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
ksrini@826 | 10 | * |
ksrini@826 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
ksrini@826 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ksrini@826 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ksrini@826 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
ksrini@826 | 15 | * accompanied this code). |
ksrini@826 | 16 | * |
ksrini@826 | 17 | * You should have received a copy of the GNU General Public License version |
ksrini@826 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
ksrini@826 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ksrini@826 | 20 | * |
ksrini@826 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ksrini@826 | 22 | * or visit www.oracle.com if you need additional information or have any |
ksrini@826 | 23 | * questions. |
ksrini@826 | 24 | */ |
ksrini@826 | 25 | |
ksrini@826 | 26 | package com.sun.tools.classfile; |
ksrini@826 | 27 | |
ksrini@826 | 28 | import java.io.IOException; |
ksrini@826 | 29 | |
ksrini@826 | 30 | /** |
jjh@972 | 31 | * See JVMS <TBD> |
ksrini@826 | 32 | * http://cr.openjdk.java.net/~jrose/pres/indy-javadoc-mlvm/ |
ksrini@826 | 33 | * |
ksrini@826 | 34 | * <p><b>This is NOT part of any supported API. |
ksrini@826 | 35 | * If you write code that depends on this, you do so at your own risk. |
ksrini@826 | 36 | * This code and its internal interfaces are subject to change or |
ksrini@826 | 37 | * deletion without notice.</b> |
ksrini@826 | 38 | */ |
ksrini@826 | 39 | public class BootstrapMethods_attribute extends Attribute { |
ksrini@826 | 40 | public final BootstrapMethodSpecifier[] bootstrap_method_specifiers; |
ksrini@826 | 41 | |
ksrini@826 | 42 | BootstrapMethods_attribute(ClassReader cr, int name_index, int length) |
ksrini@826 | 43 | throws IOException, AttributeException { |
ksrini@826 | 44 | super(name_index, length); |
ksrini@826 | 45 | int bootstrap_method_count = cr.readUnsignedShort(); |
ksrini@826 | 46 | bootstrap_method_specifiers = new BootstrapMethodSpecifier[bootstrap_method_count]; |
ksrini@826 | 47 | for (int i = 0; i < bootstrap_method_specifiers.length; i++) |
ksrini@826 | 48 | bootstrap_method_specifiers[i] = new BootstrapMethodSpecifier(cr); |
ksrini@826 | 49 | } |
ksrini@826 | 50 | |
ksrini@826 | 51 | public BootstrapMethods_attribute(int name_index, BootstrapMethodSpecifier[] bootstrap_method_specifiers) { |
ksrini@826 | 52 | super(name_index, length(bootstrap_method_specifiers)); |
ksrini@826 | 53 | this.bootstrap_method_specifiers = bootstrap_method_specifiers; |
ksrini@826 | 54 | } |
ksrini@826 | 55 | |
ksrini@826 | 56 | public static int length(BootstrapMethodSpecifier[] bootstrap_method_specifiers) { |
ksrini@826 | 57 | int n = 2; |
ksrini@826 | 58 | for (BootstrapMethodSpecifier b : bootstrap_method_specifiers) |
ksrini@826 | 59 | n += b.length(); |
ksrini@826 | 60 | return n; |
ksrini@826 | 61 | } |
ksrini@826 | 62 | |
ksrini@826 | 63 | @Override |
ksrini@826 | 64 | public <R, P> R accept(Visitor<R, P> visitor, P p) { |
ksrini@826 | 65 | return visitor.visitBootstrapMethods(this, p); |
ksrini@826 | 66 | } |
ksrini@826 | 67 | |
ksrini@826 | 68 | public static class BootstrapMethodSpecifier { |
ksrini@826 | 69 | public int bootstrap_method_ref; |
ksrini@826 | 70 | public int[] bootstrap_arguments; |
ksrini@826 | 71 | |
ksrini@826 | 72 | public BootstrapMethodSpecifier(int bootstrap_method_ref, int[] bootstrap_arguments) { |
ksrini@826 | 73 | this.bootstrap_method_ref = bootstrap_method_ref; |
ksrini@826 | 74 | this.bootstrap_arguments = bootstrap_arguments; |
ksrini@826 | 75 | } |
ksrini@826 | 76 | BootstrapMethodSpecifier(ClassReader cr) throws IOException { |
ksrini@826 | 77 | bootstrap_method_ref = cr.readUnsignedShort(); |
ksrini@826 | 78 | int method_count = cr.readUnsignedShort(); |
ksrini@826 | 79 | bootstrap_arguments = new int[method_count]; |
ksrini@826 | 80 | for (int i = 0; i < bootstrap_arguments.length; i++) { |
ksrini@826 | 81 | bootstrap_arguments[i] = cr.readUnsignedShort(); |
ksrini@826 | 82 | } |
ksrini@826 | 83 | } |
ksrini@826 | 84 | |
ksrini@826 | 85 | int length() { |
ksrini@826 | 86 | // u2 (method_ref) + u2 (argc) + u2 * argc |
ksrini@826 | 87 | return 2 + 2 + (bootstrap_arguments.length * 2); |
ksrini@826 | 88 | } |
ksrini@826 | 89 | } |
ksrini@826 | 90 | } |