mcimadamore@1438: /* jjg@1721: * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. mcimadamore@1438: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. mcimadamore@1438: * mcimadamore@1438: * This code is free software; you can redistribute it and/or modify it mcimadamore@1438: * under the terms of the GNU General Public License version 2 only, as mcimadamore@1438: * published by the Free Software Foundation. Oracle designates this mcimadamore@1438: * particular file as subject to the "Classpath" exception as provided mcimadamore@1438: * by Oracle in the LICENSE file that accompanied this code. mcimadamore@1438: * mcimadamore@1438: * This code is distributed in the hope that it will be useful, but WITHOUT mcimadamore@1438: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or mcimadamore@1438: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License mcimadamore@1438: * version 2 for more details (a copy is included in the LICENSE file that mcimadamore@1438: * accompanied this code). mcimadamore@1438: * mcimadamore@1438: * You should have received a copy of the GNU General Public License version mcimadamore@1438: * 2 along with this work; if not, write to the Free Software Foundation, mcimadamore@1438: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. mcimadamore@1438: * mcimadamore@1438: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA mcimadamore@1438: * or visit www.oracle.com if you need additional information or have any mcimadamore@1438: * questions. mcimadamore@1438: */ mcimadamore@1438: mcimadamore@1438: /** mcimadamore@1438: * @test jjg@1721: * @ignore 8007517: DefaultMethodRegressionTests.java fail in TL mcimadamore@1438: * @bug 8003639 mcimadamore@1438: * @summary convert lambda testng tests to jtreg and add them mcimadamore@1438: * @run testng DefaultMethodRegressionTests mcimadamore@1438: */ mcimadamore@1438: mcimadamore@1438: import java.util.ArrayList; mcimadamore@1438: import java.util.Arrays; mcimadamore@1438: import java.util.List; mcimadamore@1438: import org.testng.annotations.Test; mcimadamore@1438: mcimadamore@1438: import static org.testng.Assert.*; mcimadamore@1438: mcimadamore@1438: /** mcimadamore@1438: * This set of classes/interfaces (K/I/C) is specially designed to expose a mcimadamore@1438: * bug in the JVM where it did not find some overloaded methods in some mcimadamore@1438: * specific situations. (fixed by hotspot changeset ffb9316fd9ed) mcimadamore@1438: */ mcimadamore@1438: interface K { mcimadamore@1438: int bbb(Long l); mcimadamore@1438: } mcimadamore@1438: mcimadamore@1438: interface I extends K { mcimadamore@1438: default void aaa() {} mcimadamore@1438: default void aab() {} mcimadamore@1438: default void aac() {} mcimadamore@1438: mcimadamore@1438: default int bbb(Integer i) { return 22; } mcimadamore@1438: default int bbb(Float f) { return 33; } mcimadamore@1438: default int bbb(Long l) { return 44; } mcimadamore@1438: default int bbb(Double d) { return 55; } mcimadamore@1438: default int bbb(String s) { return 66; } mcimadamore@1438: mcimadamore@1438: default void caa() {} mcimadamore@1438: default void cab() {} mcimadamore@1438: default void cac() {} mcimadamore@1438: } mcimadamore@1438: mcimadamore@1438: class C implements I {} mcimadamore@1438: mcimadamore@1438: public class DefaultMethodRegressionTests { mcimadamore@1438: mcimadamore@1438: @Test(groups = "vm") mcimadamore@1438: public void testLostOverloadedMethod() { mcimadamore@1438: C c = new C(); mcimadamore@1438: assertEquals(c.bbb(new Integer(1)), 22); mcimadamore@1438: assertEquals(c.bbb(new Float(1.1)), 33); mcimadamore@1438: assertEquals(c.bbb(new Long(1L)), 44); mcimadamore@1438: assertEquals(c.bbb(new Double(0.01)), 55); mcimadamore@1438: assertEquals(c.bbb(new String("")), 66); mcimadamore@1438: } mcimadamore@1438: mcimadamore@1438: // Test to ensure that the inference verifier accepts older classfiles mcimadamore@1438: // with classes that implement interfaces with defaults. mcimadamore@1438: @Test(groups = "vm") mcimadamore@1438: public void testInferenceVerifier() { mcimadamore@1438: // interface I { int m() default { return 99; } } mcimadamore@1438: byte I_bytes[] = { mcimadamore@1438: (byte)0xca, (byte)0xfe, (byte)0xba, (byte)0xbe, 0x00, 0x00, 0x00, 0x33, mcimadamore@1438: 0x00, 0x08, 0x07, 0x00, 0x06, 0x07, 0x00, 0x07, mcimadamore@1438: 0x01, 0x00, 0x03, 0x66, 0x6f, 0x6f, 0x01, 0x00, mcimadamore@1438: 0x03, 0x28, 0x29, 0x49, 0x01, 0x00, 0x04, 0x43, mcimadamore@1438: 0x6f, 0x64, 0x65, 0x01, 0x00, 0x01, 0x49, 0x01, mcimadamore@1438: 0x00, 0x10, 0x6a, 0x61, 0x76, 0x61, 0x2f, 0x6c, mcimadamore@1438: 0x61, 0x6e, 0x67, 0x2f, 0x4f, 0x62, 0x6a, 0x65, mcimadamore@1438: 0x63, 0x74, 0x06, 0x00, 0x00, 0x01, 0x00, 0x02, mcimadamore@1438: 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x01, mcimadamore@1438: 0x00, 0x03, 0x00, 0x04, 0x00, 0x01, 0x00, 0x05, mcimadamore@1438: 0x00, 0x00, 0x00, 0x0f, 0x00, 0x01, 0x00, 0x01, mcimadamore@1438: 0x00, 0x00, 0x00, 0x03, 0x10, 0x63, (byte)0xac, 0x00, mcimadamore@1438: 0x00, 0x00, 0x00, 0x00, 0x00 mcimadamore@1438: }; mcimadamore@1438: // public class C implements I {} /* -target 1.5 */ mcimadamore@1438: byte C_bytes[] = { mcimadamore@1438: (byte)0xca, (byte)0xfe, (byte)0xba, (byte)0xbe, 0x00, 0x00, 0x00, 0x31, mcimadamore@1438: 0x00, 0x0c, 0x0a, 0x00, 0x03, 0x00, 0x08, 0x07, mcimadamore@1438: 0x00, 0x09, 0x07, 0x00, 0x0a, 0x07, 0x00, 0x0b, mcimadamore@1438: 0x01, 0x00, 0x06, 0x3c, 0x69, 0x6e, 0x69, 0x74, mcimadamore@1438: 0x3e, 0x01, 0x00, 0x03, 0x28, 0x29, 0x56, 0x01, mcimadamore@1438: 0x00, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x0c, 0x00, mcimadamore@1438: 0x05, 0x00, 0x06, 0x01, 0x00, 0x01, 0x43, 0x01, mcimadamore@1438: 0x00, 0x10, 0x6a, 0x61, 0x76, 0x61, 0x2f, 0x6c, mcimadamore@1438: 0x61, 0x6e, 0x67, 0x2f, 0x4f, 0x62, 0x6a, 0x65, mcimadamore@1438: 0x63, 0x74, 0x01, 0x00, 0x01, 0x49, 0x00, 0x21, mcimadamore@1438: 0x00, 0x02, 0x00, 0x03, 0x00, 0x01, 0x00, 0x04, mcimadamore@1438: 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x05, mcimadamore@1438: 0x00, 0x06, 0x00, 0x01, 0x00, 0x07, 0x00, 0x00, mcimadamore@1438: 0x00, 0x11, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, mcimadamore@1438: 0x00, 0x05, 0x2a, (byte)0xb7, 0x00, 0x01, (byte)0xb1, 0x00, mcimadamore@1438: 0x00, 0x00, 0x00, 0x00, 0x00 mcimadamore@1438: }; mcimadamore@1438: mcimadamore@1438: ClassLoader cl = new ClassLoader() { mcimadamore@1438: protected Class findClass(String name) { mcimadamore@1438: if (name.equals("I")) { mcimadamore@1438: return defineClass("I", I_bytes, 0, I_bytes.length); mcimadamore@1438: } else if (name.equals("C")) { mcimadamore@1438: return defineClass("C", C_bytes, 0, C_bytes.length); mcimadamore@1438: } else { mcimadamore@1438: return null; mcimadamore@1438: } mcimadamore@1438: } mcimadamore@1438: }; mcimadamore@1438: try { mcimadamore@1438: Class.forName("C", true, cl); mcimadamore@1438: } catch (Exception e) { mcimadamore@1438: // unmodified verifier will throw VerifyError mcimadamore@1438: fail("No exception should be thrown"); mcimadamore@1438: } mcimadamore@1438: } mcimadamore@1438: }