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 java.lang.reflect.InvocationTargetException; 27 import java.math.BigInteger; 28 import java.util.Random; 29 30 import org.graalvm.compiler.api.test.Graal; 31 import org.graalvm.compiler.core.test.GraalCompilerTest; 32 import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig; 33 import org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider; 34 import org.graalvm.compiler.runtime.RuntimeProvider; 35 36 import org.junit.Test; 37 38 import jdk.vm.ci.amd64.AMD64; 39 import jdk.vm.ci.code.InstalledCode; 40 import jdk.vm.ci.code.InvalidInstalledCodeException; 41 import jdk.vm.ci.meta.ResolvedJavaMethod; 42 43 /* 176 assert testmethod != null; 177 178 // Force the test method to be compiled. 179 testcode = getCode(testmethod); 180 181 assert testcode != null; 182 assert testcode.isValid(); 183 } 184 185 Object invokeJava(BigInteger big, Object... args) { 186 return invokeSafe(javamethod, big, args); 187 } 188 189 Object invokeTest(Object... args) { 190 return invokeSafe(testmethod, null, args); 191 } 192 193 Object invokeCode(Object... args) { 194 try { 195 return testcode.executeVarargs(args); 196 } 197 catch (InvalidInstalledCodeException e) { 198 // Ensure the installed code is valid, possibly recompiled. 199 testcode = getCode(testmethod); 200 201 assert testcode != null; 202 assert testcode.isValid(); 203 204 return invokeCode(args); 205 } 206 } 207 208 private Object invokeSafe(ResolvedJavaMethod method, Object receiver, Object... args) { 209 try { 210 return invoke(method, receiver, args); 211 } catch (IllegalAccessException | InvocationTargetException | 212 IllegalArgumentException | InstantiationException e) { 213 throw new RuntimeException(e); 214 } 215 } 216 217 // Private data section: 218 private ResolvedJavaMethod javamethod; 219 private ResolvedJavaMethod testmethod; 220 private InstalledCode testcode; 221 } 222 223 private static GraalHotSpotVMConfig config = 224 ((HotSpotGraalRuntimeProvider) Graal.getRequiredCapability(RuntimeProvider.class)).getVMConfig(); 225 226 private static BigInteger bigTwo = BigInteger.valueOf(2); 227 private static Random rnd = new Random(17); 228 229 private static BigInteger randomBig(int i) { 230 return new BigInteger(rnd.nextInt(4096) + i2sz(i), rnd); 231 } 232 233 private static int i2sz(int i) { 234 return i * 3 + 1; 235 } 236 } | 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 26 package org.graalvm.compiler.hotspot.test; 27 28 import java.lang.reflect.InvocationTargetException; 29 import java.math.BigInteger; 30 import java.util.Random; 31 32 import org.graalvm.compiler.api.test.Graal; 33 import org.graalvm.compiler.core.test.GraalCompilerTest; 34 import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig; 35 import org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider; 36 import org.graalvm.compiler.runtime.RuntimeProvider; 37 38 import org.junit.Test; 39 40 import jdk.vm.ci.amd64.AMD64; 41 import jdk.vm.ci.code.InstalledCode; 42 import jdk.vm.ci.code.InvalidInstalledCodeException; 43 import jdk.vm.ci.meta.ResolvedJavaMethod; 44 45 /* 178 assert testmethod != null; 179 180 // Force the test method to be compiled. 181 testcode = getCode(testmethod); 182 183 assert testcode != null; 184 assert testcode.isValid(); 185 } 186 187 Object invokeJava(BigInteger big, Object... args) { 188 return invokeSafe(javamethod, big, args); 189 } 190 191 Object invokeTest(Object... args) { 192 return invokeSafe(testmethod, null, args); 193 } 194 195 Object invokeCode(Object... args) { 196 try { 197 return testcode.executeVarargs(args); 198 } catch (InvalidInstalledCodeException e) { 199 // Ensure the installed code is valid, possibly recompiled. 200 testcode = getCode(testmethod); 201 202 assert testcode != null; 203 assert testcode.isValid(); 204 205 return invokeCode(args); 206 } 207 } 208 209 private Object invokeSafe(ResolvedJavaMethod method, Object receiver, Object... args) { 210 try { 211 return invoke(method, receiver, args); 212 } catch (IllegalAccessException | InvocationTargetException | IllegalArgumentException | InstantiationException e) { 213 throw new RuntimeException(e); 214 } 215 } 216 217 // Private data section: 218 private ResolvedJavaMethod javamethod; 219 private ResolvedJavaMethod testmethod; 220 private InstalledCode testcode; 221 } 222 223 private static GraalHotSpotVMConfig config = ((HotSpotGraalRuntimeProvider) Graal.getRequiredCapability(RuntimeProvider.class)).getVMConfig(); 224 225 private static BigInteger bigTwo = BigInteger.valueOf(2); 226 private static Random rnd = new Random(17); 227 228 private static BigInteger randomBig(int i) { 229 return new BigInteger(rnd.nextInt(4096) + i2sz(i), rnd); 230 } 231 232 private static int i2sz(int i) { 233 return i * 3 + 1; 234 } 235 } |