コード例 #1
0
 @ExplodeLoop
 private void initFrame(VirtualFrame frame, Page page) {
   for (FrameMapping frameMapping : mapping) {
     frame.setObject(frameMapping.getFrameSlot(), getColumnSlow(page, frameMapping));
   }
   frame.setDouble(reduceNode.getSlot(), 0.0);
 }
コード例 #2
0
ファイル: FormatRootNode.java プロジェクト: jruby/jruby
  @Override
  public Object execute(VirtualFrame frame) {
    frame.setObject(FormatFrameDescriptor.SOURCE_SLOT, frame.getArguments()[0]);
    frame.setInt(FormatFrameDescriptor.SOURCE_LENGTH_SLOT, (int) frame.getArguments()[1]);
    frame.setInt(FormatFrameDescriptor.SOURCE_POSITION_SLOT, 0);
    frame.setObject(FormatFrameDescriptor.OUTPUT_SLOT, new byte[expectedLength]);
    frame.setInt(FormatFrameDescriptor.OUTPUT_POSITION_SLOT, 0);
    frame.setInt(FormatFrameDescriptor.STRING_LENGTH_SLOT, 0);
    frame.setInt(FormatFrameDescriptor.STRING_CODE_RANGE_SLOT, CodeRange.CR_UNKNOWN.toInt());
    frame.setBoolean(FormatFrameDescriptor.TAINT_SLOT, false);

    child.execute(frame);

    final int outputLength;

    try {
      outputLength = frame.getInt(FormatFrameDescriptor.OUTPUT_POSITION_SLOT);
    } catch (FrameSlotTypeException e) {
      throw new IllegalStateException(e);
    }

    if (outputLength > expectedLength) {
      CompilerDirectives.transferToInterpreterAndInvalidate();

      /*
       * Don't over-compensate and allocate 2x or something like that for next time, as we have to copy the
       * byte[] at the end if it's too big to make it fit its contents. In the ideal case the byte[] is exactly
       * the right size. If we have to keep making it bigger in the slow-path, we can live with that.
       */

      expectedLength = outputLength;
    }

    final byte[] output;

    try {
      output = (byte[]) frame.getObject(FormatFrameDescriptor.OUTPUT_SLOT);
    } catch (FrameSlotTypeException e) {
      throw new IllegalStateException(e);
    }

    final boolean taint;

    try {
      taint = frame.getBoolean(FormatFrameDescriptor.TAINT_SLOT);
    } catch (FrameSlotTypeException e) {
      throw new IllegalStateException(e);
    }

    final int stringLength;

    if (encoding == FormatEncoding.UTF_8) {
      try {
        stringLength = frame.getInt(FormatFrameDescriptor.STRING_LENGTH_SLOT);
      } catch (FrameSlotTypeException e) {
        throw new IllegalStateException(e);
      }
    } else {
      stringLength = outputLength;
    }

    final CodeRange stringCodeRange;

    try {
      stringCodeRange =
          CodeRange.fromInt(frame.getInt(FormatFrameDescriptor.STRING_CODE_RANGE_SLOT));
    } catch (FrameSlotTypeException e) {
      throw new IllegalStateException(e);
    }

    return new BytesResult(output, outputLength, stringLength, stringCodeRange, taint, encoding);
  }