Skip to content

Commit

Permalink
added SpeculationLog to CompilationResult since ResolvedJavaMethod.ge…
Browse files Browse the repository at this point in the history
…tSpeculationLog can return a new object each time it is called
  • Loading branch information
dougxc committed Feb 18, 2019
1 parent 390f6c8 commit a163bae
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import jdk.vm.ci.meta.InvokeTarget;
import jdk.vm.ci.meta.ResolvedJavaField;
import jdk.vm.ci.meta.ResolvedJavaMethod;
import jdk.vm.ci.meta.SpeculationLog;

/**
* Represents the output from compiling a method, including the compiled machine code, associated
Expand Down Expand Up @@ -220,6 +221,11 @@ public String toString() {
*/
private ResolvedJavaMethod[] methods;

/**
* The {@link SpeculationLog} log used during compilation.
*/
private SpeculationLog speculationLog;

/**
* The list of fields that were accessed from the bytecodes.
*/
Expand Down Expand Up @@ -372,6 +378,21 @@ public ResolvedJavaMethod[] getMethods() {
return methods;
}

/**
* Sets the {@link SpeculationLog} log used during compilation.
*/
public void setSpeculationLog(SpeculationLog speculationLog) {
checkOpen();
this.speculationLog = speculationLog;
}

/**
* Gets the {@link SpeculationLog} log, if any, used during compilation.
*/
public SpeculationLog getSpeculationLog() {
return speculationLog;
}

