Merge remote branch 'origin/master' into openjdk

Conflicts:
	makefile
	src/compile.cpp
	src/compiler.cpp
	src/type-generator.cpp
This commit is contained in:
Joel Dice
2010-11-16 10:18:08 -07:00
22 changed files with 1759 additions and 711 deletions

View File

@ -44,28 +44,80 @@ public class Runtime {
}
public Process exec(String command) throws IOException {
long[] process = new long[4];
StringTokenizer t = new StringTokenizer(command);
String[] cmd = new String[t.countTokens()];
for (int i = 0; i < cmd.length; i++)
cmd[i] = t.nextToken();
exec(cmd, process);
return new MyProcess(process[0], (int) process[1], (int) process[2], (int) process[3]);
return exec(cmd);
}
public Process exec(String[] command) {
long[] process = new long[4];
exec(command, process);
return new MyProcess(process[0], (int) process[1], (int) process[2], (int) process[3]);
public Process exec(final String[] command) throws IOException {
final MyProcess[] process = new MyProcess[1];
final Throwable[] exception = new Throwable[1];
synchronized (process) {
Thread t = new Thread() {
public void run() {
synchronized (process) {
try {
long[] info = new long[5];
exec(command, info);
process[0] = new MyProcess
(info[0], info[1], (int) info[2], (int) info[3],
(int) info[4]);
} catch (Throwable e) {
exception[0] = e;
} finally {
process.notifyAll();
}
}
MyProcess p = process[0];
if (p != null) {
synchronized (p) {
try {
if (p.pid != 0) {
p.exitCode = Runtime.waitFor(p.pid, p.tid);
p.pid = 0;
p.tid = 0;
}
} finally {
p.notifyAll();
}
}
}
}
};
t.setDaemon(true);
t.start();
while (process[0] == null && exception[0] == null) {
try {
process.wait();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
if (exception[0] != null) {
if (exception[0] instanceof IOException) {
throw new IOException(exception[0]);
} else {
throw new RuntimeException(exception[0]);
}
}
return process[0];
}
public native void addShutdownHook(Thread t);
private static native void exec(String[] command, long[] process);
private static native void exec(String[] command, long[] process)
throws IOException;
private static native int exitValue(long pid);
private static native int waitFor(long pid);
private static native int waitFor(long pid, long tid);
private static native void load(String name, boolean mapName);
@ -79,13 +131,15 @@ public class Runtime {
private static class MyProcess extends Process {
private long pid;
private long tid;
private final int in;
private final int out;
private final int err;
private int exitCode;
public MyProcess(long pid, int in, int out, int err) {
public MyProcess(long pid, long tid, int in, int out, int err) {
this.pid = pid;
this.tid = tid;
this.in = in;
this.out = out;
this.err = err;
@ -95,13 +149,6 @@ public class Runtime {
throw new RuntimeException("not implemented");
}
public int exitValue() {
if (pid != 0) {
exitCode = Runtime.exitValue(pid);
}
return exitCode;
}
public InputStream getInputStream() {
return new FileInputStream(new FileDescriptor(in));
}
@ -114,11 +161,19 @@ public class Runtime {
return new FileInputStream(new FileDescriptor(err));
}
public int waitFor() throws InterruptedException {
public synchronized int exitValue() {
if (pid != 0) {
exitCode = Runtime.waitFor(pid);
pid = 0;
throw new IllegalThreadStateException();
}
return exitCode;
}
public synchronized int waitFor() throws InterruptedException {
while (pid != 0) {
wait();
}
return exitCode;
}
}