[kaffe] Fwd: MonitorVariable allocation problem

Guilhem Lavaux guilhem.lavaux@free.fr
Sat Jul 12 00:47:01 2003


--Boundary-00=_d67D/lmRRuYZ4uD
Content-Type: Text/Plain;
  charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Content-Description: clearsigned data
Content-Disposition: inline

Hi,

I know this is not really the place for that patch (I also sent it to KOPI=
=20
Developer list) but I do not know if the project is still really active...=
=20
Meanwhile here is a patch to fix KJC's problem raised by ShutdownHookTest. =
I=20
have checked the new compiler by compiling all the java libraries with itan=
d=20
all regression tests pass successfully. So if someone is interested in=20
testing it...

Regards,

Guilhem.
--Boundary-00=_d67D/lmRRuYZ4uD
Content-Type: message/rfc822;
  name="forwarded message"
Content-Transfer-Encoding: 8bit
Content-Description: Guilhem Lavaux <guilhem.lavaux@free.fr>: MonitorVariable allocation problem

Return-Path: <kopi-developers-return-41-guilhem.lavaux=free.fr@dms.at>
Delivered-To: online.fr-guilhem.lavaux@free.fr
Received: (qmail 2720 invoked from network); 12 Jul 2003 06:44:25 -0000
Received: from static62-99-203-81vienna-neutor-xdsl-line.inode.at (HELO dms.at) (62.99.203.81)
  by mrelay1-2.free.fr with SMTP; 12 Jul 2003 06:44:25 -0000
Received: (qmail 31686 invoked by uid 502); 12 Jul 2003 06:44:24 -0000
Mailing-List: contact kopi-developers-help@dms.at; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Post: <mailto:kopi-developers@dms.at>
List-Help: <mailto:kopi-developers-help@dms.at>
List-Unsubscribe: <mailto:kopi-developers-unsubscribe@dms.at>
List-Subscribe: <mailto:kopi-developers-subscribe@dms.at>
Delivered-To: mailing list kopi-developers@dms.at
Received: (qmail 31679 invoked by uid 2027); 12 Jul 2003 06:44:24 -0000
X-Spam-Status: No, hits=-5.2 required=5.0
From: Guilhem Lavaux <guilhem.lavaux@free.fr>
To: kopi-developers@dms.at
Subject: MonitorVariable allocation problem
Date: Sat, 12 Jul 2003 07:47:47 +0100
User-Agent: KMail/1.5
MIME-Version: 1.0
Content-Type: Multipart/Mixed;
  boundary="Boundary-00=_T86D/0iWtKpXGko"
Message-Id: <200307120747.50406.guilhem.lavaux@free.fr>
Status: RO
X-Status: O
X-KMail-EncryptionState: N
X-KMail-SignatureState: N


--Boundary-00=_T86D/0iWtKpXGko
Content-Type: Text/Plain;
  charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Content-Description: clearsigned data
Content-Disposition: inline

Hi,

I know that Iko Kazumitsu has recently sent a bug report on a problem with=
=20
Kaffe's KJC (actually I am the reporter) but it is also present in KJC 2.1B=
=2E=20
I managed to fix the problem and here is a patch against KJC 2.1B. The patc=
h=20
mainly add a system so that when you add a monitor variable the update of t=
he=20
position of all variables are back-propagated to all children block context=
=20
created before the call. Before that, only the variables of the parent bloc=
ks=20
have been updated.

Regards,

Guilhem.
--Boundary-00=_T86D/0iWtKpXGko
Content-Type: text/x-diff;
  charset="us-ascii";
  name="patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="patch"

