2007-10-24 21:06:02 +00:00
|
|
|
public class Misc {
|
2008-02-17 20:57:40 +00:00
|
|
|
private static int alpha;
|
|
|
|
private static int beta;
|
|
|
|
private static byte byte1, byte2, byte3;
|
2008-04-01 00:34:57 +00:00
|
|
|
|
2008-02-17 20:57:40 +00:00
|
|
|
private int gamma;
|
2008-04-01 00:34:57 +00:00
|
|
|
private int pajama;
|
|
|
|
private boolean boolean1;
|
|
|
|
private boolean boolean2;
|
|
|
|
private long time;
|
|
|
|
|
|
|
|
public Misc() {
|
2008-04-28 15:53:48 +00:00
|
|
|
expect(! boolean1);
|
|
|
|
expect(! boolean2);
|
2008-04-01 00:34:57 +00:00
|
|
|
|
2008-04-28 15:53:48 +00:00
|
|
|
time = 0xffffffffffffffffL;
|
2008-04-01 00:34:57 +00:00
|
|
|
|
2008-04-28 15:53:48 +00:00
|
|
|
expect(! boolean1);
|
|
|
|
expect(! boolean2);
|
2008-04-01 00:34:57 +00:00
|
|
|
}
|
2008-02-17 20:57:40 +00:00
|
|
|
|
|
|
|
private String foo(String s) {
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String bar(String s) {
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static String baz(String s) {
|
|
|
|
return s;
|
|
|
|
}
|
2007-12-16 00:24:15 +00:00
|
|
|
|
2008-02-17 20:57:40 +00:00
|
|
|
private static void expect(boolean v) {
|
|
|
|
if (! v) throw new RuntimeException();
|
|
|
|
}
|
|
|
|
|
|
|
|
private synchronized byte sync() {
|
|
|
|
byte[] array = new byte[123];
|
|
|
|
return array[42];
|
|
|
|
}
|
2008-02-12 00:20:32 +00:00
|
|
|
|
2008-02-17 20:57:40 +00:00
|
|
|
private static synchronized byte syncStatic(boolean throw_) {
|
|
|
|
byte[] array = new byte[123];
|
|
|
|
if (throw_) {
|
|
|
|
throw new RuntimeException();
|
|
|
|
} else {
|
|
|
|
return array[42];
|
|
|
|
}
|
|
|
|
}
|
2008-02-12 00:20:32 +00:00
|
|
|
|
2008-02-17 20:57:40 +00:00
|
|
|
public static void putInt(int val, byte[] dst, int offset) {
|
|
|
|
System.out.println("put " + val);
|
|
|
|
dst[offset] = (byte)((val >> 24) & 0xff);
|
|
|
|
dst[offset+1] = (byte)((val >> 16) & 0xff);
|
|
|
|
dst[offset+2] = (byte)((val >> 8) & 0xff);
|
|
|
|
dst[offset+3] = (byte)((val ) & 0xff);
|
|
|
|
}
|
2008-02-12 00:20:32 +00:00
|
|
|
|
2008-02-17 20:57:40 +00:00
|
|
|
public static void putLong(long val, byte[] dst, int offset) {
|
|
|
|
putInt((int)(val >> 32), dst, offset);
|
|
|
|
putInt((int)val, dst, offset + 4);
|
|
|
|
}
|
2008-01-11 22:16:24 +00:00
|
|
|
|
2008-02-17 20:57:40 +00:00
|
|
|
public String toString() {
|
|
|
|
return super.toString();
|
|
|
|
}
|
2007-09-26 23:23:03 +00:00
|
|
|
|
2008-04-30 15:44:17 +00:00
|
|
|
private static int zap() {
|
|
|
|
return 42;
|
|
|
|
}
|
2008-04-28 15:53:48 +00:00
|
|
|
|
2008-04-30 15:44:17 +00:00
|
|
|
private static int zip() {
|
|
|
|
return 5 + zap();
|
|
|
|
}
|
2008-04-28 15:53:48 +00:00
|
|
|
|
2008-04-30 15:44:17 +00:00
|
|
|
public static void main(String[] args) {
|
2008-04-30 17:15:21 +00:00
|
|
|
{ int a = -5;
|
|
|
|
int b = 2;
|
|
|
|
expect(a >> b == -5 >> 2);
|
|
|
|
expect(a >>> b == -5 >>> 2);
|
|
|
|
expect(a << b == -5 << 2);
|
|
|
|
expect(a * b == -5 * 2);
|
|
|
|
expect(a / b == -5 / 2);
|
|
|
|
expect(a % b == -5 % 2);
|
|
|
|
|
|
|
|
a = 5;
|
|
|
|
b = 2;
|
|
|
|
expect(a >> b == 5 >> 2);
|
|
|
|
expect(a >>> b == 5 >>> 2);
|
|
|
|
expect(a << b == 5 << 2);
|
|
|
|
expect(a * b == 5 * 2);
|
|
|
|
expect(a / b == 5 / 2);
|
|
|
|
expect(a % b == 5 % 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
byte2 = 0;
|
|
|
|
expect(byte2 == 0);
|
|
|
|
|
|
|
|
expect(Long.valueOf(231L) == 231L);
|
|
|
|
|
|
|
|
long x = 231;
|
|
|
|
expect((x >> 32) == 0);
|
|
|
|
expect((x >>> 32) == 0);
|
|
|
|
expect((x << 32) == 992137445376L);
|
|
|
|
|
|
|
|
int shift = 32;
|
|
|
|
expect((x >> shift) == 0);
|
|
|
|
expect((x >>> shift) == 0);
|
|
|
|
expect((x << shift) == 992137445376L);
|
|
|
|
|
|
|
|
long y = -231;
|
|
|
|
expect((y >> 32) == 0xffffffffffffffffL);
|
|
|
|
expect((y >>> 32) == 0xffffffffL);
|
|
|
|
|
|
|
|
byte[] array = new byte[8];
|
|
|
|
putLong(231, array, 0);
|
|
|
|
expect((array[0] & 0xff) == 0);
|
|
|
|
expect((array[1] & 0xff) == 0);
|
|
|
|
expect((array[2] & 0xff) == 0);
|
|
|
|
expect((array[3] & 0xff) == 0);
|
|
|
|
expect((array[4] & 0xff) == 0);
|
|
|
|
expect((array[5] & 0xff) == 0);
|
|
|
|
expect((array[6] & 0xff) == 0);
|
|
|
|
expect((array[7] & 0xff) == 231);
|
|
|
|
|
|
|
|
java.nio.ByteBuffer buffer = java.nio.ByteBuffer.allocate(8);
|
|
|
|
buffer.putLong(231);
|
|
|
|
buffer.flip();
|
|
|
|
expect(buffer.getLong() == 231);
|
|
|
|
|
|
|
|
boolean v = Boolean.valueOf("true");
|
|
|
|
|
|
|
|
ClassLoader.getSystemClassLoader().toString();
|
|
|
|
|
|
|
|
int a = 2;
|
|
|
|
int b = 2;
|
|
|
|
int c = a + b;
|
|
|
|
|
|
|
|
Misc m = new Misc();
|
|
|
|
m.toString();
|
|
|
|
|
|
|
|
String s = "hello";
|
|
|
|
m.foo(s);
|
|
|
|
m.bar(s);
|
|
|
|
baz(s);
|
|
|
|
|
|
|
|
m.sync();
|
|
|
|
syncStatic(false);
|
|
|
|
try {
|
|
|
|
syncStatic(true);
|
|
|
|
} catch (RuntimeException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
int d = alpha;
|
|
|
|
beta = 42;
|
|
|
|
alpha = 43;
|
|
|
|
int e = beta;
|
|
|
|
int f = alpha;
|
|
|
|
m.gamma = 44;
|
|
|
|
|
|
|
|
expect(beta == 42);
|
|
|
|
expect(alpha == 43);
|
|
|
|
expect(m.gamma == 44);
|
2008-04-30 15:44:17 +00:00
|
|
|
|
|
|
|
zip();
|
2007-09-24 01:39:03 +00:00
|
|
|
}
|
|
|
|
}
|