protected ConstantNode defaultElementValue() { return ConstantNode.defaultForKind(elementType().getJavaKind(), graph()); }
protected NewArrayNode createNewArray(ResolvedJavaType elementType, ValueNode length, boolean fillContents) { return new NewArrayNode(elementType, length, fillContents); }
@Override @SuppressWarnings("try") public void simplify(SimplifierTool tool) { if (hasNoUsages()) { NodeView view = NodeView.from(tool); Stamp lengthStamp = length().stamp(view); if (lengthStamp instanceof IntegerStamp) { IntegerStamp lengthIntegerStamp = (IntegerStamp) lengthStamp; if (lengthIntegerStamp.isPositive()) { GraphUtil.removeFixedWithUnusedInputs(this); return; } } // Should be areFrameStatesAtSideEffects but currently SVM will complain about // RuntimeConstraint if (graph().getGuardsStage().allowsFloatingGuards()) { try (DebugCloseable context = this.withNodeSourcePosition()) { LogicNode lengthNegativeCondition = CompareNode.createCompareNode(graph(), CanonicalCondition.LT, length(), ConstantNode.forInt(0, graph()), tool.getConstantReflection(), view); // we do not have a non-deopting path for that at the moment so action=None. FixedGuardNode guard = graph().add(new FixedGuardNode(lengthNegativeCondition, DeoptimizationReason.RuntimeConstraint, DeoptimizationAction.None, true)); graph().replaceFixedWithFixed(this, guard); } } } } }
@Override public void lower(NewArrayNode node, LoweringTool tool) { if (node.graph().getGuardsStage() != StructuredGraph.GuardsStage.AFTER_FSA) { return; } SharedType type = (SharedType) node.elementType().getArrayClass(); Arguments args = new Arguments(newArray, node.graph().getGuardsStage(), tool.getLoweringStage()); args.add("hub", type.getHub()); args.add("length", node.length()); args.addConst("layoutEncoding", type.getHub().getLayoutEncoding()); args.addConst("fillContents", node.fillContents()); addCounterArgs(args, node, type); template(node, args).instantiate(providers.getMetaAccess(), node, SnippetTemplate.DEFAULT_REPLACER, args); } }
protected VirtualArrayNode createVirtualArrayNode(int constantLength) { return new VirtualArrayNode(elementType(), constantLength); }
NewArrayNode newArrayNode = (NewArrayNode) node; PEAppendGraphBuilderContext graphBuilderContext = new PEAppendGraphBuilderContext(methodScope, newArrayNode); ResolvedJavaType elementType = newArrayNode.elementType(); ValueNode length = newArrayNode.length(); for (NodePlugin nodePlugin : nodePlugins) { if (nodePlugin.handleNewArray(graphBuilderContext, elementType, length)) {
@Override public void virtualize(VirtualizerTool tool) { ValueNode lengthAlias = tool.getAlias(length()); if (lengthAlias.asConstant() != null) { int constantLength = lengthAlias.asJavaConstant().asInt(); if (constantLength >= 0 && constantLength < tool.getMaximumEntryCount()) { ValueNode[] state = new ValueNode[constantLength]; ConstantNode defaultForKind = constantLength == 0 ? null : defaultElementValue(); for (int i = 0; i < constantLength; i++) { state[i] = defaultForKind; } VirtualObjectNode virtualObject = createVirtualArrayNode(constantLength); tool.createVirtualObject(virtualObject, state, Collections.<MonitorIdNode> emptyList(), false); tool.replaceWithVirtual(virtualObject); } } }
ValueNode newArrayLengthNode = newArray.length(); if (!newArrayLengthNode.isJavaConstant()) { assert newArray.successors().count() <= 1 : "Detected node with multiple successors: " + newArray; Node successor = newArray.successors().first(); while (successor instanceof StoreIndexedNode) { StoreIndexedNode store = (StoreIndexedNode) successor;
public static ValueNode create(ValueNode forValue, ConstantReflectionProvider constantReflection) { if (forValue instanceof NewArrayNode) { NewArrayNode newArray = (NewArrayNode) forValue; return newArray.length(); } ValueNode length = readArrayLength(forValue, constantReflection); if (length != null) { return length; } return new ArrayLengthNode(forValue); }
public static Object newUninitializedArray(Class<?> elementType, int length) { return newArray(elementType, length, false); }
StructuredGraph graph = newArrayNode.graph(); ResolvedJavaType elementType = newArrayNode.elementType(); HotSpotResolvedObjectType arrayType = (HotSpotResolvedObjectType) elementType.getArrayClass(); JavaKind elementKind = elementType.getJavaKind(); ValueNode length = newArrayNode.length(); args.add("length", length.isAlive() ? length : graph.addOrUniqueWithInputs(length)); assert arrayType.prototypeMarkWord() == lookupArrayClass(tool, JavaKind.Object).prototypeMarkWord() : "all array types are assumed to have the same prototypeMarkWord"; args.addConst("headerSize", headerSize); args.addConst("log2ElementSize", log2ElementSize); args.addConst("fillContents", newArrayNode.fillContents()); args.addConst("threadRegister", registers.getThreadRegister()); args.addConst("maybeUnroll", length.isConstant());
protected void processNewArray(NewArrayNode node, TypeFlowsOfNodes state) { AnalysisType type = ((AnalysisType) node.elementType()).getArrayClass(); assert type.isInstantiated(); Object key = uniqueKey(node); BytecodeLocation allocationLabel = bb.analysisPolicy().createAllocationSite(bb, key, method); TypeFlowBuilder<?> newArrayBuilder = TypeFlowBuilder.create(bb, node, NewInstanceTypeFlow.class, () -> { NewInstanceTypeFlow newArray = createNewArrayTypeFlow(node, type, allocationLabel); methodFlow.addAllocation(newArray); return newArray; }); state.add(node, newArrayBuilder); }
AnalysisType type = ((AnalysisType) node.elementType()).getArrayClass(); type.registerAsAllocated(node);
protected NewArrayNode createNewArrayFromVirtual(VirtualObjectNode virtual, ValueNode length) { return new NewArrayNode(((VirtualArrayNode) virtual).componentType(), length, true); }
/** Hook for subclasses to instantiate a subclass of {@link NewArrayNode}. */ protected NewArrayNode createNewArrayNode(ResolvedJavaType type) { return new NewArrayNode(type, length(), fillContents(), stateBefore()); }
@Override public boolean execute(GraphBuilderContext b, ResolvedJavaMethod targetMethod, InvocationPlugin.Receiver receiver, ValueNode[] args) { jdk.vm.ci.meta.ResolvedJavaType arg0; if (args[0].isConstant()) { jdk.vm.ci.meta.JavaConstant cst = args[0].asJavaConstant(); arg0 = b.getConstantReflection().asJavaType(cst); if (arg0 == null) { arg0 = snippetReflection.asObject(jdk.vm.ci.meta.ResolvedJavaType.class, cst); } } else { assert b.canDeferPlugin(this) : b.getClass().toString(); return false; } ValueNode arg1 = args[1]; boolean arg2; if (args[2].isConstant()) { arg2 = args[2].asJavaConstant().asInt() != 0; } else { assert b.canDeferPlugin(this) : b.getClass().toString(); return false; } org.graalvm.compiler.nodes.java.NewArrayNode node = new org.graalvm.compiler.nodes.java.NewArrayNode(arg0, arg1, arg2); b.addPush(JavaKind.Object, node); return true; } @Override
private ValueNode newArray(HostedProviders providers, JNIGraphKit kit, List<ValueNode> arguments) { ResolvedJavaType elementType = providers.getMetaAccess().lookupJavaType(elementKind.toJavaClass()); ValueNode length = arguments.get(1); ConstantNode zero = kit.createInt(0); kit.startIf(new IntegerLessThanNode(length, zero), BranchProbabilityNode.VERY_SLOW_PATH_PROBABILITY); kit.thenPart(); ValueNode nullHandle = kit.createConstant(JavaConstant.INT_0, providers.getWordTypes().getWordKind()); kit.elsePart(); ValueNode array = kit.append(new NewArrayNode(elementType, length, true)); ValueNode arrayHandle = kit.boxObjectInLocalHandle(array); AbstractMergeNode merge = kit.endIf(); Stamp handleStamp = providers.getWordTypes().getWordStamp(providers.getMetaAccess().lookupJavaType(JNIObjectHandle.class)); return kit.unique(new ValuePhiNode(handleStamp, merge, new ValueNode[]{nullHandle, arrayHandle})); }