001/*
002 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.
008 *
009 * This code is distributed in the hope that it will be useful, but WITHOUT
010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
011 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
012 * version 2 for more details (a copy is included in the LICENSE file that
013 * accompanied this code).
014 *
015 * You should have received a copy of the GNU General Public License version
016 * 2 along with this work; if not, write to the Free Software Foundation,
017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
018 *
019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
020 * or visit www.oracle.com if you need additional information or have any
021 * questions.
022 */
023
024package com.oracle.graal.hotspot.test;
025
026import org.junit.*;
027
028import com.oracle.graal.compiler.test.*;
029import com.oracle.graal.graph.*;
030import com.oracle.graal.nodes.*;
031import com.oracle.graal.nodes.StructuredGraph.*;
032
033import com.oracle.graal.debug.*;
034import com.oracle.graal.debug.Debug.*;
035import sun.misc.*;
036import sun.reflect.*;
037
038public class ConstantPoolSubstitutionsTests extends GraalCompilerTest {
039
040    protected StructuredGraph test(final String snippet) {
041        try (Scope s = Debug.scope("ConstantPoolSubstitutionsTests", getMetaAccess().lookupJavaMethod(getMethod(snippet)))) {
042            StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
043            compile(graph.method(), graph);
044            assertNotInGraph(graph, Invoke.class);
045            Debug.dump(graph, snippet);
046            return graph;
047        } catch (Throwable e) {
048            throw Debug.handle(e);
049        }
050    }
051
052    protected static StructuredGraph assertNotInGraph(StructuredGraph graph, Class<?> clazz) {
053        for (Node node : graph.getNodes()) {
054            if (clazz.isInstance(node)) {
055                fail(node.toString());
056            }
057        }
058        return graph;
059    }
060
061    @Test
062    public void testGetSize() {
063        ConstantPool cp = SharedSecrets.getJavaLangAccess().getConstantPool(Object.class);
064        test("getSize", cp);
065    }
066
067    @Test
068    public void testGetIntAt() {
069        test("getIntAt");
070    }
071
072    @Test
073    public void testGetLongAt() {
074        test("getLongAt");
075    }
076
077    @Test
078    public void testGetFloatAt() {
079        test("getFloatAt");
080    }
081
082    @Test
083    public void testGetDoubleAt() {
084        test("getDoubleAt");
085    }
086
087    // @Test
088    public void testGetUTF8At() {
089        test("getUTF8At");
090    }
091
092    public int getSize(ConstantPool cp) {
093        return cp.getSize();
094    }
095
096    public int getIntAt(ConstantPool cp) {
097        return cp.getIntAt(0);
098    }
099
100    public long getLongAt(ConstantPool cp) {
101        return cp.getLongAt(0);
102    }
103
104    public float getFloatAt(ConstantPool cp) {
105        return cp.getFloatAt(0);
106    }
107
108    public double getDoubleAt(ConstantPool cp) {
109        return cp.getDoubleAt(0);
110    }
111
112    public String getUTF8At(ConstantPool cp) {
113        return cp.getUTF8At(0);
114    }
115
116}