diff -x 'KjcScanner*' -ru kopi-2.1B.orig/src/bytecode/ssa/LivenessComputer.java kopi-2.1B/src/bytecode/ssa/LivenessComputer.java
--- kopi-2.1B.orig/src/bytecode/ssa/LivenessComputer.java	2002-07-15 19:53:29.000000000 +0100
+++ kopi-2.1B/src/bytecode/ssa/LivenessComputer.java	2003-07-10 19:18:06.000000000 +0100
@@ -334,7 +334,7 @@
 		if (phi instanceof QPhiCatch) {
 
 		    //compute temp = (use[ij] - def[i1i2..i(j-1)]).
-		    temp.clear();
+		    for (int u=0;u<temp.size();u++) temp.clear(u);;
 		    QOperandBox[] operands = phi.getUses();
 		    for (int u = 0; u < operands.length; ++u) {
 			if (operands[u].getOperand() instanceof QSSAVar) {
@@ -360,7 +360,7 @@
 	    while (insts.hasNext()) {
 
 		//compute temp = (use[ij] - def[i1i2..i(j-1)]).
-		temp.clear();
+		for (int u=0;u<temp.size();u++) temp.clear(u);;
 		QInst inst = (QInst) insts.next();
 		QOperandBox[] operands = inst.getUses();
 		for (int u = 0; u < operands.length; ++u) {
@@ -434,7 +434,7 @@
 
 
 		//out[n] = union {s in succ[n]}  in[s]
-		out.clear();
+		for (int u=0;u<out.size();u++) out.clear(u);
 		Iterator succs = nodes[nodeIndex].getSuccessors();
 		while (succs.hasNext()) {
 		    out.or(ins[((Node)succs.next()).getIndex()]);
@@ -491,7 +491,7 @@
 	    while (insts.hasNext()) {
 
 		//compute temp = (use[ij] - def[i1i2..i(j-1)]).
-		temp.clear();
+		for (int u=0;u<temp.size();u++) temp.clear(u);
 		QInst inst = (QInst) insts.next();
 		QOperandBox[] operands = inst.getUses();
 		for (int u = 0; u < operands.length; ++u) {
@@ -530,7 +530,7 @@
 
 
 		//out[n] = union {s in succ[n]}  in[s]
-		out.clear();
+		for (int u=0;u<out.size();u++) out.clear(u);
 		Iterator succs = nodes[nodeIndex].getSuccessors();
 		while (succs.hasNext()) {
 		    out.or(ins[((Node)succs.next()).getIndex()]);
diff -x 'KjcScanner*' -ru kopi-2.1B.orig/src/kjc/CBlockContext.java kopi-2.1B/src/kjc/CBlockContext.java
--- kopi-2.1B.orig/src/kjc/CBlockContext.java	2002-07-15 19:53:32.000000000 +0100
+++ kopi-2.1B/src/kjc/CBlockContext.java	2003-07-12 07:38:44.000000000 +0100
@@ -59,6 +59,8 @@
     this.localVars = localVars == 0 ? null : new ArrayList(localVars);
     this.localsPosition = 0;
     this.parentIndex = 0;
+    this.localsIndex = 0;
+    this.childrenBlock = null;
   }
 
   /**
@@ -81,11 +83,15 @@
     super(parent, environment);
 
     this.localVars = new ArrayList(predictedVars);
+    this.childrenBlock = null;
 
     CBlockContext	parentBlock = parent.getBlockContext();
 
     this.localsPosition = parentBlock.localsPosition();
+    this.localsIndex = 0;
     this.parentIndex = parentBlock.localsIndex();
+
+    parentBlock.registerChildBlock(this);
   }
 
   // ----------------------------------------------------------------------
@@ -165,6 +171,41 @@
     localsPosition += var.getType().getSize();
   }
 
+  public void registerChildBlock(CBlockContext child) {
+     if (childrenBlock == null) {
+	 childrenBlock = new ArrayList();
+     }
+     childrenBlock.add(child);
+  }
+
+  /**
+   * Fix the position of local variables as a monitor variable has been
+   * added to the stack.
+   * 
+   * @param     incr     the update increment for local variables
+   */
+  public void fixVariablePositions(int increment) throws UnpositionedError {
+       localsPosition += increment;
+       parentIndex++;
+       for (int i=0; i < localVars.size(); i++) {
+           JLocalVariable  localVar = (JLocalVariable) localVars.get(i);
+
+           localVar.setPosition(localVar.getPosition()+increment);
+        // fix 27.03.02 lackner
+        // synthetic variable has no entry in CVariableInfo
+        // not necessary  think
+        //  localVar.setIndex(localVar.getIndex()+1);
+       }
+
+       if (childrenBlock != null) {
+         for (int i=0; i < childrenBlock.size(); i++) {
+	   CBlockContext child = (CBlockContext)childrenBlock.get(i);
+	   
+	   child.fixVariablePositions(increment);
+         }
+       }
+  }
+
   /**
    * Adds the variable for the monitor of the synchronized statement to the 
    * correct context.
@@ -173,23 +214,18 @@
    */
   public void addMonitorVariable(JLocalVariable var)  throws UnpositionedError {
     if (parent instanceof CMethodContext) {
+      int increment = var.getType().getSize();
+
       addVariable(var);
+      if (childrenBlock != null) {
+        for (int i=0; i < childrenBlock.size(); i++) {
+	   CBlockContext child = (CBlockContext)childrenBlock.get(i);
+	   
+	   child.fixVariablePositions(increment);
+        }
+      }
     } else {
       parent.addMonitorVariable(var);
-      // correct index
-      int       size = var.getType().getSize();
-
-      localsPosition += size;
-      parentIndex++;
-      for (int i=0; i < localVars.size(); i++) {
-        JLocalVariable  localVar = (JLocalVariable) localVars.get(i);
-
-        localVar.setPosition(localVar.getPosition()+size);
-        // fix 27.03.02 lackner
-        // synthetic variable has no entry in CVariableInfo
-        // not necessary  think
-        //  localVar.setIndex(localVar.getIndex()+1);
-      }
     }
   }
   /**
@@ -287,6 +323,7 @@
 
   private Hashtable				localClasses;
   private ArrayList				localVars;
+  private ArrayList				childrenBlock;
 
   private /*final*/ int				parentIndex;
   private int					localsIndex;

--Boundary-00=_T86D/0iWtKpXGko--



--Boundary-00=_d67D/lmRRuYZ4uD--