1/*
2 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24/**
25 * @test
26 * @bug 8140650
27 * @summary Method::is_accessor should cover getters and setters for all types
28 * @modules java.base/jdk.internal.misc
29 * @library /test/lib
30 *
31 * @run driver compiler.inlining.InlineAccessors
32 */
33
34package compiler.inlining;
35
36import jdk.test.lib.process.OutputAnalyzer;
37import jdk.test.lib.process.ProcessTools;
38
39public class InlineAccessors {
40    public static void main(String[] args) throws Exception {
41        // try some sanity checks first
42        doTest();
43
44        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
45                "-XX:+IgnoreUnrecognizedVMOptions", "-showversion",
46                "-server", "-XX:-TieredCompilation", "-Xbatch", "-Xcomp",
47                "-XX:+PrintCompilation", "-XX:+UnlockDiagnosticVMOptions", "-XX:+PrintInlining",
48                    Launcher.class.getName());
49
50        OutputAnalyzer analyzer = new OutputAnalyzer(pb.start());
51
52        analyzer.shouldHaveExitValue(0);
53
54        // The test is applicable only to C2 (present in Server VM).
55        if (analyzer.getStderr().contains("Server VM")) {
56            analyzer.shouldContain("InlineAccessors::setBool (6 bytes)   accessor");
57            analyzer.shouldContain("InlineAccessors::setByte (6 bytes)   accessor");
58            analyzer.shouldContain("InlineAccessors::setChar (6 bytes)   accessor");
59            analyzer.shouldContain("InlineAccessors::setShort (6 bytes)   accessor");
60            analyzer.shouldContain("InlineAccessors::setInt (6 bytes)   accessor");
61            analyzer.shouldContain("InlineAccessors::setFloat (6 bytes)   accessor");
62            analyzer.shouldContain("InlineAccessors::setLong (6 bytes)   accessor");
63            analyzer.shouldContain("InlineAccessors::setDouble (6 bytes)   accessor");
64            analyzer.shouldContain("InlineAccessors::setObject (6 bytes)   accessor");
65            analyzer.shouldContain("InlineAccessors::setArray (6 bytes)   accessor");
66
67            analyzer.shouldContain("InlineAccessors::getBool (5 bytes)   accessor");
68            analyzer.shouldContain("InlineAccessors::getByte (5 bytes)   accessor");
69            analyzer.shouldContain("InlineAccessors::getChar (5 bytes)   accessor");
70            analyzer.shouldContain("InlineAccessors::getShort (5 bytes)   accessor");
71            analyzer.shouldContain("InlineAccessors::getInt (5 bytes)   accessor");
72            analyzer.shouldContain("InlineAccessors::getFloat (5 bytes)   accessor");
73            analyzer.shouldContain("InlineAccessors::getLong (5 bytes)   accessor");
74            analyzer.shouldContain("InlineAccessors::getDouble (5 bytes)   accessor");
75            analyzer.shouldContain("InlineAccessors::getObject (5 bytes)   accessor");
76            analyzer.shouldContain("InlineAccessors::getArray (5 bytes)   accessor");
77        }
78    }
79
80    boolean bool;
81    byte b;
82    char c;
83    short s;
84    int i;
85    float f;
86    long l;
87    double d;
88    Object o;
89    Object[] a;
90
91    public void setBool(boolean v)   { bool = v; }
92    public void setByte(byte v)      { b = v; }
93    public void setChar(char v)      { c = v; }
94    public void setShort(short v)    { s = v; }
95    public void setInt(int v)        { i = v; }
96    public void setFloat(float v)    { f = v; }
97    public void setLong(long v)      { l = v; }
98    public void setDouble(double v)  { d = v; }
99    public void setObject(Object v)  { o = v; }
100    public void setArray(Object[] v) { a = v; }
101
102    public boolean  getBool()        { return bool; }
103    public byte     getByte()        { return b; }
104    public char     getChar()        { return c; }
105    public short    getShort()       { return s; }
106    public int      getInt()         { return i; }
107    public float    getFloat()       { return f; }
108    public long     getLong()        { return l; }
109    public double   getDouble()      { return d; }
110    public Object   getObject()      { return o; }
111    public Object[] getArray()       { return a; }
112
113    static void doTest() {
114        InlineAccessors o = new InlineAccessors();
115        o.setBool(false);
116        o.setByte((byte)0);
117        o.setChar('a');
118        o.setShort((short)0);
119        o.setInt(0);
120        o.setFloat(0F);
121        o.setLong(0L);
122        o.setDouble(0D);
123        o.setObject(new Object());
124        o.setArray(new Object[1]);
125
126        o.getBool();
127        o.getByte();
128        o.getChar();
129        o.getShort();
130        o.getInt();
131        o.getFloat();
132        o.getLong();
133        o.getDouble();
134        o.getObject();
135        o.getArray();
136    }
137
138    static class Launcher {
139        public static void main(String[] args) throws Exception {
140            for (int c = 0; c < 20_000; c++) {
141              doTest();
142            }
143        }
144    }
145}
146