Esempio n. 1
0
 public EdgesTest() {
   node = new TestNode();
   i1 = ConstantNode.forInt(1, graph);
   i2 = ConstantNode.forDouble(1.0d, graph);
   i3 = ConstantNode.forInt(4, graph);
   i4 = ConstantNode.forInt(14, graph);
   node.itail = new NodeInputList<>(node, new ValueNode[] {i3, i4});
   node.i1 = i1;
   node.i2 = i2;
   graph.add(node);
   inputs = node.getNodeClass().getInputEdges();
 }
 @Override
 protected boolean checkLowTierGraph(StructuredGraph graph) {
   for (ConstantNode constantNode : graph.getNodes().filter(ConstantNode.class)) {
     assert constantNode.asJavaConstant() == null
             || constantNode.asJavaConstant().getJavaKind() != JavaKind.Object
             || constantNode.asJavaConstant().isDefaultForKind()
         : "Found unexpected object constant "
             + constantNode
             + ", this should have been removed by the LoadJavaMirrorWithKlassPhase.";
   }
   return true;
 }
  private ValueNode computeBase(ValueNode base, ValueNode pos) {
    FixedWithNextNode basePtr = graph().add(new GetObjectAddressNode(base));
    graph().addBeforeFixed(this, basePtr);

    int shift = CodeUtil.log2(getArrayIndexScale(JavaKind.Object));
    ValueNode scaledIndex =
        graph().unique(new LeftShiftNode(pos, ConstantNode.forInt(shift, graph())));
    ValueNode offset =
        graph()
            .unique(
                new AddNode(
                    scaledIndex,
                    ConstantNode.forInt(getArrayBaseOffset(JavaKind.Object), graph())));
    return graph().unique(new OffsetAddressNode(basePtr, offset));
  }
Esempio n. 4
0
 public void lower(ArrayCopySlowPathNode arraycopy, LoweringTool tool) {
   StructuredGraph graph = arraycopy.graph();
   if (!graph.getGuardsStage().areFrameStatesAtDeopts()) {
     // Can't be lowered yet
     return;
   }
   SnippetInfo snippetInfo = arraycopy.getSnippet();
   Arguments args = new Arguments(snippetInfo, graph.getGuardsStage(), tool.getLoweringStage());
   args.add("nonNullSrc", arraycopy.getSource());
   args.add("srcPos", arraycopy.getSourcePosition());
   args.add("nonNullDest", arraycopy.getDestination());
   args.add("destPos", arraycopy.getDestinationPosition());
   if (snippetInfo == arraycopyUnrolledWorkSnippet) {
     args.addConst("length", ((Integer) arraycopy.getArgument()).intValue());
     args.addConst("elementKind", arraycopy.getElementKind());
   } else {
     args.add("length", arraycopy.getLength());
   }
   if (snippetInfo == arraycopyPredictedObjectWorkSnippet) {
     HotSpotResolvedObjectType arrayKlass =
         (HotSpotResolvedObjectType) tool.getMetaAccess().lookupJavaType(Object[].class);
     ValueNode objectArrayKlass =
         ConstantNode.forConstant(
             KlassPointerStamp.klassNonNull(),
             arrayKlass.klass(),
             tool.getMetaAccess(),
             arraycopy.graph());
     args.add("objectArrayKlass", objectArrayKlass);
     args.addConst("counter", arraycopyCallCounters.get(JavaKind.Object));
     args.addConst("copiedCounter", arraycopyCallCopiedCounters.get(JavaKind.Object));
   }
   instantiate(args, arraycopy);
 }
