use of jdk.vm.ci.code.InstalledCode in project graal by oracle.
the class GraalTutorial method testIntrinsicIntegerReverseBytes.
@Test
public void testIntrinsicIntegerReverseBytes() throws InvalidInstalledCodeException {
int input = 0x12345678;
int expected = intrinsicIntegerReverseBytes(input);
InstalledCode compiledMethod = compileAndInstallMethod(findMethod(GraalTutorial.class, "intrinsicIntegerReverseBytes"));
int actual = (int) compiledMethod.executeVarargs(input);
Assert.assertEquals(expected, actual);
}
use of jdk.vm.ci.code.InstalledCode in project graal by oracle.
the class GraalTutorial method testSpeculativeOptimization.
@Test
public void testSpeculativeOptimization() throws InvalidInstalledCodeException {
for (int i = 0; i < 10000; i++) {
/* Execute several times so that enough profiling information gets collected. */
speculativeOptimization(false);
}
/*
* Warmup to collect profiling information is done, now we compile the method. Since the
* value of "flag" was always false during the warmup, the compiled code speculates that the
* value remains false.
*/
InstalledCode compiledMethod = compileAndInstallMethod(findMethod(GraalTutorial.class, "speculativeOptimization"));
f1 = 0;
f2 = 0;
compiledMethod.executeVarargs(this, true);
Assert.assertEquals(41, f1);
Assert.assertEquals(42, f2);
/*
* We executed the compiled method with a "flag" value that triggered deoptimization (since
* the warmup always used the different "flag" value). The interpreter updated the profiling
* information, so the second compilation does not perform the speculative optimization.
*/
compiledMethod = compileAndInstallMethod(findMethod(GraalTutorial.class, "speculativeOptimization"));
f1 = 0;
f2 = 0;
compiledMethod.executeVarargs(this, false);
Assert.assertEquals(41, f1);
Assert.assertEquals(43, f2);
}
use of jdk.vm.ci.code.InstalledCode in project graal by oracle.
the class GraalTutorial method testInstanceOfUsage.
@Test
public void testInstanceOfUsage() throws InvalidInstalledCodeException {
/*
* Collect profiling information by running the method in the interpreter.
*/
A a = new A();
/* Allocate an (unused) instance of B so that the class B gets loaded. */
@SuppressWarnings("unused") B b = new B();
int expectedResult = instanceOfUsage(a);
for (int i = 0; i < 10000; i++) {
/* Execute several times so that enough profiling information gets collected. */
instanceOfUsage(a);
}
/* Warmup to collect profiling information is done, now compile the method. */
InstalledCode compiledMethod = compileAndInstallMethod(findMethod(GraalTutorial.class, "instanceOfUsage"));
int result = (int) compiledMethod.executeVarargs(a);
Assert.assertEquals(expectedResult, result);
}
use of jdk.vm.ci.code.InstalledCode in project graal by oracle.
the class GraalTutorial method testIdentityHashCodeUsage.
@Test
public void testIdentityHashCodeUsage() throws InvalidInstalledCodeException {
Object a = new Object();
int expectedResult = identityHashCodeUsage(a);
InstalledCode compiledMethod = compileAndInstallMethod(findMethod(GraalTutorial.class, "identityHashCodeUsage"));
int result = (int) compiledMethod.executeVarargs(a);
Assert.assertEquals(expectedResult, result);
}
use of jdk.vm.ci.code.InstalledCode in project graal by oracle.
the class Backend method createInstalledCode.
/**
* Installs code based on a given compilation result.
*
* @param method the method compiled to produce {@code compiledCode} or {@code null} if the
* input to {@code compResult} was not a {@link ResolvedJavaMethod}
* @param compilationRequest the compilation request or {@code null}
* @param compilationResult the code to be installed
* @param predefinedInstalledCode a pre-allocated {@link InstalledCode} object to use as a
* reference to the installed code. If {@code null}, a new {@link InstalledCode}
* object will be created.
* @param speculationLog the speculation log to be used
* @param isDefault specifies if the installed code should be made the default implementation of
* {@code compRequest.getMethod()}. The default implementation for a method is the
* code executed for standard calls to the method. This argument is ignored if
* {@code compRequest == null}.
* @param context a custom debug context to use for the code installation
* @return a reference to the compiled and ready-to-run installed code
* @throws BailoutException if the code installation failed
*/
@SuppressWarnings("try")
public InstalledCode createInstalledCode(DebugContext debug, ResolvedJavaMethod method, CompilationRequest compilationRequest, CompilationResult compilationResult, SpeculationLog speculationLog, InstalledCode predefinedInstalledCode, boolean isDefault, Object[] context) {
Object[] debugContext = context != null ? context : new Object[] { getProviders().getCodeCache(), method, compilationResult };
CodeInstallationTask[] tasks;
synchronized (this) {
tasks = new CodeInstallationTask[codeInstallationTaskFactories.size()];
for (int i = 0; i < codeInstallationTaskFactories.size(); i++) {
tasks[i] = codeInstallationTaskFactories.get(i).create();
}
}
try (DebugContext.Scope s2 = debug.scope("CodeInstall", debugContext);
DebugContext.Activation a = debug.activate()) {
InstalledCode installedCode;
try {
preCodeInstallationTasks(tasks, compilationResult, predefinedInstalledCode);
CompiledCode compiledCode = createCompiledCode(method, compilationRequest, compilationResult);
installedCode = getProviders().getCodeCache().installCode(method, compiledCode, predefinedInstalledCode, speculationLog, isDefault);
assert predefinedInstalledCode == null || installedCode == predefinedInstalledCode;
} catch (Throwable t) {
failCodeInstallationTasks(tasks, t);
throw t;
}
postCodeInstallationTasks(tasks, installedCode);
return installedCode;
} catch (Throwable e) {
throw debug.handle(e);
}
}
Aggregations