/** {@inheritDoc} */ @Override public void annotate(String msg) { if (annotations == null) { return; } endAnnotation(); annotations.add(new Annotation(cursor, msg)); }
/** {@inheritDoc} */ public void writeByte(int value) { int writeAt = cursor; int end = writeAt + 1; if (stretchy) { ensureCapacity(end); } else if (end > data.length) { throwBounds(); return; } data[writeAt] = (byte) value; cursor = end; }
/** * Returns the contents of this instance as a {@code .dex} file, * in {@code byte[]} form. * * @param humanOut {@code null-ok;} where to write human-oriented output to * @param verbose whether to be verbose when writing human-oriented output * @return {@code non-null;} a {@code .dex} file for this instance */ public byte[] toDex(Writer humanOut, boolean verbose) throws IOException { boolean annotate = (humanOut != null); ByteArrayAnnotatedOutput result = toDex0(annotate, verbose); if (annotate) { result.writeAnnotationsTo(humanOut); } return result.getArray(); }
/** * Emits an {@link DebugInfoConstants#DBG_ADVANCE_PC DBG_ADVANCE_PC} * sequence. * * @param deltaAddress {@code >= 0;} amount to change program counter by * @throws IOException */ private void emitAdvancePc(int deltaAddress) throws IOException { int mark = output.getCursor(); output.writeByte(DBG_ADVANCE_PC); output.writeUleb128(deltaAddress); address += deltaAddress; if (annotateTo != null || debugPrint != null) { annotate(output.getCursor() - mark, String.format("%04x: advance pc", address)); } if (DEBUG) { System.err.printf("Emitting advance_pc for %d\n", deltaAddress); } }
/** * Emits an {@link DebugInfoConstants#DBG_ADVANCE_LINE DBG_ADVANCE_LINE} * sequence. * * @param deltaLines amount to change line number register by * @throws IOException */ private void emitAdvanceLine(int deltaLines) throws IOException { int mark = output.getCursor(); output.writeByte(DBG_ADVANCE_LINE); output.writeSleb128(deltaLines); line += deltaLines; if (annotateTo != null || debugPrint != null) { annotate(output.getCursor() - mark, String.format("line = %d", line)); } if (DEBUG) { System.err.printf("Emitting advance_line for %d\n", deltaLines); } }
ByteArrayAnnotatedOutput out = new ByteArrayAnnotatedOutput(barr); out.enableAnnotations(dumpWidth, verbose); try { Section one = sections[i]; int zeroCount = one.getFileOffset() - out.getCursor(); if (zeroCount < 0) { throw new ExceptionWithContext("excess write of " + (-zeroCount)); out.writeZeroes(one.getFileOffset() - out.getCursor()); one.writeTo(out); } catch (RuntimeException ex) { if (out.getCursor() != fileSize) { throw new RuntimeException("foreshortened write"); "\nmethod code index:\n\n"); getStatistics().writeAnnotation(out); out.finishAnnotating();
public EncodedValue adjustEncodedValue(EncodedValue encodedValue) { ByteArrayAnnotatedOutput out = new ByteArrayAnnotatedOutput(32); new EncodedValueTransformer(encodedValue, out).readValue(); return new EncodedValue(out.toByteArray()); }
/** {@inheritDoc} */ @Override public int writeUleb128(int value) { if (stretchy) { ensureCapacity(cursor + 5); // pessimistic } int cursorBefore = cursor; Leb128.writeUnsignedLeb128(this, value); return (cursor - cursorBefore); }
int width2 = getAnnotationWidth(); int width1 = annotationWidth - width2 - 1;
/** * Emits a {@link DebugInfoConstants#DBG_RESTART_LOCAL DBG_RESTART_LOCAL} * sequence. * * @param entry entry associated with this restart * @throws IOException */ private void emitLocalRestart(LocalList.Entry entry) throws IOException { int mark = output.getCursor(); output.writeByte(DBG_RESTART_LOCAL); emitUnsignedLeb128(entry.getRegister()); if (annotateTo != null || debugPrint != null) { annotate(output.getCursor() - mark, String.format("%04x: +local restart %s", address, entryAnnotationString(entry))); } if (DEBUG) { System.err.println("emit local restart"); } }
ByteArrayAnnotatedOutput out = new ByteArrayAnnotatedOutput(barr); out.enableAnnotations(dumpWidth, verbose); try { Section one = sections[i]; int zeroCount = one.getFileOffset() - out.getCursor(); if (zeroCount < 0) { throw new ExceptionWithContext("excess write of " + (-zeroCount)); out.writeZeroes(one.getFileOffset() - out.getCursor()); one.writeTo(out); } catch (RuntimeException ex) { if (out.getCursor() != fileSize) { throw new RuntimeException("foreshortened write"); "\nmethod code index:\n\n"); getStatistics().writeAnnotation(out); out.finishAnnotating();
/** * Emits an {@link DebugInfoConstants#DBG_ADVANCE_PC DBG_ADVANCE_PC} * sequence. * * @param deltaAddress {@code >= 0;} amount to change program counter by * @throws IOException */ private void emitAdvancePc(int deltaAddress) throws IOException { int mark = output.getCursor(); output.writeByte(DBG_ADVANCE_PC); output.writeUleb128(deltaAddress); address += deltaAddress; if (annotateTo != null || debugPrint != null) { annotate(output.getCursor() - mark, String.format("%04x: advance pc", address)); } if (DEBUG) { System.err.printf("Emitting advance_pc for %d\n", deltaAddress); } }
/** {@inheritDoc} */ @Override protected void place0(Section addedTo, int offset) { // Encode the data and note the size. ByteArrayAnnotatedOutput out = new ByteArrayAnnotatedOutput(); encodeOutput(addedTo.getFile(), out); encodedForm = out.toByteArray(); setWriteSize(encodedForm.length); }
/** * Emits an {@link DebugInfoConstants#DBG_ADVANCE_LINE DBG_ADVANCE_LINE} * sequence. * * @param deltaLines amount to change line number register by * @throws IOException */ private void emitAdvanceLine(int deltaLines) throws IOException { int mark = output.getCursor(); output.writeByte(DBG_ADVANCE_LINE); output.writeSleb128(deltaLines); line += deltaLines; if (annotateTo != null || debugPrint != null) { annotate(output.getCursor() - mark, String.format("line = %d", line)); } if (DEBUG) { System.err.printf("Emitting advance_line for %d\n", deltaLines); } }
/** {@inheritDoc} */ @Override public int writeSleb128(int value) { if (stretchy) { ensureCapacity(cursor + 5); // pessimistic } int cursorBefore = cursor; Leb128.writeSignedLeb128(this, value); return (cursor - cursorBefore); }
int width2 = getAnnotationWidth(); int width1 = annotationWidth - width2 - 1;
ByteArrayAnnotatedOutput out = new ByteArrayAnnotatedOutput(barr); out.enableAnnotations(dumpWidth, verbose); try { Section one = sections[i]; int zeroCount = one.getFileOffset() - out.getCursor(); if (zeroCount < 0) { throw new ExceptionWithContext("excess write of " + (-zeroCount)); out.writeZeroes(one.getFileOffset() - out.getCursor()); one.writeTo(out); } catch (RuntimeException ex) { if (out.getCursor() != fileSize) { throw new RuntimeException("foreshortened write"); "\nmethod code index:\n\n"); getStatistics().writeAnnotation(out); out.finishAnnotating();
/** * Emits an {@link DebugInfoConstants#DBG_ADVANCE_PC DBG_ADVANCE_PC} * sequence. * * @param deltaAddress {@code >= 0;} amount to change program counter by * @throws IOException */ private void emitAdvancePc(int deltaAddress) throws IOException { int mark = output.getCursor(); output.writeByte(DBG_ADVANCE_PC); output.writeUleb128(deltaAddress); address += deltaAddress; if (annotateTo != null || debugPrint != null) { annotate(output.getCursor() - mark, String.format("%04x: advance pc", address)); } if (DEBUG) { System.err.printf("Emitting advance_pc for %d\n", deltaAddress); } }
/** {@inheritDoc} */ @Override protected void place0(Section addedTo, int offset) { // Encode the data and note the size. ByteArrayAnnotatedOutput out = new ByteArrayAnnotatedOutput(); encodeOutput(addedTo.getFile(), out); encodedForm = out.toByteArray(); setWriteSize(encodedForm.length); }
/** {@inheritDoc} */ public void writeByte(int value) { int writeAt = cursor; int end = writeAt + 1; if (stretchy) { ensureCapacity(end); } else if (end > data.length) { throwBounds(); return; } data[writeAt] = (byte) value; cursor = end; }