Path: blob/master/test/hotspot/jtreg/runtime/LoaderConstraints/vtableAME/Test.java
40948 views
/*1* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 818609226* @compile ../common/Foo.java27* ../common/J.java28* I.java29* ../common/C.jasm30* Task.java31* ../common/PreemptingClassLoader.java32* @run main/othervm Test33*/3435import java.io.PrintStream;36import java.lang.reflect.*;3738public class Test {3940// Test that LinkageError exceptions are not thrown during vtable creation,41// for loader constraint errors, if the target method is an overpass method.42//43// In this test, during vtable creation for class Task, the target method44// "Task.m()LFoo;" is an overpass method (that throws an AME). So, even45// though it is inheriting the method from its super class C, and Task has46// a different class Foo than C, no LinkageError exception should be thrown47// because the loader constraint check that would cause the LinkageError48// should not be done.49public static void main(String args[]) throws Exception {50Class<?> c = test.Foo.class; // forces standard class loader to load Foo51ClassLoader l = new PreemptingClassLoader("test.Task", "test.Foo", "test.I", "test.J");52l.loadClass("test.Foo");53l.loadClass("test.Task").newInstance();54test.Task t = new test.Task();55try {56t.m(); // Should get AME57throw new RuntimeException("Missing AbstractMethodError exception");58} catch (AbstractMethodError e) {59if (!e.getMessage().contains("Method test/Task.m()Ltest/Foo; is abstract")) {60throw new RuntimeException("Wrong AME exception thrown: " + e.getMessage());61}62}63}6465}666768