Exemplo n.º 1
0
    /**
     * Instantiate the snippet template and fix up the FrameState of any Invokes of System.arraycopy
     * and propagate the captured bci in the ArrayCopySlowPathNode.
     *
     * @param args
     * @param arraycopy
     */
    private void instantiate(Arguments args, BasicArrayCopyNode arraycopy) {
      StructuredGraph graph = arraycopy.graph();
      SnippetTemplate template = template(args);
      Map<Node, Node> replacements =
          template.instantiate(
              providers.getMetaAccess(), arraycopy, SnippetTemplate.DEFAULT_REPLACER, args);
      for (Node originalNode : replacements.keySet()) {
        if (originalNode instanceof Invoke) {
          Invoke invoke = (Invoke) replacements.get(originalNode);
          assert invoke.asNode().graph() == graph;
          CallTargetNode call = invoke.callTarget();

          if (!call.targetMethod().equals(originalArraycopy)) {
            throw new GraalError("unexpected invoke %s in snippet", call.targetMethod());
          }
          // Here we need to fix the bci of the invoke
          InvokeNode newInvoke = graph.add(new InvokeNode(invoke.callTarget(), arraycopy.getBci()));
          if (arraycopy.stateDuring() != null) {
            newInvoke.setStateDuring(arraycopy.stateDuring());
          } else {
            assert arraycopy.stateAfter() != null;
            newInvoke.setStateAfter(arraycopy.stateAfter());
          }
          graph.replaceFixedWithFixed((InvokeNode) invoke.asNode(), newInvoke);
        } else if (originalNode instanceof ArrayCopySlowPathNode) {
          ArrayCopySlowPathNode slowPath = (ArrayCopySlowPathNode) replacements.get(originalNode);
          assert arraycopy.stateAfter() != null;
          slowPath.setStateAfter(arraycopy.stateAfter());
          slowPath.setBci(arraycopy.getBci());
        }
      }
    }
Exemplo n.º 2
0
    public static JavaKind selectComponentKind(BasicArrayCopyNode arraycopy, boolean exact) {
      ResolvedJavaType srcType = StampTool.typeOrNull(arraycopy.getSource().stamp());
      ResolvedJavaType destType = StampTool.typeOrNull(arraycopy.getDestination().stamp());

      if (srcType == null || !srcType.isArray() || destType == null || !destType.isArray()) {
        if (!exact) {
          JavaKind component = getComponentKind(srcType);
          if (component != null) {
            return component;
          }
          return getComponentKind(destType);
        }
        return null;
      }
      if (exact) {
        if (!destType.getComponentType().isAssignableFrom(srcType.getComponentType())) {
          return null;
        }
        if (!arraycopy.isExact()) {
          return null;
        }
      }
      return srcType.getComponentType().getJavaKind();
    }