use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.
the class TraceLocalMoveResolver method addMapping.
public void addMapping(TraceInterval fromInterval, TraceInterval toInterval) {
if (isIllegal(toInterval.location()) && toInterval.canMaterialize()) {
if (debug.isLogEnabled()) {
debug.log("no store to rematerializable interval %s needed", toInterval);
}
return;
}
if (isIllegal(fromInterval.location()) && fromInterval.canMaterialize()) {
// Instead of a reload, re-materialize the value
JavaConstant rematValue = fromInterval.getMaterializedValue();
addMapping(rematValue, toInterval);
return;
}
if (debug.isLogEnabled()) {
debug.log("add move mapping from %s to %s", fromInterval, toInterval);
}
assert fromInterval.operandNumber != toInterval.operandNumber : "from and to interval equal: " + fromInterval;
assert LIRKind.verifyMoveKinds(allocator.getKind(toInterval), allocator.getKind(fromInterval), allocator.getRegisterAllocationConfig()) : String.format("Kind mismatch: %s vs. %s, from=%s, to=%s", allocator.getKind(fromInterval), allocator.getKind(toInterval), fromInterval, toInterval);
mappingFrom.add(fromInterval);
mappingFromOpr.add(null);
mappingTo.add(toInterval);
}
use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.
the class BytecodeParser method genDynamicInvokeHelper.
private boolean genDynamicInvokeHelper(ResolvedJavaMethod target, int cpi, int opcode) {
assert opcode == INVOKEDYNAMIC || opcode == INVOKEVIRTUAL;
InvokeDynamicPlugin invokeDynamicPlugin = graphBuilderConfig.getPlugins().getInvokeDynamicPlugin();
if (opcode == INVOKEVIRTUAL && invokeDynamicPlugin != null && !invokeDynamicPlugin.isResolvedDynamicInvoke(this, cpi, opcode)) {
// regular invokevirtual, let caller handle it
return false;
}
if (GeneratePIC.getValue(options) && (invokeDynamicPlugin == null || !invokeDynamicPlugin.supportsDynamicInvoke(this, cpi, opcode))) {
// bail out if static compiler and no dynamic type support
append(new DeoptimizeNode(InvalidateRecompile, Unresolved));
return true;
}
JavaConstant appendix = constantPool.lookupAppendix(cpi, opcode);
ValueNode appendixNode = null;
if (appendix != null) {
if (invokeDynamicPlugin != null) {
invokeDynamicPlugin.recordDynamicMethod(this, cpi, opcode, target);
// Will perform runtime type checks and static initialization
FrameState stateBefore = frameState.create(bci(), getNonIntrinsicAncestor(), false, null, null);
appendixNode = invokeDynamicPlugin.genAppendixNode(this, cpi, opcode, appendix, stateBefore);
} else {
appendixNode = ConstantNode.forConstant(appendix, metaAccess, graph);
}
frameState.push(JavaKind.Object, appendixNode);
} else if (GeneratePIC.getValue(options)) {
// Need to emit runtime guard and perform static initialization.
// Not implemented yet.
append(new DeoptimizeNode(InvalidateRecompile, Unresolved));
return true;
}
boolean hasReceiver = (opcode == INVOKEDYNAMIC) ? false : !target.isStatic();
ValueNode[] args = frameState.popArguments(target.getSignature().getParameterCount(hasReceiver));
if (hasReceiver) {
appendInvoke(InvokeKind.Virtual, target, args);
} else {
appendInvoke(InvokeKind.Static, target, args);
}
return true;
}
use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.
the class BytecodeParser method genIntegerSwitch.
protected void genIntegerSwitch(ValueNode value, ArrayList<BciBlock> actualSuccessors, int[] keys, double[] keyProbabilities, int[] keySuccessors) {
if (value.isConstant()) {
JavaConstant constant = (JavaConstant) value.asConstant();
int constantValue = constant.asInt();
for (int i = 0; i < keys.length; ++i) {
if (keys[i] == constantValue) {
appendGoto(actualSuccessors.get(keySuccessors[i]));
return;
}
}
appendGoto(actualSuccessors.get(keySuccessors[keys.length]));
} else {
this.controlFlowSplit = true;
double[] successorProbabilities = successorProbabilites(actualSuccessors.size(), keySuccessors, keyProbabilities);
IntegerSwitchNode switchNode = append(new IntegerSwitchNode(value, actualSuccessors.size(), keys, keyProbabilities, keySuccessors));
for (int i = 0; i < actualSuccessors.size(); i++) {
switchNode.setBlockSuccessor(i, createBlockTarget(successorProbabilities[i], actualSuccessors.get(i), frameState));
}
}
}
use of jdk.vm.ci.meta.JavaConstant 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.meta.JavaConstant in project graal by oracle.
the class BoxingSnippets method canonicalizeBoxing.
public static FloatingNode canonicalizeBoxing(BoxNode box, MetaAccessProvider metaAccess, ConstantReflectionProvider constantReflection) {
ValueNode value = box.getValue();
if (value.isConstant()) {
JavaConstant sourceConstant = value.asJavaConstant();
if (sourceConstant.getJavaKind() != box.getBoxingKind() && sourceConstant.getJavaKind().isNumericInteger()) {
switch(box.getBoxingKind()) {
case Boolean:
sourceConstant = JavaConstant.forBoolean(sourceConstant.asLong() != 0L);
break;
case Byte:
sourceConstant = JavaConstant.forByte((byte) sourceConstant.asLong());
break;
case Char:
sourceConstant = JavaConstant.forChar((char) sourceConstant.asLong());
break;
case Short:
sourceConstant = JavaConstant.forShort((short) sourceConstant.asLong());
break;
}
}
JavaConstant boxedConstant = constantReflection.boxPrimitive(sourceConstant);
if (boxedConstant != null && sourceConstant.getJavaKind() == box.getBoxingKind()) {
return ConstantNode.forConstant(boxedConstant, metaAccess, box.graph());
}
}
return null;
}
Aggregations