The Artima Developer Community
Sponsored Link

Java Answers Forum
PipeStreaming with ObjectStreaming App. - Freezes

1 reply on 1 page. Most recent reply: May 12, 2003 2:41 AM by Adam Duffy

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Natalie

Posts: 2
Nickname: natalya
Registered: May, 2003

PipeStreaming with ObjectStreaming App. - Freezes Posted: May 5, 2003 12:07 PM
Reply to this message Reply
Advertisement
Hi - Please help! I have a multi-threaded application that involves three threads: Filter, EventRecognizer, and Checker. Initially the application communicated successfully using PipeStreaming with DataStreaming. Now I want to communicate non-primitive objects, so I am changing the communication to be PipeStreaming with ObjectStreaming. Unfortunately the execution freezes somewhere between communication of Filter to EventRecognizer, I think?K ?? any ideas and/or suggestions? Why is this happening? How do I fix it?
I have attached some bits of the application code below. Any ideas/suggestions to get this working would be most appreciated.
Unfortunately, the code is quite detailed so I did my best to extract the causing parts. Feel free to contact me at natalieabowles@hotmail.com as well.
Thank you!

[b]public class[/b] MaCMain {

[b]public static void[/b] main(String args[]) {

[b]int[/b] currentArg = 0;

[b]try[/b] {

[i]/* Pipe */[/i]
PipedInputStream erChkInput =
mac.types.interfaceERChecker.Pipe.erChkInput;
PipedOutputStream erChkOutput =
mac.types.interfaceERChecker.Pipe.erChkOutput;
erChkInput.connect(erChkOutput);
PipedOutputStream chkSteerOutput = null;

[i]/* Target System */[/i]
Class targetSystem = Class.forName(args[currentArg++]);
Method mainMeth = targetSystem.getMethod("main",
new Class[] {Class.forName("[Ljava.lang.String;")});
[b]int[/b] systemArgsLength = 0;

[i]/* Event Recognizer part */[/i]
System.out.println(mac.Version.info(
"MaC Event Recognizer: Monitor of Instrumented\n" +
" Java Program"));

new EventRecognizerMain(erChkOutput,
args[currentArg++],
args[currentArg++]).run();

[/i]/* checker part */[/i]
System.out.println(mac.Version.info(
"MaC Runtime Checker: Checker of Monitored Behavior\n" +
" for Run-time Formal Analysis"));

if( currentArg+2 == args.length && args[currentArg+1].equals("-s"))
chkSteerOutput =
mac.types.steeringTypes.Pipe.chkSteerOutput;

if( currentArg+1 != args.length && currentArg+2 != args.length)
throw new Exception();

(new CheckerMain(0, null, 0, args[currentArg], null,
erChkInput, chkSteerOutput)).run();

[i]/* start target system */[/i]
(new TargetSystem(mainMeth, param)).start();
}
catch(Exception e) {
System.err.println("** Error: incorrect arguments ... ");
System.err.println("** Usage is ... ");
System.err.println(" java mac.MaCMain targetsystem_class"+
" targetsystem_arguments");
System.err.println(" pedl.out instrumentation.out"+
" medl.out [-s]");
System.exit(1);
}
}
}
[b]public final class [/b]Filter
{
??[b]??static boolean[/b] initDone = false;
[i]/** A list of monitored objects, methods and fields */

/** Network-related variables */[/i]
[b]static[/b] Socket s = null;
[b]static[/b] OutputStream sout=null;
[b]////public static DataOutputStream oStream;
public static ObjectOutputStream oStream;[/b]

[b]public final static Object[/b] lock = new Object();

[i]/* For monitoring object */[/i]
[b]public static[/b] PedlInstrObject instrumentationOut = null;

[i] /** This method performs 3 jobs
* 1. It initialize communication channel to an event recognizer.
* 2. It sets the size of buffers and other configurations based on
* run-time parameters
* 3. It generates a filter thread. A filter thread performs book-keeping of
* address/name table and actuall communication for making low overhead
* to original program
*/[/i]
[b]static public void ??[/b]??init(String host, int port, int period, boolean deltaValue){ [i]// Communication channel
// If initialization is already performed, do not do it again[/i]
??[b]??if??[/b]??( initDone ) { return;}

initDone = true;

[b]try {
if [/b](port == 0 && host == null)
sout = Pipe.filterEROutput;
[b] else {[/b]
s = new Socket(host,port);
sout = s.getOutputStream();
}

[i]// For efficiency, use BufferedOutput[/i]
[b]////oStream = new DataOutputStream(sout);
oStream = new ObjectOutputStream(sout);[/b]


}

[b]public static void[/b]init(String filename, int period, boolean deltaValue) {
[b]if[/b]( initDone ) { return;}
initDone = true;


/* Usa: Check for timestamps */
System.out.println("Filter:period -> "+period);
??[b]??try{[/b]
////oStream = new DataOutputStream(
oStream = new ObjectOutputStream(
new FileOutputStream(filename,false));
??[b]??if[/b](period != 0 ) new TimeStamp(period);
SendMethods.delta = deltaValue;
}catch(IOException e) {
System.out.println("I Caught this IOException in Filter.java: " + e);
System.err.println("In init(String), " + e);
}
}
public static void init(int period, boolean deltaValue) { // general output stream
if( initDone ) { return;}
initDone = true;

/* Usa: Check for timestamps */
System.out.println("Filter:period -> "+period);

if( period != 0 ) new TimeStamp(period);
SendMethods.delta = deltaValue;
}

[i]/** This method is used for giving inputstream and output stream to the
* target application. targetClass should be fully qualified class name. parameter is is ignored */[/i]
??[b]??public static void[/b] hook(String targetClass, String[] args,
InputStream is, OutputStream os) {
??[b]??try{
////oStream = new DataOutputStream(os);
oStream = new ObjectOutputStream(os);[/b]
Class targetApp = Class.forName(targetClass);

Method main = targetApp.getMethod("main",
new Class[] {Class.forName("[Ljava.lang.String;")});
main.invoke(null, new Object[] { args});
oStream.close();
}catch (IOException ioe) {
System.out.println("I Caught this IOException in Filter.java: " + ioe);
} catch(Exception e) {System.err.println(e);System.exit(-1);
}


}
}
??[b]??public class[/b] EventRecognizer ??[b]??extends[/b] Thread {

??[b]??protected final int[/b] MAX_HEIGHT; // maximum height in tree
??[b]??public final static int[/b] startID = PedlInstrObject.startID;
OutputStream outStream;
InputStream inputStream;

??[b]??//protected DataInputStream primitiveIn;
protected ObjectInputStream primitiveIn;
////DataOutputStream events_conds_out;
protected ObjectOutputStream events_conds_out;[/b]

[i]// For reducing the run-time cost of creating an object of ErChkObject,
// I create the object once then change the contents of the
// object every time. [/i]
??[b]??protected[/b] ErChkObject obj ;
??[b]??protected[/b] InterfaceERChecker exportTBL;

??[b]??Vector[/b] monExecPoints;
??[b]??int[/b] numExecPoints;

??[b]??Vector[/b] monLocalVars;
??[b]??int[/b] numLocalVars;

??[b]??Vector[/b] monGlobalVars;
??[b]??int[/b] numGlobalVars;

??[b]??int[/b] num = 0; [i]// number of event received so far[/i]

??[b]??public[/b] EventRecognizer(InputStream inStream, OutputStream outStream,
ParserErObject pedl_out, PedlInstrObject objMonEntities){
this.parseTree = pedl_out.getParseTree();
this.symbolTbl = pedl_out.getSymbolTable();
this.exportEvents = pedl_out.getExportedEvents();
this.exportConditions = pedl_out.getExportedConditions();
this.conditions = pedl_out.getConditions();
this.events= pedl_out.getEvents();
this.lastOccurrenceTimes = new long[events.length];
period = objMonEntities.tickPeriod;
// Make varTypes : varId -> varType
varTypes = new int[objMonEntities.getNumMonEntities()
+startID];
varDeltaTypes = new int[objMonEntities.getNumMonEntities()
+startID];
}

monExecPoints = objMonEntities.getExecPoints();
numExecPoints = monExecPoints.size();

monLocalVars = objMonEntities.getLocalVars();
numLocalVars = monLocalVars.size();

monGlobalVars= objMonEntities.getGlobalVars();
numGlobalVars = monGlobalVars.size();

this.outStream = outStream;

[b]try {
////events_conds_out = new DataOutputStream(outStream);
events_conds_out = new ObjectOutputStream(outStream);

////primitiveIn = new DataInputStream(inStream);
primitiveIn = new ObjectInputStream(inStream);
} catch [/b](IOException ioe) {
System.out.println("I Caught this IOException in EventRecognizer.java: " + ioe);
}
hasTimeStamp = objMonEntities.isTimeStampRequired();
exportTBL = new InterfaceERChecker(
exportEvents,exportConditions,hasTimeStamp);

MAX_HEIGHT = parseTree.getHeight();
}

[b]public void[/b] run() {
[b]int dataType;
int varId=0;[/b]

[b]String[/b] type = null;
[b]byte[][/b] ba = new byte[200];
[b]Object[/b] value = null;

initializeSymbolTbl();

ObjectOutputStream oOut = new ObjectOutputStream(outStream);
oOut.writeObject(exportTBL);
oOut.flush();

[b]for(;;)[/b] {

[b]varId = primitiveIn.readByte();[/b]

// Special id sections such as time stamps
[b]switch[/b](varId ) {
case 0: System.err.println(
"Something wrong happens; ID 0 is received!");
break;
case 1: currentTargetTime += period; continue;
default:
}

resetSymbolTBL(); // reset updated flag.
[b]dataType = varId >= 0 ?
varTypes[varId] : varDeltaTypes[- varId ]; [/b]

[b]switch[/b](dataType) {
case DataTypes.SHORT:
value = getObjectValue(primitiveIn.readShort());
updateSymbolTBL(varId,value);
break;
case DataTypes.INT:
value = getObjectValue(primitiveIn.readInt());
updateSymbolTBL(varId,value);
break;
case DataTypes.LONG:
value = getObjectValue(primitiveIn.readLong());
updateSymbolTBL(varId,value);
break;
case DataTypes.FLOAT:
value = getObjectValue(primitiveIn.readFloat());
updateSymbolTBL(varId,value);
break;
case DataTypes.DOUBLE:
value = getObjectValue(primitiveIn.readDouble());
updateSymbolTBL(varId,value);
break;
case DataTypes.BYTE:
value = getObjectValue(primitiveIn.readByte());
updateSymbolTBL(varId,value);
break;
case DataTypes.CHAR:
value = getObjectValue(primitiveIn.readChar());
updateSymbolTBL(varId,value);
break;
case DataTypes.BOOLEAN:
// From Nov 27, method start/end is informed through
// boolean, not string
temp = primitiveIn.readBoolean();
[b]if[/b]( varId < // Execution point
numExecPoints+startID) {
value = temp ?
"end of " + monExecPoints.elementAt(
varId - startID) :
"start of "+monExecPoints.elementAt(varId - startID);
//System.out.println(varId+":"+value);
[b]} else[/b] value = getObjectValue(temp);

updateSymbolTBL(varId,value);
break;
case DataTypes.STRING: // Execution Point
value = primitiveIn.readUTF();
updateSymbolTBL(varId,value);
break;
default:
}

evaluateBackward(varId, value);

sendSignals();

}

}[b]
catch[/b](EOFException e){
System.out.println("ER: Trace is completely read.");
[b]try[/b]{outStream.flush();}
[b]catch[/b](IOException ioe) {System.err.println(ioe);}
System.exit(0);
} [b]catch[/b](IOException e){
if (e.getMessage().equals("Pipe broken") ||
e.getMessage().equals("Write end dead")) {
System.out.println("ER: Trace is completely read.");
[b]try{[/b]
outStream.flush();
}
[b]catch[/b](IOException ioe) {System.err.println(ioe);}
}
[b]else[/b]
e.printStackTrace();
}
}
[i]/**
* Given snapshot object from the filter, it checks what events
* happen or what conditions are satisfied. Then it sends detected
* events and conditions to the run-time checker[/i]
*/
[b]Object[/b] getObjectValue(short s) {
return (new Short(s));
}
[b]Object[/b] getObjectValue(int i) {
return (new Integer(i));
}
[b]Object[/b] getObjectValue(long l) {
return (new Long(l));
}
[b]Object[/b] getObjectValue(float f) {
return (new Float(f));
}
[b]Object[/b] getObjectValue(double d) {
return (new Double(d));
}
[b]Object[/b] getObjectValue(char c) {
return (new Character(c));
}
[b]Object[/b] getObjectValue(boolean b) {
return (new Boolean(b));
}
[b]Object[/b] getObjectValue(int varId, byte b) {
return (new Byte(b));
}
[b]Object[/b] getObjectValue(int varId, String s) {
return s;
}

