From: jzhou Date: Wed, 3 Nov 2010 23:31:35 +0000 (+0000) Subject: Fix volatile in mgc version. Volatile variable should not be allocated in the shared... X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=c48ebf719f4e5bb995e187273ac7df4de7289299;p=IRC.git Fix volatile in mgc version. Volatile variable should not be allocated in the shared heap like static variables --- diff --git a/Robust/src/IR/ClassDescriptor.java b/Robust/src/IR/ClassDescriptor.java index 98bb261c..3ca241e0 100644 --- a/Robust/src/IR/ClassDescriptor.java +++ b/Robust/src/IR/ClassDescriptor.java @@ -199,7 +199,7 @@ public class ClassDescriptor extends Descriptor { throw new Error(fd.getSymbol()+" already defined"); fields.add(fd); fieldvec.add(fd); - if((fd.isStatic()) || (fd.isVolatile())) { + if(fd.isStatic()) { this.incStaticFields(); } } diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index ff48bb57..bb0679cc 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -2180,8 +2180,8 @@ public class BuildCode { for(int i=0; i"+fd.getSafeSymbol()+"=&(global_defs_p->"+cn.getSafeSymbol()+fd.getSafeSymbol()+");"); } } @@ -5086,7 +5086,7 @@ public class BuildCode { // DEBUG } if(state.MGC) { // TODO add version for normal Java later - if((ffn.getField().isStatic()) || (ffn.getField().isVolatile())) { + if(ffn.getField().isStatic()) { // static field if((fm.getMethod().isStaticBlock()) || (fm.getMethod().isInvokedByStatic())) { // is a static block or is invoked in some static block @@ -5232,7 +5232,7 @@ public class BuildCode { // DEBUG } if(state.MGC) { // TODO add version for normal Java later - if((fsfn.getField().isStatic()) || (fsfn.getField().isVolatile())) { + if(fsfn.getField().isStatic()) { // static field if((fm.getMethod().isStaticBlock()) || (fm.getMethod().isInvokedByStatic())) { // is a static block or is invoked in some static block diff --git a/Robust/src/Tests/VolatileTest.java b/Robust/src/Tests/VolatileTest.java index 4eb0c7b4..2ec8a703 100644 --- a/Robust/src/Tests/VolatileTest.java +++ b/Robust/src/Tests/VolatileTest.java @@ -1,31 +1,38 @@ -public class VolatileTest extends Thread { - volatile int num; - String name; +public class VInt { + public int num; - { - num = 0; + public VInt() { + this.num = 0; } +} + +public class VolatileTest extends Thread { + volatile VInt vi; + String name; - public VolatileTest(String name) { + public VolatileTest(String name, VInt vi) { this.name = name; + this.vi = vi; } public void run(){ if(name.equals("Thread1")){ - num=10; + vi.num=10; } else{ - System.out.println("value of num is :"+num); + System.out.println("value of num is :"+vi.num); } } public static void main(String args[]){ - Thread t1 = new VolatileTest("Thread1"); + VInt vi = new VInt(); + + Thread t1 = new VolatileTest("Thread1", vi); t1.start(); Thread.sleep(1000); - Thread t2 = new VolatileTest("Thread2"); + Thread t2 = new VolatileTest("Thread2", vi); t2.start(); } } \ No newline at end of file