corda/classpath/avian/Stream.java
Joel Dice c743140e08 add new subroutine test
This test covers the case where a local stack slot is first used to
store an object reference and later to store a subroutine return
address.  Unfortunately, this confuses the VM's stack mapping code;
I'll be working on a fix for that next.

The new test requires generating bytecode from scratch, since there's
no reliable way to get javac to generate the code we want.  Since we
already had primitive bytecode construction code in Proxy.java, I
factored it out so we can reuse it in Subroutine.java.
2011-02-16 11:41:33 -07:00

81 lines
2.4 KiB
Java

/* Copyright (c) 2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
package avian;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.io.EOFException;
public abstract class Stream {
public static void write1(OutputStream out, int v) throws IOException {
out.write(v & 0xFF);
}
public static int read1(InputStream in) throws IOException {
return in.read();
}
public static void write2(OutputStream out, int v) throws IOException {
out.write((v >>> 8) & 0xFF);
out.write((v ) & 0xFF);
}
public static int read2(InputStream in) throws IOException {
int b1 = in.read();
int b2 = in.read();
if (b2 == -1) throw new EOFException();
return ((b1 << 8) | (b2 & 0xFF));
}
public static void write4(OutputStream out, int v) throws IOException {
out.write((v >>> 24) & 0xFF);
out.write((v >>> 16) & 0xFF);
out.write((v >>> 8) & 0xFF);
out.write((v ) & 0xFF);
}
public static int read4(InputStream in) throws IOException {
int b1 = in.read();
int b2 = in.read();
int b3 = in.read();
int b4 = in.read();
if (b4 == -1) throw new EOFException();
return ((b1 << 24) | (b2 << 16) | (b3 << 8) | (b4));
}
public static void write8(OutputStream out, long v) throws IOException {
write4(out, (int) (v >>> 32) & 0xFFFFFFFF);
write4(out, (int) (v ) & 0xFFFFFFFF);
}
public static long read8(InputStream in) throws IOException {
long b1 = in.read();
long b2 = in.read();
long b3 = in.read();
long b4 = in.read();
long b5 = in.read();
long b6 = in.read();
long b7 = in.read();
long b8 = in.read();
if (b8 == -1) throw new EOFException();
return ((b1 << 56) | (b2 << 48) | (b3 << 40) | (b4 << 32) |
(b5 << 24) | (b6 << 16) | (b7 << 8) | (b8));
}
public static void set4(byte[] array, int offset, int v) {
array[offset ] = (byte) ((v >>> 24) & 0xFF);
array[offset + 1] = (byte) ((v >>> 16) & 0xFF);
array[offset + 2] = (byte) ((v >>> 8) & 0xFF);
array[offset + 3] = (byte) ((v ) & 0xFF);
}
}