1 /* 2 * Copyright (c) 2014, 2015, 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 package org.graalvm.compiler.hotspot.test; 25 26 import org.junit.Assume; 27 import org.junit.Test; 28 29 import org.graalvm.compiler.hotspot.CompressEncoding; 30 import org.graalvm.compiler.hotspot.nodes.CompressionNode; 31 import org.graalvm.compiler.nodes.ValueNode; 32 import org.graalvm.compiler.nodes.debug.OpaqueNode; 33 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration; 34 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext; 35 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin; 36 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins; 37 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration; 38 39 import jdk.vm.ci.meta.JavaKind; 40 import jdk.vm.ci.meta.ResolvedJavaMethod; 41 42 public class DataPatchTest extends HotSpotGraalCompilerTest { 43 44 public static double doubleSnippet() { 45 return 84.72; 46 } 47 48 @Test 49 public void doubleTest() { 50 test("doubleSnippet"); 51 } 52 53 public static Object oopSnippet() { 54 return "asdf"; 55 } 56 57 @Test 58 public void oopTest() { 59 test("oopSnippet"); 60 } 61 62 private static Object compressUncompress(Object obj) { 63 return obj; 64 } 65 66 public static Object narrowOopSnippet() { 67 return compressUncompress("narrowAsdf"); 68 } 69 70 @Test 71 public void narrowOopTest() { 72 Assume.assumeTrue("skipping narrow oop data patch test", runtime().getVMConfig().useCompressedOops); 73 test("narrowOopSnippet"); 74 } 75 76 @Override 77 protected GraphBuilderConfiguration editGraphBuilderConfiguration(GraphBuilderConfiguration conf) { 78 InvocationPlugins invocationPlugins = conf.getPlugins().getInvocationPlugins(); 79 Registration r = new Registration(invocationPlugins, DataPatchTest.class); 80 r.register1("compressUncompress", Object.class, new InvocationPlugin() { 81 @Override 82 public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg) { 83 CompressEncoding encoding = runtime().getVMConfig().getOopEncoding(); 84 ValueNode compressed = b.add(CompressionNode.compress(arg, encoding)); 85 ValueNode proxy = b.add(new OpaqueNode(compressed)); 86 b.addPush(JavaKind.Object, CompressionNode.uncompress(proxy, encoding)); 87 return true; 88 } 89 }); 90 return super.editGraphBuilderConfiguration(conf); 91 } 92 }