< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/classfile/RedefineIntrinsicTest.java

Print this page
rev 56282 : [mq]: graal
   1 /*
   2  * Copyright (c) 2011, 2018, 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  */


  38 import java.lang.management.ManagementFactory;
  39 import java.lang.reflect.Method;
  40 import java.nio.file.Files;
  41 import java.nio.file.Path;
  42 import java.security.ProtectionDomain;
  43 import java.util.List;
  44 import java.util.jar.Attributes;
  45 import java.util.jar.JarEntry;
  46 import java.util.jar.JarOutputStream;
  47 import java.util.jar.Manifest;
  48 
  49 import javax.tools.ToolProvider;
  50 
  51 import org.graalvm.compiler.api.replacements.ClassSubstitution;
  52 import org.graalvm.compiler.api.replacements.MethodSubstitution;
  53 import org.graalvm.compiler.bytecode.BytecodeProvider;
  54 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
  55 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration;
  56 import org.graalvm.compiler.replacements.test.ReplacementsTest;
  57 import org.graalvm.compiler.serviceprovider.JavaVersionUtil;

  58 import org.graalvm.compiler.test.SubprocessUtil.Subprocess;
  59 import org.junit.Assert;
  60 import org.junit.Test;
  61 
  62 import jdk.vm.ci.meta.ResolvedJavaMethod;
  63 
  64 /**
  65  * Tests that intrinsics (and snippets) are isolated from bytecode instrumentation.
  66  */
  67 public class RedefineIntrinsicTest extends ReplacementsTest {
  68 
  69     public static class Original {
  70 
  71         // Intrinsified by Intrinsic.getValue
  72         public static String getValue() {
  73             return "original";
  74         }
  75     }
  76 
  77     @ClassSubstitution(Original.class)


  99     public static String callIntrinsicGetValue() {
 100         // This call will *not* be intrinsified when compiled by Graal
 101         return Intrinsic.getValue();
 102     }
 103 
 104     @Test
 105     public void test() throws Throwable {
 106         assumeManagementLibraryIsLoadable();
 107         try {
 108             Class.forName("java.lang.instrument.Instrumentation");
 109         } catch (ClassNotFoundException ex) {
 110             // skip this test if java.instrument JDK9 module is missing
 111             return;
 112         }
 113         String recursionPropName = getClass().getName() + ".recursion";
 114         if (JavaVersionUtil.JAVA_SPEC <= 8 || Boolean.getBoolean(recursionPropName)) {
 115             testHelper();
 116         } else {
 117             List<String> vmArgs = withoutDebuggerArguments(getVMCommandLine());
 118             vmArgs.add("-D" + recursionPropName + "=true");

 119             vmArgs.add("-Djdk.attach.allowAttachSelf=true");
 120             Subprocess proc = java(vmArgs, "com.oracle.mxtool.junit.MxJUnitWrapper", getClass().getName());
 121             if (proc.exitCode != 0) {
 122                 Assert.fail(String.format("non-zero exit code %d for command:%n%s", proc.exitCode, proc));
 123             }
 124         }
 125     }
 126 
 127     public void testHelper() throws Throwable {
 128 
 129         Object receiver = null;
 130         Object[] args = {};
 131 
 132         // Prior to redefinition, both Original and Intrinsic
 133         // should behave as per their Java source code
 134         Assert.assertEquals("original", Original.getValue());
 135         Assert.assertEquals("intrinsic", Intrinsic.getValue());
 136 
 137         ResolvedJavaMethod callOriginalGetValue = getResolvedJavaMethod("callOriginalGetValue");
 138         ResolvedJavaMethod callIntrinsicGetValue = getResolvedJavaMethod("callIntrinsicGetValue");


   1 /*
   2  * Copyright (c) 2011, 2019, 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  */


  38 import java.lang.management.ManagementFactory;
  39 import java.lang.reflect.Method;
  40 import java.nio.file.Files;
  41 import java.nio.file.Path;
  42 import java.security.ProtectionDomain;
  43 import java.util.List;
  44 import java.util.jar.Attributes;
  45 import java.util.jar.JarEntry;
  46 import java.util.jar.JarOutputStream;
  47 import java.util.jar.Manifest;
  48 
  49 import javax.tools.ToolProvider;
  50 
  51 import org.graalvm.compiler.api.replacements.ClassSubstitution;
  52 import org.graalvm.compiler.api.replacements.MethodSubstitution;
  53 import org.graalvm.compiler.bytecode.BytecodeProvider;
  54 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
  55 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration;
  56 import org.graalvm.compiler.replacements.test.ReplacementsTest;
  57 import org.graalvm.compiler.serviceprovider.JavaVersionUtil;
  58 import org.graalvm.compiler.test.SubprocessUtil;
  59 import org.graalvm.compiler.test.SubprocessUtil.Subprocess;
  60 import org.junit.Assert;
  61 import org.junit.Test;
  62 
  63 import jdk.vm.ci.meta.ResolvedJavaMethod;
  64 
  65 /**
  66  * Tests that intrinsics (and snippets) are isolated from bytecode instrumentation.
  67  */
  68 public class RedefineIntrinsicTest extends ReplacementsTest {
  69 
  70     public static class Original {
  71 
  72         // Intrinsified by Intrinsic.getValue
  73         public static String getValue() {
  74             return "original";
  75         }
  76     }
  77 
  78     @ClassSubstitution(Original.class)


 100     public static String callIntrinsicGetValue() {
 101         // This call will *not* be intrinsified when compiled by Graal
 102         return Intrinsic.getValue();
 103     }
 104 
 105     @Test
 106     public void test() throws Throwable {
 107         assumeManagementLibraryIsLoadable();
 108         try {
 109             Class.forName("java.lang.instrument.Instrumentation");
 110         } catch (ClassNotFoundException ex) {
 111             // skip this test if java.instrument JDK9 module is missing
 112             return;
 113         }
 114         String recursionPropName = getClass().getName() + ".recursion";
 115         if (JavaVersionUtil.JAVA_SPEC <= 8 || Boolean.getBoolean(recursionPropName)) {
 116             testHelper();
 117         } else {
 118             List<String> vmArgs = withoutDebuggerArguments(getVMCommandLine());
 119             vmArgs.add("-D" + recursionPropName + "=true");
 120             vmArgs.addAll(SubprocessUtil.getPackageOpeningOptions());
 121             vmArgs.add("-Djdk.attach.allowAttachSelf=true");
 122             Subprocess proc = java(vmArgs, "com.oracle.mxtool.junit.MxJUnitWrapper", getClass().getName());
 123             if (proc.exitCode != 0) {
 124                 Assert.fail(String.format("non-zero exit code %d for command:%n%s", proc.exitCode, proc));
 125             }
 126         }
 127     }
 128 
 129     public void testHelper() throws Throwable {
 130 
 131         Object receiver = null;
 132         Object[] args = {};
 133 
 134         // Prior to redefinition, both Original and Intrinsic
 135         // should behave as per their Java source code
 136         Assert.assertEquals("original", Original.getValue());
 137         Assert.assertEquals("intrinsic", Intrinsic.getValue());
 138 
 139         ResolvedJavaMethod callOriginalGetValue = getResolvedJavaMethod("callOriginalGetValue");
 140         ResolvedJavaMethod callIntrinsicGetValue = getResolvedJavaMethod("callIntrinsicGetValue");


< prev index next >