[Isolate-interest] Question about multiple isolates
Laurent Daynes
Laurent.Daynes at Sun.COM
Wed Dec 21 16:30:30 EST 2005
Skipped content of type multipart/alternative-------------- next part --------------
package tests.gc;
import java.util.HashMap;
import javax.isolate.Isolate;
import javax.isolate.IsolateStatus;
import javax.isolate.IsolateStartupException;
import javax.isolate.Link;
import javax.isolate.LinkMessage;
import javax.isolate.LinkMessageDispatcher;
import javax.isolate.LinkMessageHandler;
import javax.isolate.ClosedLinkException;
import java.io.IOException;
public class ThroughputLoader implements LinkMessageHandler {
final LinkMessageDispatcher dispatcher;
final int throughput;
final int totalRequested;
final LoadFactory factory;
final HashMap<Link, Isolate> currentLoad;
int totalLaunched;
int totalStarted;
int totalExecuted;
public ThroughputLoader(LoadFactory factory, int totalRequested, int throughput) {
this.factory = factory;
this.totalRequested = totalRequested;
this.throughput = throughput;
currentLoad = new HashMap<Link, Isolate>(throughput);
totalLaunched = totalStarted = totalExecuted = 0;
dispatcher = new LinkMessageDispatcher();
}
private void startProgram(Isolate isolate) {
if (isolate != null) {
Link l = null;
try {
l = isolate.newStatusLink(Isolate.currentIsolate());
currentLoad.put(l, isolate);
dispatcher.add(l, this);
isolate.start();
totalLaunched++;
} catch (IsolateStartupException estart) {
currentLoad.remove(l);
dispatcher.remove(l);
} catch (ClosedLinkException eclosed) {
}
}
}
public void runLoad() {
System.out.println("Starting Dispatcher");
new Thread(dispatcher).start();
System.out.println("Starting concurrent load");
synchronized (this) {
while (totalLaunched < totalRequested) {
try {
if (currentLoad.size() >= throughput) {
wait();
}
startProgram(factory.nextProgram());
} catch (InterruptedException eint1) {
}
}
while (totalExecuted < totalRequested) {
try {
wait();
} catch (InterruptedException eint1) {
}
}
}
System.out.println("\n\n\nShutting down Dispatcher");
dispatcher.shutDown();
System.out.println("End of run");
}
public void messageReceived(Link link, LinkMessage message) {
synchronized (this) {
assert currentLoad.containsKey(link) && message.containsStatus();
IsolateStatus.State state = message.extractStatus().getState();
if (state == IsolateStatus.State.STARTED) {
totalStarted++;
} else if (state == IsolateStatus.State.EXITED) {
dispatcher.remove(link);
currentLoad.remove(link);
link.close();
totalExecuted++;
notify();
}
}
}
public void receiveFailed(Link link, Throwable throwable) {
System.err.println("Receipt of message failed for link " +
link + " : " + throwable);
}
}
-------------- next part --------------
package tests.gc;
import java.util.Properties;
import javax.isolate.Isolate;
import javax.isolate.IsolateStartupException;
/**
*
*/
public class Spec98LoadFactory implements LoadFactory {
static final String CLASSPATH;
static final String PREFIX;
static {
String s = System.getProperty("specjvm98.path", "/space/barcelone1/benchmarks/jvm98-1.03");
CLASSPATH = s.replace('/', java.io.File.separatorChar);
PREFIX = CLASSPATH + new String("/spec/benchmarks/").replace('/', java.io.File.separatorChar);
}
String [] programNames;
int current;
public Spec98LoadFactory(String programName) {
this(new String[] { programName });
}
public Spec98LoadFactory(String [] programNames) {
this.programNames = programNames;
current = 0;
}
private synchronized int next() {
int n = current;
current = (current+1) % programNames.length;
return n;
}
public Isolate nextProgram() {
try {
String name = programNames[next()];
String classname = "spec.benchmarks." + name + ".Main";
Properties p = new Properties();
p.setProperty("java.class.path", CLASSPATH);
p.setProperty("user.dir", PREFIX + name);
System.out.println("Program: " + classname + " classpath: " + p.getProperty("java.class.path"));
return new Isolate(p, classname);
} catch (IsolateStartupException e) {
return null;
}
}
}
-------------- next part --------------
package tests.gc;
public class ConcurrentSpecRun {
public static void main(String [] args) {
// Parse argument
if (args.length != 3 || ! args[0].startsWith("_2")) {
usage();
}
String benchName = args[0];
int totalRequested = Integer.parseInt(args[1]);
int throughput = Integer.parseInt(args[2]);
new ThroughputLoader(new Spec98LoadFactory(benchName), totalRequested, throughput).runLoad();
}
public static void usage() {
System.err.println("ConcurrentSpecRun <specprogramname> <total> <concurrency>");
System.exit(1);
}
}
-------------- next part --------------
package tests.gc;
import javax.isolate.Isolate;
public interface LoadFactory {
public Isolate nextProgram();
}
More information about the Isolate-interest
mailing list