use of jdk.vm.ci.code.site.DataPatch in project graal by oracle.
the class HotSpotCompiledCodeBuilder method createCompiledCode.
public static HotSpotCompiledCode createCompiledCode(CodeCacheProvider codeCache, ResolvedJavaMethod method, HotSpotCompilationRequest compRequest, CompilationResult compResult) {
String name = compResult.getName();
byte[] targetCode = compResult.getTargetCode();
int targetCodeSize = compResult.getTargetCodeSize();
Site[] sites = getSortedSites(codeCache, compResult);
Assumption[] assumptions = compResult.getAssumptions();
ResolvedJavaMethod[] methods = compResult.getMethods();
List<CodeAnnotation> annotations = compResult.getAnnotations();
Comment[] comments = new Comment[annotations.size()];
if (!annotations.isEmpty()) {
for (int i = 0; i < comments.length; i++) {
CodeAnnotation annotation = annotations.get(i);
String text;
if (annotation instanceof CodeComment) {
CodeComment codeComment = (CodeComment) annotation;
text = codeComment.value;
} else if (annotation instanceof JumpTable) {
JumpTable jumpTable = (JumpTable) annotation;
text = "JumpTable [" + jumpTable.low + " .. " + jumpTable.high + "]";
} else {
text = annotation.toString();
}
comments[i] = new Comment(annotation.position, text);
}
}
DataSection data = compResult.getDataSection();
byte[] dataSection = new byte[data.getSectionSize()];
ByteBuffer buffer = ByteBuffer.wrap(dataSection).order(ByteOrder.nativeOrder());
Builder<DataPatch> patchBuilder = Stream.builder();
data.buildDataSection(buffer, (position, vmConstant) -> {
patchBuilder.accept(new DataPatch(position, new ConstantReference(vmConstant)));
});
int dataSectionAlignment = data.getSectionAlignment();
DataPatch[] dataSectionPatches = patchBuilder.build().toArray(len -> new DataPatch[len]);
int totalFrameSize = compResult.getTotalFrameSize();
StackSlot customStackArea = compResult.getCustomStackArea();
boolean isImmutablePIC = compResult.isImmutablePIC();
if (method instanceof HotSpotResolvedJavaMethod) {
HotSpotResolvedJavaMethod hsMethod = (HotSpotResolvedJavaMethod) method;
int entryBCI = compResult.getEntryBCI();
boolean hasUnsafeAccess = compResult.hasUnsafeAccess();
int id;
long jvmciEnv;
if (compRequest != null) {
id = compRequest.getId();
jvmciEnv = compRequest.getJvmciEnv();
} else {
id = hsMethod.allocateCompileId(entryBCI);
jvmciEnv = 0L;
}
return new HotSpotCompiledNmethod(name, targetCode, targetCodeSize, sites, assumptions, methods, comments, dataSection, dataSectionAlignment, dataSectionPatches, isImmutablePIC, totalFrameSize, customStackArea, hsMethod, entryBCI, id, jvmciEnv, hasUnsafeAccess);
} else {
return new HotSpotCompiledCode(name, targetCode, targetCodeSize, sites, assumptions, methods, comments, dataSection, dataSectionAlignment, dataSectionPatches, isImmutablePIC, totalFrameSize, customStackArea);
}
}
use of jdk.vm.ci.code.site.DataPatch in project graal by oracle.
the class Stub method checkStubInvariants.
/**
* Checks the conditions a compilation must satisfy to be installed as a RuntimeStub.
*/
private boolean checkStubInvariants(CompilationResult compResult) {
assert compResult.getExceptionHandlers().isEmpty() : this;
// assumptions and there is no point in recording evol_method dependencies
assert compResult.getAssumptions() == null : "stubs should not use assumptions: " + this;
for (DataPatch data : compResult.getDataPatches()) {
if (data.reference instanceof ConstantReference) {
ConstantReference ref = (ConstantReference) data.reference;
if (ref.getConstant() instanceof HotSpotMetaspaceConstant) {
HotSpotMetaspaceConstant c = (HotSpotMetaspaceConstant) ref.getConstant();
if (c.asResolvedJavaType() != null && c.asResolvedJavaType().getName().equals("[I")) {
// embedding the type '[I' is safe, since it is never unloaded
continue;
}
}
}
assert !(data.reference instanceof ConstantReference) : this + " cannot have embedded object or metadata constant: " + data.reference;
}
for (Infopoint infopoint : compResult.getInfopoints()) {
assert infopoint instanceof Call : this + " cannot have non-call infopoint: " + infopoint;
Call call = (Call) infopoint;
assert call.target instanceof HotSpotForeignCallLinkage : this + " cannot have non runtime call: " + call.target;
HotSpotForeignCallLinkage callLinkage = (HotSpotForeignCallLinkage) call.target;
assert !callLinkage.isCompiledStub() || callLinkage.getDescriptor().equals(UNCOMMON_TRAP_HANDLER) : this + " cannot call compiled stub " + callLinkage;
}
return true;
}
use of jdk.vm.ci.code.site.DataPatch in project graal by oracle.
the class InstalledCodeBuilder method patchData.
private void patchData(AMD64InstructionPatcher patcher) {
for (DataPatch dataPatch : compilation.getDataPatches()) {
DataSectionReference ref = (DataSectionReference) dataPatch.reference;
int pcDisplacement = constantsOffset + ref.getOffset() - dataPatch.pcOffset;
patcher.findPatchData(dataPatch.pcOffset, pcDisplacement).apply(compiledBytes);
}
}
use of jdk.vm.ci.code.site.DataPatch in project graal by oracle.
the class GraalCompiler method emitCode.
@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) {
DebugContext debug = lirGenRes.getLIR().getDebug();
try (DebugCloseable a = EmitCode.start(debug)) {
FrameMap frameMap = lirGenRes.getFrameMap();
CompilationResultBuilder crb = backend.newCompilationResultBuilder(lirGenRes, frameMap, compilationResult, factory);
backend.emitCode(crb, lirGenRes.getLIR(), installedCodeOwner);
if (assumptions != null && !assumptions.isEmpty()) {
compilationResult.setAssumptions(assumptions.toArray());
}
if (rootMethod != null) {
compilationResult.setMethods(rootMethod, inlinedMethods);
compilationResult.setFields(accessedFields);
compilationResult.setBytecodeSize(bytecodeSize);
}
crb.finish();
if (debug.isCountEnabled()) {
List<DataPatch> ldp = compilationResult.getDataPatches();
JavaKind[] kindValues = JavaKind.values();
CounterKey[] dms = new CounterKey[kindValues.length];
for (int i = 0; i < dms.length; i++) {
dms[i] = DebugContext.counter("DataPatches-%s", kindValues[i]);
}
for (DataPatch dp : ldp) {
JavaKind kind = JavaKind.Illegal;
if (dp.reference instanceof ConstantReference) {
VMConstant constant = ((ConstantReference) dp.reference).getConstant();
if (constant instanceof JavaConstant) {
kind = ((JavaConstant) constant).getJavaKind();
}
}
dms[kind.ordinal()].add(debug, 1);
}
DebugContext.counter("CompilationResults").increment(debug);
DebugContext.counter("CodeBytesEmitted").add(debug, compilationResult.getTargetCodeSize());
DebugContext.counter("InfopointsEmitted").add(debug, compilationResult.getInfopoints().size());
DebugContext.counter("DataPatches").add(debug, ldp.size());
DebugContext.counter("ExceptionHandlersEmitted").add(debug, compilationResult.getExceptionHandlers().size());
}
debug.dump(DebugContext.BASIC_LEVEL, compilationResult, "After code generation");
}
}
use of jdk.vm.ci.code.site.DataPatch in project graal by oracle.
the class CompilationResult method recordDataPatch.
/**
* Records a data patch in the code section. The data patch can refer to something in the
* {@link DataSectionReference data section} or directly to an {@link ConstantReference inlined
* constant}.
*
* @param codePos the position in the code that needs to be patched
* @param ref the reference that should be inserted in the code
*/
public void recordDataPatch(int codePos, Reference ref) {
checkOpen();
assert codePos >= 0 && ref != null;
dataPatches.add(new DataPatch(codePos, ref));
}
Aggregations