Commit 8afe9f4c authored by Melanie Jakob's avatar Melanie Jakob

Mutex hinzugefügt, allgemeine Verbesserungen

parent d789114d
#Thu Jul 02 11:43:18 GMT 2009
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.4
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning
org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
org.eclipse.jdt.core.compiler.source=1.3
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.5
/home/petter/temp/
test.wim
C:\Daten\UniMel\vam\
mutextest.tma
import vam.base.*;
import vam.util.*;
/*
* :-)
*/
public class Starter
{
static private void printUsage() {
......
......@@ -81,6 +81,7 @@ public class Cell extends JLabel implements MouseListener
defineType( "RQ", Color.blue, Color.white, 30, stdHeight, NOPOINTER);
defineType("RQ2", Color.blue, Color.white, 20, stdHeight, NOPOINTER);
defineType("JTable", Color.blue, Color.white, 50, stdHeight, NOPOINTER);
defineType("Mutex",Color.cyan,Color.black,50,stdHeight,NOPOINTER);
}
......
......@@ -19,7 +19,7 @@ public class Memory
HashMap memory;
// Laufzeitumgebeung
ViewMachine vm;
static ViewMachine vm;
public int ct; // von mir fr neue Berechnung von Location
......@@ -694,8 +694,8 @@ public class Memory
{
vm.finalizeStackVisualization(true, address, 1);
}
else{
*/// Stack
else{*/
// Stack
if ( 0<=address && address<=700 )
{
int cellsPerColumn = (vm.view.getHeight()-30)/Cell.stdHeight;
......@@ -706,6 +706,10 @@ public class Memory
p.setLocation( trans.x*(ct+1),trans.y );
}
else {p.setLocation( startwidth+differenz*(ct),trans.y );}
/*if(thread.getStack().getSize() >= bound )
{
vm.finalizeStackVisualization(true, address, 1);
}*/
}
else p.setLocation(startwidth+differenz*(ct),vm.view.getHeight()-30);
p.translate( ((address-ct*differenz)/cellsPerColumn)*(Cell.stdWidth+30),-((address-ct*differenz) % cellsPerColumn)*Cell.stdHeight );
......@@ -729,7 +733,7 @@ public class Memory
p.translate( -(count2)*(Cell.stdWidth+30), (1200-count1)*Cell.stdHeight );
}
// }
return p;
}
/**
......
......@@ -400,11 +400,11 @@ public class Memory2 extends Memory
public void setCell( int address, Cell cell, boolean visible, String type )
{
/*String ext = ViewMachine.ext;
String ext = ViewMachine.ext;
if (ext.equals("tma")){
super.setCell(address, cell, visible, type);
}
else{*/
else{
if ( getCell(address) != cell )
{
free( address );
......@@ -435,7 +435,7 @@ public class Memory2 extends Memory
vm.sync();
cell.highlight( false );
}
}
}
// AD : setzt newHeapObjectLocation auf initialen Wert zurueck
......
......@@ -34,7 +34,9 @@ public class Pointer extends JPanel
public Pointer( Cell source )
{
super();
setBounds( 0,0,1000,1000 );
//changed by Melanie Jakob: bei größerem Fenster waren die Pointer abgeschnitten
//setBounds( 0,0,1000,1000 );
setBounds(0,0,Memory.vm.view.getWidth(),Memory.vm.view.getHeight());
setOpaque( false );
// Zufällige Farbwahl zur besseren Unterscheidung
......
......@@ -28,7 +28,11 @@ public class ViewMachine implements ActionListener
// GUI stuff
public JFrame frame;
JLayeredPane view;
JButton runButton, stepButton, backButton, yieldButton, compactButton;
JButton runButton, stepButton, backButton;
public static JButton yieldButton;
JButton compactButton;
// Options
int optionMoveStep = 8;
......@@ -114,7 +118,7 @@ public class ViewMachine implements ActionListener
comment = null;
compactHeap = false;
stackBound = 0;
stackBound = 20;
hiddenStackCells = 0;
// Animationstimer
......@@ -415,6 +419,8 @@ public class ViewMachine implements ActionListener
yieldButton = new JButton("Yield");
yieldButton.setPreferredSize( new Dimension(85,30) );
if (ext!="tma"){yieldButton.setEnabled(false);}
yieldButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
......@@ -1345,19 +1351,11 @@ public class ViewMachine implements ActionListener
IR = (Command)codeMem.get(PC.get());
ViewMachine.output( PC.get()+": "+IR.toString() );
if (yield){
if(PC.get()>0){
PC.set(PC.get()-1);}
}
else{
PC.set(PC.get()+1);}
if (!yield){PC.set(PC.get()+1);}
IR.execute();
if (yield){
codeMem.remove(PC.get());
if(!ReadyQueue.array[0].isBelegt()){
PC.set(PC.get()+1);
}
yield=false;
}
sync();
......@@ -1535,7 +1533,7 @@ public class ViewMachine implements ActionListener
vam.machines.tma.Thread thread = Threadtable.list.get(MainCommand.CT.get());
int ct = MainCommand.CT.get();
int stackSize = stack.getSize();
int stackSize = thread.stack.getSize();
Vector actions = new Vector();
if(down) {
// stack bis auf oberste Zelle nach unten bewegen
......
package vam.machines.tma;
public class BROADCAST extends MainCommand{
public BROADCAST()
{
super("BROADCAST");
}
public void execute()
{
int cvpointer = memory.getIntValue(SP());
while(memory.getValue(cvpointer)!=""){
ReadyQueue.enqueue(memory.getIntValue(cvpointer));
for (int i = 0;i<MainCommand.getStacknumber();i++){
if(memory.getValue(cvpointer+i+1) == ""){
memory.setValue(cvpointer+i, "");
}
else{memory.setIntValue(cvpointer+i,memory.getIntValue(cvpointer+1+i));}
}
}
}
}
......@@ -42,8 +42,10 @@ public class INITSTACK extends MainCommand{
memory.setValue( newstackSP,""); //evtl warten um besser darzustellen?
memory.setIntValue(newstackSP,memory.getIntValue(oldSP-1));
memory.setIntValue(newstackSP+1,-1);
memory.setIntValue(newstackSP+2,memory.getIntValue(oldSP-2));
if(MainCommand.viewMachine.labels.containsKey("f")){
int label = ((Integer)MainCommand.viewMachine.labels.get("f")).intValue();
memory.setIntValue(newstackSP+2,label);}
else {memory.setIntValue(newstackSP+2,0);}
memory.setIntValue( oldSP-1, newstackSP+2 );
memory.pointer( oldSP );
......
package vam.machines.tma;
public class LOCK extends MainCommand {
public LOCK()
{
super("LOCK");
}
public void execute()
{
int owner = memory.getIntValue(memory.getIntValue(SP()));
int pointer = memory.getIntValue(SP());
if(owner<0){
memory.setIntValue(memory.getIntValue(SP()), MainCommand.CT.get());
Thread thread = Threadtable.list.get(MainCommand.CT.get());
thread.getStack().pop();
}
else{for (int i = 0; i<MainCommand.getStacknumber()-1;i++){
if (memory.getValue(pointer+i+1)==""){
memory.setIntValue(pointer+i+1, MainCommand.CT.get());
break;
}
}
Thread thread = Threadtable.list.get(MainCommand.CT.get());
thread.getStack().pop();
//next
Thread threadold = Threadtable.list.get(MainCommand.CT.get());
int threadnewTid = ReadyQueue.array[0].getIntValue();
ReadyQueue.next();
Thread threadnew = Threadtable.list.get(threadnewTid);
threadold.save();
CT.set(threadnew.tid);
threadnew.restore();
}
}
}
......@@ -13,9 +13,9 @@ public class MARK extends MainCommand
{
Thread thread = Threadtable.list.get(MainCommand.CT.get());
// stack.push(); // organisatorische Zellen
// thread.stack.push( EP() ); // reservieren und initialisieren
thread.getStack().push(0); // EP nicht mehr bentigt
thread.getStack().highlight( 1,Color.magenta ); // organisatorische Zellen einf�rben
//thread.stack.push( EP() ); // reservieren und initialisieren
//thread.getStack().push(0); // EP nicht mehr bentigt
//thread.getStack().highlight( 1,Color.magenta ); // organisatorische Zellen einf�rben
thread.getStack().push( FP() );
thread.getStack().highlight( 1,Color.magenta ); // organisatorische Zellen einf�rben
// stack.push();
......
......@@ -6,7 +6,7 @@ import vam.util.Stack2;
public class MainCommand extends Command
{
static ViewMachine viewMachine; // erm�glicht Zugriff auf die Visualisierung
public static ViewMachine viewMachine; // erm�glicht Zugriff auf die Visualisierung
static Memory memory; // Speicherverwaltung
static Stack2 stack; // Kellerspeicher
static Register FP; // Frame Pointer
......@@ -99,6 +99,7 @@ public class MainCommand extends Command
stack = t1.getStack();
vm.stack = stack;
ViewMachine.yieldButton.setEnabled(true);
// Gruppe zur Gruppierung der Halde
heapGroup = new CellGroup("Heap");
......
package vam.machines.tma;
import java.awt.Point;
import vam.base.Cell;
public class NEWCONDVAR extends MainCommand
{
public NEWCONDVAR()
{
super("NEWCONDVAR");
}
public void execute()
{
Point p = new Point(0,0);
Thread thread = Threadtable.list.get(MainCommand.CT.get());
thread.getStack().push("");
memory.highlight( SP(),true );
int number = MainCommand.getStacknumber();
NP( NP()- number+1 );
p = memory.getLocation(NP());
p.translate(-50, 0);
Cell c = new Cell("CV: ","Mutex",p,true);
for (int i = 0; i<MainCommand.getStacknumber()-1;i++){
memory.setValue( NP()+i,"","RQ2" );
/*p = memory.getLocation(NP()+i);
p.translate(-ReadyQueue.array[0].getWidth(), 0);
Cell c = new Cell("WQ: ","RQ",p,true);*/
heapGroup.add( memory.getCell( NP()+i ) );
//heapGroup.add( c );
}
memory.setIntValue( SP(), NP() );
memory.pointer( SP() );
memory.highlight( SP(),false );
}
}
package vam.machines.tma;
import java.awt.Point;
import vam.base.Cell;
public class NEWMUTEX extends MainCommand
......@@ -11,27 +14,69 @@ public class NEWMUTEX extends MainCommand
public void execute()
{
memory.highlight( SP(),true );
/*if( (NP() - memory.getIntValue(SP())) <= EP() )
memory.setIntValue( SP(),-1 );
else
{*/
NP( NP()- memory.getIntValue( SP() ) );
int number = MainCommand.getStacknumber();
memory.setValue( NP(),"TID: ","Register" );
for( int i=1;i< number; i++ )
{
memory.setValue( NP()+i,"WQ: ","RQ2" );
heapGroup.add( memory.getCell( NP()+i ) );
}
Point p = new Point(0,0);
Thread thread = Threadtable.list.get(MainCommand.CT.get());
thread.getStack().push("");
memory.highlight( SP(),true );
int number = MainCommand.getStacknumber();
NP( NP()- number );
memory.setValue( NP(),"","Mutex" );
memory.setIntValue(NP(), -1);
heapGroup.add(memory.getCell(NP()));
p = memory.getLocation(NP()+1);
p.translate(-50, 0);
Cell c = new Cell("WQ: ","Mutex",p,true);
p = memory.getLocation(NP());
p.translate(-50, 0);
Cell d = new Cell("Owner: ","Mutex",p,true);
for (int i = 1; i<MainCommand.getStacknumber();i++){
memory.setValue( NP()+i,"","Mutex" );
heapGroup.add( memory.getCell( NP()+i ) );
}
memory.setIntValue( SP(), NP() );
memory.pointer( SP() );
memory.highlight( SP(),false );
}
}
/*Thread thread = Threadtable.list.get(MainCommand.CT.get());
thread.getStack().push("");
memory.highlight( SP(),true );
int number = MainCommand.getStacknumber();
NP( NP()- number );
memory.setValue( NP(),"","RQ" );
memory.setIntValue(NP(), -1);
heapGroup.add( NP());
int sp = NP.get();
//Visualisierung der Queue des Mutex, die Zellen im Memory werden unsichtbar fr den Zugriff angelegt
Point loc = new Point(0,0);
loc = memory.getLocation(NP()+1);
Mutex.newMutex(loc, sp);
for( int i=1;i< number; i++ )
{
memory.setValue( NP()+i,"WQ: ","RQ2" );
heapGroup.add( memory.getCell( NP()+i ) );
memory.getCell(NP()+i).setVisible(false);
}
memory.setIntValue( SP(), NP() );
memory.pointer( SP() );
memory.highlight( SP(),false );
//NP.isPointer(true);
}
}
}*/
......@@ -14,7 +14,7 @@ public class RETURN extends MainCommand
//if( EP() >= NP() ) cmaError("Stack Overflow");
int newFP = memory.getIntValue( FP()-1 ); // erst Wert lesen, da setSize die Adresse FP()-1 freigibt
SP( FP()-3 );
SP( FP()-2 );
FP( newFP );
}
}
......@@ -12,8 +12,7 @@ public class ReadyQueue extends Cell{
String name;
public int value;
public static ReadyQueue[] array = new ReadyQueue[MainCommand.getStacknumber()];
private static boolean yieldTrigger;
boolean belegt;
public boolean belegt;
/**
Generiert neue RQ-Zelle.
......@@ -54,10 +53,6 @@ public class ReadyQueue extends Cell{
static public void yield()
{
//graphische Darstellung und Neuberechnung des RQ-Arrays
/* if(yieldTrigger)
{System.out.println(java.lang.Thread.currentThread().toString());
System.out.println("nasenbr");
}*/
Cell c = array[0].copy();
c.setVisible(true);
Cell d = array[0].copy();
......@@ -73,7 +68,7 @@ public class ReadyQueue extends Cell{
e.sync();
c.remove();
e.remove();
for(int i = 0; i<4;i++){
for(int i = 0; i<MainCommand.getStacknumber()-1;i++){
if (array[i+1].belegt == true){
array[i].setValue(array[i+1].get());
}
......@@ -203,14 +198,9 @@ public class ReadyQueue extends Cell{
this.belegt = belegt;
}
public static void setYieldTrigger() {
System.out.println(java.lang.Thread.currentThread().toString());
yieldTrigger=true;
}
}
}
......
package vam.machines.tma;
public class SIGNAL extends MainCommand{
public SIGNAL()
{
super("SIGNAL");
}
public void execute()
{
int cvpointer = memory.getIntValue(SP());
if(memory.getValue(cvpointer)!=""){
ReadyQueue.enqueue(memory.getIntValue(cvpointer));
for (int i = 0;i<MainCommand.getStacknumber()-2;i++){
if(memory.getValue(cvpointer+i+1) == ""){
memory.setValue(cvpointer+i, "");
}
else{memory.setIntValue(cvpointer+i,memory.getIntValue(cvpointer+1+i));}
}
}
}
}
......@@ -10,7 +10,7 @@ public class Thread {
int FP;
int PC;
int SP;
private Stack2 stack;
public Stack2 stack;
Memory memory = MainCommand.memory;
ViewMachine vm = MainCommand.viewMachine;
JTable table;
......@@ -32,7 +32,7 @@ public class Thread {
public void save(){
this.FP = MainCommand.FP.get();
this.PC = MainCommand.viewMachine.PC.get()+1;
this.PC = MainCommand.viewMachine.PC.get();
this.SP = MainCommand.SP.get();
......
......@@ -25,7 +25,6 @@ public class Threadtable extends Register{
super( name, "Register", nextLocation, true );
this.name = name;
TTab.add( this );
nextLocation.translate( 0,getHeight() );
......
package vam.machines.tma;
import vam.base.ViewMachine;
public class UNLOCK extends MainCommand {
public UNLOCK()
{
super("UNLOCK");
}
public void execute()
{
int owner = memory.getIntValue(memory.getIntValue(SP()));
int pointer = memory.getIntValue(SP());
if(owner!=MainCommand.CT.get()){
ViewMachine.output("Illegal Unlock");
}
else{
if (memory.getValue(pointer+1) == ""){
memory.setIntValue(pointer,-1);
Thread thread = Threadtable.list.get(MainCommand.CT.get());
thread.getStack().pop();
}
else{memory.setIntValue(pointer, memory.getIntValue(pointer+1));
for (int i = 1;i<MainCommand.getStacknumber();i++){
if(memory.getValue(pointer+1+i) == ""){
memory.setValue(pointer+1, "");
}
else{memory.setIntValue(pointer+1,memory.getIntValue(pointer+1+i));}
}
Thread thread = Threadtable.list.get(MainCommand.CT.get());
thread.getStack().pop();
}
}
}
}
package vam.machines.tma;
import vam.base.ViewMachine;
public class WAIT extends MainCommand{
public WAIT()
{
super("WAIT");
}
public void execute()
{
int owner = memory.getIntValue(memory.getIntValue(SP()-1));
int cvpointer = memory.getIntValue(SP());
if(owner!=MainCommand.CT.get()){
ViewMachine.output("Illegal wait!");
}
else{for (int i = 0; i<MainCommand.getStacknumber()-1;i++){
if (memory.getValue(cvpointer+i)==""){
memory.setIntValue(cvpointer+i, MainCommand.CT.get());
break;
}
}
Thread thread = Threadtable.list.get(MainCommand.CT.get());
thread.getStack().pop();
}
}
}
......@@ -16,12 +16,13 @@ public class YIELD extends MainCommand{
{
if (ReadyQueue.array[0].belegt == true){
int tid = ReadyQueue.array[0].getIntValue();
ReadyQueue.yield();
Thread now = Threadtable.list.get(MainCommand.CT.get());
now.save();
ReadyQueue.yield();
ReadyQueue.enqueue(now.getTid());
MainCommand.CT.set(tid);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment