ConstValInlining.java revision 0
0N/A/*
0N/A * Copyright 1999-2002 Sun Microsystems, Inc. All Rights Reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0N/A * CA 95054 USA or visit www.sun.com if you need additional information or
0N/A * have any questions.
0N/A */
0N/A
0N/A/*
0N/A * @test
0N/A * @bug 4253590 4255513 4115099
0N/A * @summary Verify that non-static fields with a ConstValue attribute inlined only when used as a simple name.
0N/A * @author maddox, gafter (adapted from leo's bug report)
0N/A *
0N/A * @run compile test_ff1.java
0N/A * @run compile ConstValInlining.java
0N/A * @run compile test_ff2.java
0N/A * @run main ConstValInlining
0N/A */
0N/A
0N/Apublic class ConstValInlining {
0N/A
0N/A void test() throws Exception {
0N/A Class checksClass = Class.forName("test_ff");
0N/A test_ff obj = new test_ff();
0N/A String reflected_fnl_str = (String)checksClass.getField("fnl_str").get(obj);
0N/A
0N/A T t = new T();
0N/A
0N/A // even when used by a qualified name, the compiler must inline
0N/A if (t.fnl_str.equals(reflected_fnl_str))
0N/A throw new Exception("FAILED: compiler failed to inline a qualified nonstatic constant");
0N/A
0N/A // when used by an unqualified name, they must not differ
0N/A t.test(reflected_fnl_str);
0N/A }
0N/A
0N/A static class T extends test_ff {
0N/A void test(String reflected) throws Exception {
0N/A // when used by an unqualified qualified name, they must differ
0N/A if (fnl_str.equals(reflected))
0N/A throw new Exception("FAILED: compiler failed to inline an unqualified nonstatic constant");
0N/A }
0N/A };
0N/A
0N/A public static void main(String args[]) throws Exception {
0N/A new ConstValInlining().test();
0N/A }
0N/A}