/**
* Sets the fields that were referenced from the bytecodes that were used as input to the
* compilation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import jdk.vm.ci.meta.JavaKind;
import jdk.vm.ci.meta.ResolvedJavaField;
import jdk.vm.ci.meta.ResolvedJavaMethod;
import jdk.vm.ci.meta.SpeculationLog;
import jdk.vm.ci.meta.VMConstant;

public class LIRCompilerBackend {
Expand All @@ -83,7 +84,17 @@ public static <T extends CompilationResult> void emitBackEnd(StructuredGraph gra
try (DebugContext.Scope s2 = debug.scope("CodeGen", lirGen, lirGen.getLIR())) {
int bytecodeSize = graph.method() == null ? 0 : graph.getBytecodeSize();
compilationResult.setHasUnsafeAccess(graph.hasUnsafeAccess());
emitCode(backend, graph.getAssumptions(), graph.method(), graph.getMethods(), graph.getFields(), bytecodeSize, lirGen, compilationResult, installedCodeOwner, factory);
emitCode(backend,
graph.getAssumptions(),
graph.method(),
graph.getMethods(),
graph.getFields(),
graph.getSpeculationLog(),
bytecodeSize,
lirGen,
compilationResult,
installedCodeOwner,
factory);
} catch (Throwable e) {
throw debug.handle(e);
}
Expand Down Expand Up @@ -172,8 +183,17 @@ private static LIRGenerationResult emitLowLevel(TargetDescription target, LIRGen
}

@SuppressWarnings("try")
public static void emitCode(Backend backend, Assumptions assumptions, ResolvedJavaMethod rootMethod, Collection<ResolvedJavaMethod> inlinedMethods, EconomicSet<ResolvedJavaField> accessedFields,
int bytecodeSize, LIRGenerationResult lirGenRes, CompilationResult compilationResult, ResolvedJavaMethod installedCodeOwner, CompilationResultBuilderFactory factory) {
public static void emitCode(Backend backend,
Assumptions assumptions,
ResolvedJavaMethod rootMethod,
Collection<ResolvedJavaMethod> inlinedMethods,
EconomicSet<ResolvedJavaField> accessedFields,
SpeculationLog speculationLog,
int bytecodeSize,
LIRGenerationResult lirGenRes,
CompilationResult compilationResult,
ResolvedJavaMethod installedCodeOwner,
CompilationResultBuilderFactory factory) {
DebugContext debug = lirGenRes.getLIR().getDebug();
try (DebugCloseable a = EmitCode.start(debug)) {
LIRGenerationProvider lirBackend = (LIRGenerationProvider) backend;
Expand All @@ -189,6 +209,9 @@ public static void emitCode(Backend backend, Assumptions assumptions, ResolvedJa
compilationResult.setFields(accessedFields);
compilationResult.setBytecodeSize(bytecodeSize);
}
if (speculationLog != null) {
compilationResult.setSpeculationLog(speculationLog);
}
crb.finish();
if (debug.isCountEnabled()) {
List<DataPatch> ldp = compilationResult.getDataPatches();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
import jdk.vm.ci.meta.JavaKind;
import jdk.vm.ci.meta.MetaAccessProvider;
import jdk.vm.ci.meta.ResolvedJavaMethod;
import jdk.vm.ci.meta.SpeculationLog;

/**
* Represents a compiler backend for Graal.
Expand Down Expand Up @@ -124,21 +123,28 @@ public LIRKind getValueKind(JavaKind javaKind) {

/**
* @see #createInstalledCode(DebugContext, ResolvedJavaMethod, CompilationRequest,
* CompilationResult, SpeculationLog, InstalledCode, boolean, Object[])
* CompilationResult, InstalledCode, boolean, Object[])
*/
public InstalledCode createInstalledCode(DebugContext debug, ResolvedJavaMethod method, CompilationResult compilationResult,
SpeculationLog speculationLog, InstalledCode predefinedInstalledCode, boolean isDefault) {
return createInstalledCode(debug, method, null, compilationResult, speculationLog, predefinedInstalledCode, isDefault, null);
public InstalledCode createInstalledCode(DebugContext debug,
ResolvedJavaMethod method,
CompilationResult compilationResult,
InstalledCode predefinedInstalledCode,
boolean isDefault) {
return createInstalledCode(debug, method, null, compilationResult, predefinedInstalledCode, isDefault, null);
}

/**
* @see #createInstalledCode(DebugContext, ResolvedJavaMethod, CompilationRequest,
* CompilationResult, SpeculationLog, InstalledCode, boolean, Object[])
* CompilationResult, InstalledCode, boolean, Object[])
*/
@SuppressWarnings("try")
public InstalledCode createInstalledCode(DebugContext debug, ResolvedJavaMethod method, CompilationRequest compilationRequest, CompilationResult compilationResult,
SpeculationLog speculationLog, InstalledCode predefinedInstalledCode, boolean isDefault) {
return createInstalledCode(debug, method, compilationRequest, compilationResult, speculationLog, predefinedInstalledCode, isDefault, null);
public InstalledCode createInstalledCode(DebugContext debug,
ResolvedJavaMethod method,
CompilationRequest compilationRequest,
CompilationResult compilationResult,
InstalledCode predefinedInstalledCode,
boolean isDefault) {
return createInstalledCode(debug, method, compilationRequest, compilationResult, predefinedInstalledCode, isDefault, null);
}

/**
Expand All @@ -151,7 +157,6 @@ public InstalledCode createInstalledCode(DebugContext debug, ResolvedJavaMethod
* @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
Expand All @@ -164,8 +169,13 @@ public InstalledCode createInstalledCode(DebugContext debug, ResolvedJavaMethod
* {@link InstalledCode} object
*/
@SuppressWarnings("try")
public InstalledCode createInstalledCode(DebugContext debug, ResolvedJavaMethod method, CompilationRequest compilationRequest, CompilationResult compilationResult,
SpeculationLog speculationLog, InstalledCode predefinedInstalledCode, boolean isDefault, Object[] context) {
public InstalledCode createInstalledCode(DebugContext debug,
ResolvedJavaMethod method,
CompilationRequest compilationRequest,
CompilationResult compilationResult,
InstalledCode predefinedInstalledCode,
boolean isDefault,
Object[] context) {
Object[] debugContext = context != null ? context : new Object[]{getProviders().getCodeCache(), method, compilationResult};
CodeInstallationTask[] tasks;
synchronized (this) {
Expand All @@ -181,7 +191,7 @@ public InstalledCode createInstalledCode(DebugContext debug, ResolvedJavaMethod
try {
preCodeInstallationTasks(tasks, compilationResult);
CompiledCode compiledCode = createCompiledCode(method, compilationRequest, compilationResult, isDefault, debug.getOptions());
installedCode = getProviders().getCodeCache().installCode(method, compiledCode, predefinedInstalledCode, speculationLog, isDefault);
installedCode = getProviders().getCodeCache().installCode(method, compiledCode, predefinedInstalledCode, compilationResult.getSpeculationLog(), isDefault);
assert predefinedInstalledCode == null || installedCode == predefinedInstalledCode;
} catch (Throwable t) {
failCodeInstallationTasks(tasks, t);
Expand Down Expand Up @@ -225,12 +235,15 @@ private static void postCodeInstallationTasks(CodeInstallationTask[] tasks, Comp
* @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 request or {@code null}
* @param compilationResult the code to be compiled
* @param compilationResult the compiled code
* @return a reference to the compiled and ready-to-run installed code
* @throws BailoutException if the code installation failed
*/
public InstalledCode addInstalledCode(DebugContext debug, ResolvedJavaMethod method, CompilationRequest compilationRequest, CompilationResult compilationResult) {
return createInstalledCode(debug, method, compilationRequest, compilationResult, null, null, false);
public InstalledCode addInstalledCode(DebugContext debug,
ResolvedJavaMethod method,
CompilationRequest compilationRequest,
CompilationResult compilationResult) {
return createInstalledCode(debug, method, compilationRequest, compilationResult, null, false);
}

/**
Expand All @@ -239,12 +252,13 @@ public InstalledCode addInstalledCode(DebugContext debug, ResolvedJavaMethod met
*
* @param method the method compiled to produce {@code compiledCode} or {@code null} if the
* input to {@code compResult} was not a {@link ResolvedJavaMethod}
* @param compilationResult the code to be compiled
* @param compilationResult the compiled code
* @return a reference to the compiled and ready-to-run installed code
* @throws BailoutException if the code installation failed
*/
public InstalledCode createDefaultInstalledCode(DebugContext debug, ResolvedJavaMethod method, CompilationResult compilationResult) {
return createInstalledCode(debug, method, compilationResult, null, null, true);
System.out.println(compilationResult.getSpeculationLog());
return createInstalledCode(debug, method, compilationResult, null, true);
}

/**
Expand All @@ -257,7 +271,11 @@ public CompilationIdentifier getCompilationIdentifier(ResolvedJavaMethod resolve
return CompilationIdentifier.INVALID_COMPILATION_ID;
}

public void emitBackEnd(StructuredGraph graph, Object stub, ResolvedJavaMethod installedCodeOwner, CompilationResult compilationResult, CompilationResultBuilderFactory factory,
public void emitBackEnd(StructuredGraph graph,
Object stub,
ResolvedJavaMethod installedCodeOwner,
CompilationResult compilationResult,
CompilationResultBuilderFactory factory,
RegisterConfig config, LIRSuites lirSuites) {
LIRCompilerBackend.emitBackEnd(graph, stub, installedCodeOwner, this, compilationResult, factory, config, lirSuites);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,14 @@ private void installMethod(DebugContext debug, final CompilationResult compResul
installedCode = null;
Object[] context = {new DebugDumpScope(getIdString(), true), codeCache, getMethod(), compResult};
try (DebugContext.Scope s = debug.scope("CodeInstall", context)) {
installedCode = (HotSpotInstalledCode) backend.createInstalledCode(debug, getRequest().getMethod(), getRequest(), compResult,
getRequest().getMethod().getSpeculationLog(), null, installAsDefault, context);
HotSpotCompilationRequest request = getRequest();
installedCode = (HotSpotInstalledCode) backend.createInstalledCode(debug,
request.getMethod(),
request,
compResult,
null,
installAsDefault,
context);
} catch (Throwable e) {
throw debug.handle(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@
import org.graalvm.compiler.core.common.CompilationIdentifier;
import org.graalvm.compiler.core.common.alloc.ComputeBlockOrder;
import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
import org.graalvm.compiler.core.gen.LIRGenerationProvider;
import org.graalvm.compiler.core.gen.LIRCompilerBackend;
import org.graalvm.compiler.core.gen.LIRGenerationProvider;
import org.graalvm.compiler.core.target.Backend;
import org.graalvm.compiler.debug.DebugHandlersFactory;
import org.graalvm.compiler.debug.DebugContext;
import org.graalvm.compiler.debug.DebugHandlersFactory;
import org.graalvm.compiler.lir.LIR;
import org.graalvm.compiler.lir.asm.CompilationResultBuilderFactory;
import org.graalvm.compiler.lir.gen.LIRGenerationResult;
Expand Down Expand Up @@ -89,6 +89,7 @@
import jdk.vm.ci.meta.ConstantReflectionProvider;
import jdk.vm.ci.meta.MetaAccessProvider;
import jdk.vm.ci.meta.ResolvedJavaMethod;
import jdk.vm.ci.meta.SpeculationLog;

/**
* State providing a new copy of a graph for each invocation of a benchmark. Subclasses of this
Expand Down Expand Up @@ -461,8 +462,10 @@ protected PostAllocationOptimizationContext createPostAllocationOptimizationCont
*/
protected final void emitCode() {
int bytecodeSize = request.graph.method() == null ? 0 : request.graph.getBytecodeSize();
SpeculationLog speculationLog = null;
request.compilationResult.setHasUnsafeAccess(request.graph.hasUnsafeAccess());
LIRCompilerBackend.emitCode(request.backend, request.graph.getAssumptions(), request.graph.method(), request.graph.getMethods(), request.graph.getFields(), bytecodeSize, lirGenRes,
LIRCompilerBackend.emitCode(request.backend, request.graph.getAssumptions(), request.graph.method(), request.graph.getMethods(), request.graph.getFields(),
speculationLog, bytecodeSize, lirGenRes,
request.compilationResult, request.installedCodeOwner, request.factory);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ protected SpeculationLog getSpeculationLog() {

@Override
protected InstalledCode addMethod(DebugContext debug, final ResolvedJavaMethod method, final CompilationResult compilationResult) {
return getBackend().createInstalledCode(debug, method, compilationResult, speculationLog, null, false);
assert speculationLog == compilationResult.getSpeculationLog();
return getBackend().createInstalledCode(debug, method, compilationResult, null, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public CompilationResultBuilder createBuilder(CodeCacheProvider codeCache, Forei
protected void closeCompilationResult() {
CompilationResult result = this.compilationResult;
result.setMethods(graph.method(), graph.getMethods());
result.setSpeculationLog(graph.getSpeculationLog());
result.setBytecodeSize(graph.getBytecodeSize());

Set<Assumption> newAssumptions = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,8 @@ public CompilationResult compilePEGraph(StructuredGraph graph, String name, Phas

try (DebugCloseable a = CodeInstallationTime.start(debug); DebugCloseable c = CodeInstallationMemUse.start(debug)) {
InstalledCode installedCode = createInstalledCode(compilable);

backend.createInstalledCode(debug, graph.method(), compilationRequest, result, graph.getSpeculationLog(), installedCode, false);
assert graph.getSpeculationLog() == result.getSpeculationLog();
backend.createInstalledCode(debug, graph.method(), compilationRequest, result, installedCode, false);
} catch (Throwable e) {
throw debug.handle(e);
}
Expand Down

0 comments on commit a163bae

Please sign in to comment.