Esempio n. 5
0
 private StructuredGraph parseAndProcess(String snippet) {
   StructuredGraph graph = parse(snippet);
   LocalNode local = graph.getNodes(LocalNode.class).first();
   ConstantNode constant = ConstantNode.forInt(0, graph);
   for (Node n : local.usages().filter(isNotA(FrameState.class)).snapshot()) {
     n.replaceFirstInput(local, constant);
   }
   Map<Invoke, Double> hints = new HashMap<>();
   for (Invoke invoke : graph.getInvokes()) {
     hints.put(invoke, 1000d);
   }
   Assumptions assumptions = new Assumptions(false);
   new InliningPhase(
           runtime(),
           hints,
           replacements,
           assumptions,
           null,
           getDefaultPhasePlan(),
           OptimisticOptimizations.ALL)
       .apply(graph);
   new CanonicalizerPhase.Instance(runtime(), assumptions, true).apply(graph);
   new DeadCodeEliminationPhase().apply(graph);
   return graph;
 }
Esempio n. 6
0
  /**
   * Creates a graph for this stub.
   *
   * <p>If the stub returns an object, the graph created corresponds to this pseudo code:
   *
   * <pre>
   *     Object foreignFunctionStub(args...) {
   *         foreignFunction(currentThread,  args);
   *         if (clearPendingException(thread())) {
   *             getAndClearObjectResult(thread());
   *             DeoptimizeCallerNode.deopt(InvalidateReprofile, RuntimeConstraint);
   *         }
   *         return verifyObject(getAndClearObjectResult(thread()));
   *     }
   * </pre>
   *
   * If the stub returns a primitive or word, the graph created corresponds to this pseudo code
   * (using {@code int} as the primitive return type):
   *
   * <pre>
   *     int foreignFunctionStub(args...) {
   *         int result = foreignFunction(currentThread,  args);
   *         if (clearPendingException(thread())) {
   *             DeoptimizeCallerNode.deopt(InvalidateReprofile, RuntimeConstraint);
   *         }
   *         return result;
   *     }
   * </pre>
   *
   * If the stub is void, the graph created corresponds to this pseudo code:
   *
   * <pre>
   *     void foreignFunctionStub(args...) {
   *         foreignFunction(currentThread,  args);
   *         if (clearPendingException(thread())) {
   *             DeoptimizeCallerNode.deopt(InvalidateReprofile, RuntimeConstraint);
   *         }
   *     }
   * </pre>
   *
   * In each example above, the {@code currentThread} argument is the C++ JavaThread value (i.e.,
   * %r15 on AMD64) and is only prepended if {@link #prependThread} is true.
   */
  @Override
  protected StructuredGraph getGraph() {
    WordTypes wordTypes = providers.getWordTypes();
    Class<?>[] args = linkage.getDescriptor().getArgumentTypes();
    boolean isObjectResult =
        !linkage.getOutgoingCallingConvention().getReturn().getLIRKind().isValue();

    StructuredGraph graph = new StructuredGraph(toString(), null, AllowAssumptions.NO);
    graph.disableUnsafeAccessTracking();

    GraphKit kit = new GraphKit(graph, providers, wordTypes, providers.getGraphBuilderPlugins());
    ParameterNode[] params = createParameters(kit, args);

    ReadRegisterNode thread =
        kit.append(
            new ReadRegisterNode(
                providers.getRegisters().getThreadRegister(),
                wordTypes.getWordKind(),
                true,
                false));
    ValueNode result = createTargetCall(kit, params, thread);
    kit.createInvoke(
        StubUtil.class,
        "handlePendingException",
        thread,
        ConstantNode.forBoolean(isObjectResult, graph));
    if (isObjectResult) {
      InvokeNode object =
          kit.createInvoke(HotSpotReplacementsUtil.class, "getAndClearObjectResult", thread);
      result = kit.createInvoke(StubUtil.class, "verifyObject", object);
    }
    kit.append(
        new ReturnNode(linkage.getDescriptor().getResultType() == void.class ? null : result));

    if (Debug.isDumpEnabled()) {
      Debug.dump(graph, "Initial stub graph");
    }

    kit.inlineInvokes();

    if (Debug.isDumpEnabled()) {
      Debug.dump(graph, "Stub graph before compilation");
    }

    return graph;
  }