[b]void[/b] updateSymbolTBL(int varId, Object value) {
if( - startID < varId && varId < startID ) {
System.err.println("varId:" + varId +
" must not be in the reserved index range "
+"(-"+startID+", "+startID+") at updateSymbolTBL()!");
}
String varName = null;
[b]int _varId = varId >= 0 ? varId - startID :
- varId - startID;[/b]



void sendSignals() {

[b]if[/b](hasTimeStamp) events_conds_out.writeLong(currentTargetTime);
events_conds_out.writeByte(numOccurredEvents);
events_conds_out.writeByte(numTrueConds);
events_conds_out.writeByte(numFalseConds);
events_conds_out.writeByte(numUndefConds);
} [b]catch[/b](IOException e3) { System.err.println(e3);}

for(int i=0; i < numOccurredEvents; i++) {
values = occurredEventValues[i];

// Currently, only update(x) contains a value vector which
// contains only 1 value. endM and startM should have a
// value vector, but not yet implemented
// Other types of events have null as a value vector
if( values.isEmpty() ) {
typeEventValue = DataTypes.NONE;
} else {
value = values.elementAt(0);

if( value instanceof Integer)
typeEventValue = DataTypes.INT;
else if( value instanceof Short)
typeEventValue = DataTypes.SHORT;
else if( value instanceof Long)
typeEventValue = DataTypes.LONG;
else if( value instanceof Float)
typeEventValue = DataTypes.FLOAT;
else if( value instanceof Double)
typeEventValue = DataTypes.DOUBLE;
else if( value instanceof Byte)
typeEventValue = DataTypes.BYTE;
else if( value instanceof Character)
typeEventValue = DataTypes.CHAR;
else if( value instanceof Boolean)
typeEventValue = DataTypes.BOOLEAN;
else if( value instanceof String)
typeEventValue = DataTypes.STRING;
else if( value instanceof ThreeValued)
typeEventValue = DataTypes.UNDEF;
else System.err.println(value +
" is not primitive numeric type nor String");
}
[b]try{[/b]

//events_conds_out.writeUTF(occurredEventNames[i]);
events_conds_out.writeByte(
exportTBL.getID(occurredEventNames[i]));
// System.out.println(exportTBL.getID(occurredEventNames[i]));

events_conds_out.writeByte(typeEventValue);
[b]switch[/b](typeEventValue) {
case DataTypes.NONE: // No value
break;
case DataTypes.SHORT:
events_conds_out.writeShort(((Short)value).shortValue());
break;
case DataTypes.INT:
events_conds_out.writeInt(((Integer)value).intValue());
break;
case DataTypes.LONG:
events_conds_out.writeLong(((Long)value).longValue());
break;
case DataTypes.FLOAT:
events_conds_out.writeFloat(((Float)value).floatValue());
break;
case DataTypes.DOUBLE:
events_conds_out.writeDouble(
((Double)value).doubleValue());
break;
case DataTypes.BYTE:
events_conds_out.writeByte(((Byte)value).byteValue());
break;
case DataTypes.CHAR:
events_conds_out.writeChar(
((Character)value).charValue());
break;
case DataTypes.BOOLEAN:
events_conds_out.writeBoolean(
((Boolean)value).booleanValue());
break;
case DataTypes.UNDEF: // false is dumb value
events_conds_out.writeBoolean(false);
break;
case DataTypes.STRING:
events_conds_out.writeObject((String)value);
break;
default: System.err.println(
"Incorrect type of value of event "
+ ev.getName() + " " + typeEventValue);
}
//System.err.println(occurredEventNames[i]+":"+values+"-"+num++ +"-:" + currentTargetTime);
// Deactivating events for next time instance
se = (SymtabEntry)symbolTbl.get( occurredEventNames[i]);
((SimpleNode)se.getValue()).setValue(new EventType(false));
} catch(IOException e1) { System.err.println(e1); }
}


}


Adam Duffy

Posts: 168
Nickname: adamduffy
Registered: Feb, 2003

Re: PipeStreaming with ObjectStreaming App. - Freezes Posted: May 12, 2003 2:41 AM
Reply to this message Reply
This is a duplicate post.

Adam

Flat View: This topic has 1 reply on 1 page
Topic: Help : Assinment for class tomorrow Previous Topic   Next Topic Topic: Converting my String Palindrome problem into a Integer

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use