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); }
@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()) {
@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); } }
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";
PEAppendGraphBuilderContext graphBuilderContext = new PEAppendGraphBuilderContext(methodScope, newArrayNode); ResolvedJavaType elementType = newArrayNode.elementType(); ValueNode length = newArrayNode.length(); for (NodePlugin nodePlugin : nodePlugins) { if (nodePlugin.handleNewArray(graphBuilderContext, elementType, length)) {