Commit 2eaa2de9 authored by Melanie Jakob's avatar Melanie Jakob

Dynamische Komonenten und sonstige Verbesserungen

parent 8afe9f4c
C:\Daten\UniMel\vam\
mutextest.tma
join.tma
......@@ -80,7 +80,7 @@ public class Cell extends JLabel implements MouseListener
defineType( "Pointer", Color.yellow, Color.black, stdWidth, stdHeight, POINTER );
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("JTable", Color.blue, Color.white, 40, stdHeight, NOPOINTER);
defineType("Mutex",Color.cyan,Color.black,50,stdHeight,NOPOINTER);
}
......
......@@ -3,9 +3,12 @@
package vam.base;
import java.util.*;
import java.util.List;
import javax.swing.*;
import vam.machines.tma.JTableElement;
import vam.machines.tma.MainCommand;
import vam.machines.tma.ReadyQueue;
import java.awt.*;
......@@ -60,8 +63,11 @@ class State {
private History history;
private LinkedList regValues;
private LinkedList rqBooleans;
private LinkedList rqValues;
private List<Integer> rqValues;
private List<List> jtabValues;
private List<Integer> threadPosition;
public static List<ReadyQueue> test2;
private HashMap mem;
private java.util.Stack trailCopy;
......@@ -71,7 +77,7 @@ class State {
public State(History history) {
this.history = history;
//readyQueue = new LinkedList<ReadyQueue>();
if(history.trail != null) {
trailCopy = (java.util.Stack)(history.trail.clone());
}
......@@ -84,20 +90,37 @@ class State {
regValues.add(new Integer(reg.value));
}
//store values of the ready queue
rqValues = new LinkedList();
ListIterator itb = history.rq.listIterator();
while(itb.hasNext()) {
ReadyQueue rq = (ReadyQueue)itb.next();
rqValues.add(new Integer(rq.get()));
rqValues = new LinkedList<Integer>();
for(ReadyQueue current:ReadyQueue.readyQueue){
rqValues.add((Integer)current.get());
}
//store values of the ready queue
rqBooleans = new LinkedList();
ListIterator itb2 = history.rq.listIterator();
while(itb2.hasNext()) {
ReadyQueue rq = (ReadyQueue)itb2.next();
rqBooleans.add(new Boolean(rq.isBelegt()));
//store Mutex and CV Cells
test2 = new LinkedList<ReadyQueue>();
for(ReadyQueue a:vam.machines.tma.MainCommand.newCells){
test2.add(a);
}
//store values of JTab
jtabValues = new ArrayList<List>();
for(JTableElement current:JTableElement.jTable){
List<Integer> a = new LinkedList<Integer>();
for(ReadyQueue now:current.waitingQueueList){
a.add(now.getIntValue());
}
jtabValues.add(a);
}
//store values of ThreadPosition
threadPosition = new LinkedList<Integer>();
for(int current:vam.machines.tma.Thread.threadPosition){
threadPosition.add(current);
}
mem = new HashMap();
......@@ -115,6 +138,7 @@ class State {
hiddenStackCells = history.vm.hiddenStackCells;
}
public void restore() {
Iterator it3 = history.vm.memory.memory.values().iterator();
while(it3.hasNext()) {
......@@ -133,6 +157,8 @@ class State {
history.vm.memory.memory.put(key, c);
}
it3 = history.vm.memory.memory.values().iterator();
while(it3.hasNext()) {
Cell c = (Cell)it3.next();
......@@ -144,9 +170,6 @@ class State {
ListIterator it = history.regs.listIterator();
ListIterator it2 = regValues.listIterator();
ListIterator itb = history.rq.listIterator();
ListIterator it2b = rqValues.listIterator();
ListIterator it3b = rqBooleans.listIterator();
while(it.hasNext()) {
......@@ -157,28 +180,17 @@ class State {
reg.set(v.intValue());
reg.updatePointer();
}
while(itb.hasNext()) {
ReadyQueue red = (ReadyQueue)itb.next();
Integer v = (Integer)it2b.next();
Boolean b = (Boolean)it3b.next();
history.vm.addVisualization(red);
if(b == true){
red.set(v.intValue());
red.setBelegt(b);
red.updatePointer();}
else {red.setValue("");
red.setBelegt(b);}
//red.set(v.intValue());
//red.setBelegt(b);
//red.updatePointer();
/*if(b == true){
red.set(v.intValue());
red.setBelegt(b);
red.updatePointer();}
else {red.setValue("");
red.setBelegt(b);}*/
restoreReadyQueue(rqValues);
restoreJTable(jtabValues);
restoreThreadPosition(threadPosition);
for(ReadyQueue c:vam.machines.tma.MainCommand.newCells){
c.remove();}
vam.machines.tma.MainCommand.newCells.clear();
for(ReadyQueue d:this.test2){
ReadyQueue e = new ReadyQueue(d.getName(),"Mutex",d.getLocation(),true);
vam.machines.tma.MainCommand.newCells.add(e);
}
history.vm.memory.addressForNewHeapObjects = addressForNewHeapObjects;
......@@ -194,12 +206,65 @@ class State {
history.vm.repaintView();
}
private void restoreThreadPosition(List<Integer> pos) {
vam.machines.tma.Thread.threadPosition.clear();
for(int current:pos){
vam.machines.tma.Thread.threadPosition.add(current);
}
int i = 0;
for(int now:pos){
if (now>-1){
vam.machines.tma.Thread t = vam.machines.tma.Threadtable.threadlist.get(i);
t.setPosition(now);
i++;}
}
}
public void restoreReadyQueue(List<Integer> rqValues) {
for(ReadyQueue current:ReadyQueue.readyQueue){
ReadyQueue.rqGroup.remove(current);
current.remove();
}
ReadyQueue.readyQueue.clear();
ReadyQueue.nextLocation = new Point(130,0);
for(Integer cur:rqValues){
ReadyQueue.enqueue(cur);
}
}
public void restoreJTable(List<List> jtab){
//alte JTable lschen
for(int i=0;i<JTableElement.jTable.size();i++){
JTableElement j = JTableElement.jTable.get(i);
for(ReadyQueue current:j.waitingQueueList){
ReadyQueue.rqGroup.remove(current);
current.remove();}
}
JTableElement.jTable.clear();
//JTable wiederherstellen
int k = 0;
for(List<Integer> entry:jtab){
JTableElement tab = new JTableElement(k,entry);
k++;
JTableElement.jTable.add(tab);
}
}
}
public class History {
public ViewMachine vm;
public LinkedList regs;
public LinkedList rq;
public java.util.Stack trail;
private java.util.Stack history;
......@@ -207,7 +272,6 @@ public class History {
this.vm = vm;
history = new java.util.Stack();
regs = new LinkedList();
rq = new LinkedList();
trail = null;
}
......@@ -231,9 +295,6 @@ public class History {
regs.add(reg);
}
public void readyqueue(ReadyQueue red){
rq.add(red);
}
public void registerTrail(java.util.Stack trail) {
......
......@@ -21,7 +21,7 @@ public class Memory
// Laufzeitumgebeung
static ViewMachine vm;
public int ct; // von mir fr neue Berechnung von Location
public int threadPos; // von mir fr neue Berechnung von Location
// (CMa)-Heap
public int addressForNewHeapObjects;
......@@ -46,10 +46,10 @@ public class Memory
addressForNewHeapObjects = 1001;
// Layout fr (CMa-)Heap
// changed by Alex Dann : Anfang vom Heap war bei kleiner Aufloesung
// nicht zu sehen
newHeapObjectLocation = new Point(440,vm.view.getHeight());
//newHeapObjectLocation = new Point(440,600+(Cell.stdHeight+13));
// changed by Alex Dann : Anfang vom Heap war bei kleiner Aufloesung
// nicht zu sehen
newHeapObjectLocation = new Point(440,vm.view.getHeight());
//newHeapObjectLocation = new Point(440,600+(Cell.stdHeight+13));
}
// ***********************
......@@ -127,6 +127,7 @@ public class Memory
setValue( address,Integer.toString(value), type );
}
/**
Liefert den Wert einer Adresse
......@@ -351,10 +352,10 @@ public class Memory
c[i].highlight( false );
highlight( sourceAddress+i, false );
}
//************************
vm.sync();
//************************
//************************
vm.sync();
//************************
// Speicherinhalte neu setzen
for( int i=0; i<number; i++ )
......@@ -646,7 +647,7 @@ public class Memory
p.setLocation( trans.x,trans.y );
}
else p.setLocation(100,vm.view.getHeight()-30);
p.translate( ((address-ct*100)/cellsPerColumn)*(Cell.stdWidth+30),-((address-ct*100) % cellsPerColumn)*Cell.stdHeight );
p.translate( ((address-threadPos*100)/cellsPerColumn)*(Cell.stdWidth+30),-((address-threadPos*100) % cellsPerColumn)*Cell.stdHeight );
}
// CMa Heap
else if ( 500<address && address<=1000 )
......@@ -683,36 +684,56 @@ public class Memory
Point calculateLocationTma( int address ){
Point p = new Point(50,0);
ct = vam.machines.tma.MainCommand.CT.get();;
Thread thread = Threadtable.threadlist.get(MainCommand.CT.get());
threadPos = thread.getPosition();
int differenz = 100; //Platz zwischen den Stacks
int startwidth = 150; //Anfangspunkt des ersten Stacks
Thread thread = Threadtable.list.get(ct);
int startwidth = 150; //Anfangspunkt des ersten Stacks
int bound = vm.getStackBound();
int a = address;
/*if(thread.getStack().getSize() >= bound )
{
vm.finalizeStackVisualization(true, address, 1);
int stackSpace = vam.machines.tma.MainCommand.getStackspace();
while (a>=stackSpace){
a=a-stackSpace;
}
else{*/
// Stack
int b = a;
if ( 0<=address && address<=700 )
{
int cellsPerColumn = (vm.view.getHeight()-30)/Cell.stdHeight;
if ( exists(0) )
{
int i = 0;
while(b>=cellsPerColumn){
b = b - cellsPerColumn;
i++;
}
if(i>0){
if((vam.machines.tma.Thread.threadPosition.get(threadPos+1)>-1)){
vam.machines.tma.Thread.threadPosition.add(threadPos+1,-2);
vam.machines.tma.Thread.push(threadPos+2);}
else{
if((vam.machines.tma.Thread.threadPosition.get(threadPos+1)>-i-1)){
vam.machines.tma.Thread.push(threadPos+2);
int now = vam.machines.tma.Thread.threadPosition.get(threadPos+1);
vam.machines.tma.Thread.threadPosition.set(threadPos+1,now-1);}
else if((vam.machines.tma.Thread.threadPosition.get(threadPos+1)<-i-1)){
vam.machines.tma.Thread.pull(threadPos+2);
int now = vam.machines.tma.Thread.threadPosition.get(threadPos+1);
vam.machines.tma.Thread.threadPosition.set(threadPos+1,now+1);}
}
}
Point trans = getCell(0).getLocation();
if (address < MainCommand.getStackspace()){
p.setLocation( trans.x*(ct+1),trans.y );
p.setLocation( trans.x*(threadPos+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*(threadPos),trans.y );}
}
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 );
else p.setLocation(startwidth+differenz*(threadPos),vm.view.getHeight()-30);
p.translate( (a/cellsPerColumn)*(Cell.stdWidth+30),-(a % cellsPerColumn)*Cell.stdHeight );
}
// CMa Heap
else
......@@ -768,18 +789,18 @@ public class Memory
Entfernt die Visualisierung einer Adresse ohne Animation.
@param address Adresse
*/
void free( int address )
{
/*
Object obj = memory.remove( new Integer(address) );
vm.removeVisualization((JComponent)obj);
*/
Cell c = (Cell)(memory.remove( new Integer(address) ));
if(c != null) {
c.removeToPointers();
c.remove();
}
}
void free( int address )
{
/*
Object obj = memory.remove( new Integer(address) );
vm.removeVisualization((JComponent)obj);
*/
Cell c = (Cell)(memory.remove( new Integer(address) ));
if(c != null) {
c.removeToPointers();
c.remove();
}
}
/**
Entfernt die Visualisierung einer Adresse mit Animation.
......@@ -791,20 +812,20 @@ public class Memory
Cell cell = (Cell)memory.get(new Integer(address));
String value = cell.getValue();
if ( cell.isVisible() )
{
cell.highlight(true);
cell.removePointer();
vm.view.repaint();
cell.fadeOut();
cell.sync();
cell.highlight(false);
}
if ( cell.isVisible() )
{
cell.highlight(true);
cell.removePointer();
vm.view.repaint();
cell.fadeOut();
cell.sync();
cell.highlight(false);
}
free( address );
return value;
......@@ -966,38 +987,38 @@ public class Memory
return alloc( types, visible );
}
// by Alex Dann
public void dealloc(int address, int number)
{
if (number <= 0)
return;
// by Alex Dann
public void dealloc(int address, int number)
{
if (number <= 0)
return;
if(addressForNewHeapObjects == address+number) {
// Es werden die obersten Zellen deallokiert
// -> addressForNewHeapObjects & newHeapObjectLocation anpassen
newHeapObjectLocation = getCell(address).getLocation();
newHeapObjectLocation.translate( 0,(Cell.stdHeight+13) );
if ( newHeapObjectLocation.y > 600 ) newHeapObjectLocation.setLocation(newHeapObjectLocation.x-160,Cell.stdHeight+13);
// -> addressForNewHeapObjects & newHeapObjectLocation anpassen
newHeapObjectLocation = getCell(address).getLocation();
newHeapObjectLocation.translate( 0,(Cell.stdHeight+13) );
if ( newHeapObjectLocation.y > 600 ) newHeapObjectLocation.setLocation(newHeapObjectLocation.x-160,Cell.stdHeight+13);
addressForNewHeapObjects -= number;
}
highlight(address, Color.black, number);
vm.sleep( vm.optionStdPause );
for(int i = 0; i < number; i++) {
//remove(address + i);
free(address + i);
}
}
highlight(address, Color.black, number);
vm.sleep( vm.optionStdPause );
for(int i = 0; i < number; i++) {
//remove(address + i);
free(address + i);
}
vm.sync();
vm.view.repaint();
// calculateLocation(addressForNewHeapObjects);
// calculateLocation(addressForNewHeapObjects);
}
// setzt newHeapObjectLocation auf initialen Wert zurueck
// wird fuer Kompaktieren des Stack nach einer GC benoetigt
public void resetHeapObjectLocation() {
newHeapObjectLocation = new Point(440,vm.view.getHeight());
}
}
}
\ No newline at end of file
......@@ -438,9 +438,9 @@ public class Memory2 extends Memory
}
}
// AD : setzt newHeapObjectLocation auf initialen Wert zurueck
// wird fuer Kompaktieren des Stack nach einer GC benoetigt
public void resetHeapObjectLocation() {
// AD : setzt newHeapObjectLocation auf initialen Wert zurueck
// wird fuer Kompaktieren des Stack nach einer GC benoetigt
public void resetHeapObjectLocation() {
newHeapObjectLocation = new Point(350,vm.view.getHeight());
}
}
......@@ -34,7 +34,7 @@ public class Pointer extends JPanel
public Pointer( Cell source )
{
super();
//changed by Melanie Jakob: bei größerem Fenster waren die Pointer abgeschnitten
//changed by Melanie Jakob 2015: 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 );
......
......@@ -92,9 +92,11 @@ public class ViewMachine implements ActionListener
public int stackBound;
private Cell dotsCell;
public int hiddenStackCells;
// von mir
// changed by Melanie Jakob
// needed by TMA
static public String ext;
public boolean yield = false;
public boolean yield = false; //true when the yield button was activated
/**
Generiert Fenster und Laufzeitumgebung.
......@@ -1430,11 +1432,13 @@ public class ViewMachine implements ActionListener
comment = null;
view.removeAll();
Register.reset();
vam.machines.tma.JTable.reset();
//von mir
Threadtable.list.clear();
// structures of the tma machine
vam.machines.tma.JTableElement.reset();
Threadtable.threadlist.clear();
Threadtable.reset();
ReadyQueue.reset();
vam.machines.tma.Thread.threadPosition.clear();
repaintView();
visualizationList.clear(); // AD : sonts bleibt das System manchmal haengen (nach einem restart)
......@@ -1530,7 +1534,7 @@ public class ViewMachine implements ActionListener
// WARNUNG : beim Verschieben nach unten wird num = 1 vorausgesetzt
// num wird nur beim Verschieben nach oben benutzt, und zwar
// falls mehrere Zellen vom Stack gleichzeitig verschwinden
vam.machines.tma.Thread thread = Threadtable.list.get(MainCommand.CT.get());
vam.machines.tma.Thread thread = Threadtable.threadlist.get(MainCommand.CT.get());
int ct = MainCommand.CT.get();
int stackSize = thread.stack.getSize();
......@@ -1562,8 +1566,8 @@ public class ViewMachine implements ActionListener
actions.add(new MoveAction(c, new Point(new_loc)));
}
thread.hiddenStackCells -= num;
//von mir warum auch immer
//thread.hiddenStackCells -= num;
}
for(int i = 0; i < actions.size(); i++) {
......@@ -1615,7 +1619,7 @@ public class ViewMachine implements ActionListener
else if(ext.equals("jvm")) {
machine = "vam.machines.minijvm";
}
// von mir
else if(ext.equals("tma")) {
machine = "vam.machines.tma";
}
......
......@@ -15,7 +15,7 @@ public class ADD extends MainCommand
{
int op2 = memory.getIntValue( SP() );
int op1 = memory.getIntValue( SP()-1 );
Thread thread = Threadtable.list.get(MainCommand.CT.get());
Thread thread = Threadtable.threadlist.get(MainCommand.CT.get());
thread.getStack().binaryOperation( "ADD", op1 + op2 );
}
}
......@@ -14,7 +14,7 @@ public class ALLOC extends MainCommand
public void execute()
{
Thread thread = Threadtable.list.get(MainCommand.CT.get());
Thread thread = Threadtable.threadlist.get(MainCommand.CT.get());
thread.getStack().increase( number );
}
}
......@@ -13,7 +13,7 @@ public class AND extends MainCommand
{
int op2 = memory.getIntValue( SP() );
int op1 = memory.getIntValue( SP()-1 );
Thread thread = Threadtable.list.get(MainCommand.CT.get());
Thread thread = Threadtable.threadlist.get(MainCommand.CT.get());
thread.getStack().binaryOperation( "AND", op1 & op2 );
}
}
......@@ -14,7 +14,7 @@ public class DIV extends MainCommand
int op2 = memory.getIntValue( SP() );
int op1 = memory.getIntValue( SP()-1 );
//else stack.binaryOperation( "DIV", op1 / op2 );
Thread thread = Threadtable.list.get(MainCommand.CT.get());
Thread thread = Threadtable.threadlist.get(MainCommand.CT.get());
if( op2 == 0 ) cmaError("Division by zero.");
else thread.getStack().binaryOperation( "DIV", op1 / op2 );
}
......
......@@ -12,7 +12,7 @@ public class DUP extends MainCommand
public void execute()
{
//stack.pushFromAddress( SP() );
Thread thread = Threadtable.list.get(MainCommand.CT.get());
Thread thread = Threadtable.threadlist.get(MainCommand.CT.get());
thread.getStack().pushFromAddress( SP() );
}
}
......@@ -14,7 +14,7 @@ public class EQ extends MainCommand
int op2 = memory.getIntValue( SP() );
int op1 = memory.getIntValue( SP()-1 );
//stack.binaryOperation( "EQ", op1==op2 ? 1 : 0 );
Thread thread = Threadtable.list.get(MainCommand.CT.get());
Thread thread = Threadtable.threadlist.get(MainCommand.CT.get());
thread.getStack().binaryOperation( "EQ", op1==op2 ? 1 : 0 );
}
}
......@@ -21,7 +21,7 @@ public class EXIT extends MainCommand
int oldFP = memory.getIntValue(MainCommand.FP.get()-1);
MainCommand.FP.set(oldFP);
FP = MainCommand.FP.getIntValue();
Thread thread = Threadtable.list.get(MainCommand.CT.get());
Thread thread = Threadtable.threadlist.get(MainCommand.CT.get());
thread.getStack().decrease(oldSP-newSP);
}
memory.setIntValue(MainCommand.SP.get(), result);
......
......@@ -11,9 +11,14 @@ public class FINALIZE extends MainCommand {
public void execute()
{
int tid = memory.getIntValue(SP.get());
memory.setIntValue(SP.get(),JTable.array2[tid][1].get());
if(tid>MainCommand.TC.get()){
MainCommand.viewMachine.output("The chosen Thread is not available");
PC(-1);
}
else{
int returnValue = JTableElement.jTable.get(tid).waitingQueueList.get(1).getIntValue();
memory.setIntValue(SP.get(),returnValue);
}
}
......
......@@ -13,7 +13,7 @@ public class GE extends MainCommand
int op2 = memory.getIntValue( SP() );
int op1 = memory.getIntValue( SP()-1 );
//stack.binaryOperation( "GE", op1>op2 ? 1 : 0 );
Thread thread = Threadtable.list.get(MainCommand.CT.get());
Thread thread = Threadtable.threadlist.get(MainCommand.CT.get());
thread.getStack().binaryOperation( "GE", op1>op2 ? 1 : 0 );
}
}
......@@ -13,7 +13,7 @@ public class GEQ extends MainCommand
int op2 = memory.getIntValue( SP() );
int op1 = memory.getIntValue( SP()-1 );
//stack.binaryOperation( "GEQ", op1>=op2 ? 1 : 0 );
Thread thread = Threadtable.list.get(MainCommand.CT.get());
Thread thread = Threadtable.threadlist.get(MainCommand.CT.get());
thread.getStack().binaryOperation( "GEQ", op1>=op2 ? 1 : 0 );
}
}
......@@ -13,7 +13,7 @@ public class GR extends MainCommand
int op2 = memory.getIntValue( SP() );
int op1 = memory.getIntValue( SP()-1 );
//stack.binaryOperation( "GR", op1>op2 ? 1 : 0 );
Thread thread = Threadtable.list.get(MainCommand.CT.get());
Thread thread = Threadtable.threadlist.get(MainCommand.CT.get());
thread.getStack().binaryOperation( "GR", op1>op2 ? 1 : 0 );
}
}
......@@ -23,7 +23,7 @@ public class INITSTACK extends MainCommand{
public void execute()