DataPatchTest.java revision 13083:b9a173f12fe6
150479Speter/*
214125Speter * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
380029Sobrien * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
480029Sobrien *
580029Sobrien * This code is free software; you can redistribute it and/or modify it
614125Speter * under the terms of the GNU General Public License version 2 only, as
780029Sobrien * published by the Free Software Foundation.
8201390Sed *
980029Sobrien * This code is distributed in the hope that it will be useful, but WITHOUT
1014125Speter * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1114125Speter * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1214125Speter * version 2 for more details (a copy is included in the LICENSE file that
1314982Speter * accompanied this code).
1414982Speter *
1526053Sasami * You should have received a copy of the GNU General Public License version
16231118Sdim * 2 along with this work; if not, write to the Free Software Foundation,
1714982Speter * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1835910Sbde *
19321274Sngie * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2014982Speter * or visit www.oracle.com if you need additional information or have any
2114982Speter * questions.
22321274Sngie */
2314982Speter
2414125Speterpackage org.graalvm.compiler.hotspot.test;
2514125Speter
2614982Speterimport org.graalvm.compiler.core.common.CompressEncoding;
2714982Speterimport org.graalvm.compiler.hotspot.nodes.HotSpotCompressionNode;
28import org.graalvm.compiler.nodes.ValueNode;
29import org.graalvm.compiler.nodes.debug.OpaqueNode;
30import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
31import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin;
32import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
33import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration;
34import org.junit.Assume;
35import org.junit.Test;
36
37import jdk.vm.ci.meta.JavaKind;
38import jdk.vm.ci.meta.ResolvedJavaMethod;
39
40public class DataPatchTest extends HotSpotGraalCompilerTest {
41
42    public static double doubleSnippet() {
43        return 84.72;
44    }
45
46    @Test
47    public void doubleTest() {
48        test("doubleSnippet");
49    }
50
51    public static Object oopSnippet() {
52        return "asdf";
53    }
54
55    @Test
56    public void oopTest() {
57        test("oopSnippet");
58    }
59
60    private static Object compressUncompress(Object obj) {
61        return obj;
62    }
63
64    public static Object narrowOopSnippet() {
65        return compressUncompress("narrowAsdf");
66    }
67
68    @Test
69    public void narrowOopTest() {
70        Assume.assumeTrue("skipping narrow oop data patch test", runtime().getVMConfig().useCompressedOops);
71        test("narrowOopSnippet");
72    }
73
74    @Override
75    protected void registerInvocationPlugins(InvocationPlugins invocationPlugins) {
76        Registration r = new Registration(invocationPlugins, DataPatchTest.class);
77        r.register1("compressUncompress", Object.class, new InvocationPlugin() {
78            @Override
79            public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg) {
80                CompressEncoding encoding = runtime().getVMConfig().getOopEncoding();
81                ValueNode compressed = b.add(HotSpotCompressionNode.compress(arg, encoding));
82                ValueNode proxy = b.add(new OpaqueNode(compressed));
83                b.addPush(JavaKind.Object, HotSpotCompressionNode.uncompress(proxy, encoding));
84                return true;
85            }
86        });
87        super.registerInvocationPlugins(invocationPlugins);
88    }
89}
90