harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wjwashb...@apache.org
Subject svn commit: r439302 - in /incubator/harmony/enhanced/drlvm/trunk/vm/MMTk: TestCopyMS.java TestGenMS.java TestMarkSweep.java TestSemiSpace.java docopyms.bat dogenms.bat doss.bat dovmmagic.bat
Date Fri, 01 Sep 2006 12:57:57 GMT
Author: wjwashburn
Date: Fri Sep  1 05:57:56 2006
New Revision: 439302

URL: http://svn.apache.org/viewvc?rev=439302&view=rev
Log:
MMTk GenMS mods

Added:
    incubator/harmony/enhanced/drlvm/trunk/vm/MMTk/TestCopyMS.java
    incubator/harmony/enhanced/drlvm/trunk/vm/MMTk/TestGenMS.java
    incubator/harmony/enhanced/drlvm/trunk/vm/MMTk/TestMarkSweep.java
    incubator/harmony/enhanced/drlvm/trunk/vm/MMTk/TestSemiSpace.java
    incubator/harmony/enhanced/drlvm/trunk/vm/MMTk/docopyms.bat
    incubator/harmony/enhanced/drlvm/trunk/vm/MMTk/dogenms.bat
    incubator/harmony/enhanced/drlvm/trunk/vm/MMTk/doss.bat
    incubator/harmony/enhanced/drlvm/trunk/vm/MMTk/dovmmagic.bat

Added: incubator/harmony/enhanced/drlvm/trunk/vm/MMTk/TestCopyMS.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/MMTk/TestCopyMS.java?rev=439302&view=auto
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/MMTk/TestCopyMS.java (added)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/MMTk/TestCopyMS.java Fri Sep  1 05:57:56 2006
@@ -0,0 +1,314 @@
+/*
+ *  Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+import org.vmmagic.unboxed.*;
+import org.apache.HarmonyDRLVM.mm.mmtk.*;
+import org.mmtk.vm.*;
+import org.mmtk.plan.Plan;
+import org.mmtk.plan.CollectorContext;
+import org.mmtk.utility.heap.LazyMmapper;
+import org.mmtk.plan.MutatorContext;
+////////////import org.mmtk.plan.marksweep.MS;
+//////////import org.mmtk.plan.nogc.*;
+import org.mmtk.plan.semispace.SS;
+import org.mmtk.utility.options.*;
+import org.mmtk.utility.Log;
+import org.mmtk.utility.heap.*;
+import org.mmtk.plan.copyms.*;
+
+public class TestCopyMS 
+{
+    static MutatorContext mc;
+    static CollectorContext cc;
+    public static void main(String[] args) 
+    {
+        VM vm_init = new VM();
+        //NoGC pl2 = (NoGC)SelectedPlan.get();
+        //MS pl2 = (MS)SelectedPlan.get();
+        //SS pl2 = (SS)SelectedPlan.get();
+        CopyMS pl2 = (CopyMS)SelectedPlan.get();
+        Plan pl = SelectedPlan.ap.global();
+
+        pl2.boot();
+        pl.fullyBooted();
+        org.apache.HarmonyDRLVM.mm.mmtk.SynchronizedCounter.boot();
+        LazyMmapper.boot(Address.zero(), 0 );
+        HeapGrowthManager.boot(Extent.fromInt(1024*1024*1), Extent.fromInt(1024*1024*1) ); //set the java heap very small to force collections
+
+        TestCopyMS.mc = SelectedPlan.ap.mutator();
+        TestCopyMS.cc = SelectedPlan.ap.collector();
+
+        //System.out.println("TestCopyMS SS.copySpace0.getName() = " + SS.copySpace0.getName() );
+        //System.out.println("TestCopyMS SS.copySpace1.getName() = " + SS.copySpace1.getName() );
+
+
+        int xx = Integer.decode(args[0]);
+        switch (xx)
+        {
+            case 1:
+                test0();
+                test1();
+                test2();
+                testWB();             
+                break;
+            case 2:
+                singleRootTest();
+                break;
+            case 3:
+                linkListOfLiveObjectsTest();
+                break;
+            case 4:
+                linkListOfLiveObjectsTest2();
+                break;
+            default:
+                System.out.println("******************** do nothing, invalid test number  ***********************");
+                break;
+        }
+    }
+
+    static final int arrayLenOffset = 8;
+    static void test0()
+    {
+        Object [] arr = new Object[13];
+        ObjectReference ref = ObjectReference.fromObject(arr);
+        Address addr = ref.toAddress();
+        Address lenAddr = addr.plus(arrayLenOffset);
+        int len = lenAddr.loadInt();
+        if (len != arr.length) 
+        {
+            throw new Error("length does not match");
+        }
+        System.out.println("test0 - ok");
+    }
+    static void test1()
+    {
+        Object [] arr = new Object[17];
+        ObjectReference ref = ObjectReference.fromObject(arr);
+        Address addr = ref.toAddress();
+        Offset off = Offset.fromIntSignExtend(arrayLenOffset);
+        int len = addr.loadInt(off);
+        if (len != arr.length) 
+        {
+            throw new Error("length does not match");
+        }
+        System.out.println("test1 - ok");
+    }
+
+    static void test2()
+    {
+        Object obj = new Object();
+        ObjectReference ref = ObjectReference.fromObject(obj);
+        ObjectReferenceArray arr = ObjectReferenceArray.create(1);
+        arr.set(0, ref);
+        if (arr.get(0) != ref) 
+        {
+            throw new Error("Invalid ref read");
+        }
+        try 
+        {
+            // Even though these are magics, can't allow to 
+            // write outside of array.
+            arr.set(10, ref);
+            // must not be here
+            throw new Error("Bounds check was not performed");
+        }
+        catch(ArrayIndexOutOfBoundsException e) 
+        {
+            // ok
+        }
+        System.out.println("test2 - ok");
+    }
+
+    static Object wbFldStatic = null;
+    Object  wbFldInstance = null;
+    static void testWB()
+    {
+        Object obj = new Object();
+        TestCopyMS t = new TestCopyMS();
+        Object[] array = new Object[10];
+        //
+        wbFldStatic = obj;
+        //
+        t.wbFldInstance = obj;
+        //
+        array[3] = obj;
+        //
+        System.out.println("testWB - seems ok");
+    }
+    static void singleRootTest()
+    {        
+        int [] ia = new int[10];
+        
+        ObjectReference orIa = ObjectReference.fromObject(ia);
+        Address addrIa = orIa.toAddress();
+        int vtblPtr = addrIa.loadInt();
+        Address addrLenIa = addrIa.plus(8);
+        int length = addrLenIa.loadInt();
+        if (length != 10) System.out.println("TestCopyMS.java -- bad length -------------------" + length);
+
+        Address addrImmortalObj = TestCopyMS.mc.alloc(52, 0, 0, Plan.ALLOC_IMMORTAL, 0);
+        addrImmortalObj.store(vtblPtr);
+        Address addrLenImmortal = addrImmortalObj.plus(8);
+        addrLenImmortal.store(length);
+  
+        Address addrImmortalObjElementZero = addrImmortalObj.plus(12); // stuff the _address_ of the root into element zero of the immortal array
+
+        Address addrLiveObj = mc.alloc(52, 0, 0, Plan.ALLOC_DEFAULT, 0);
+        addrLiveObj.store(vtblPtr);
+        Address addrLenLive = addrLiveObj.plus(8);
+        addrLenLive.store(length);
+
+        addrImmortalObjElementZero.store(addrLiveObj);  // stuff the _address_ of the array into an element to test enumeration
+        org.apache.HarmonyDRLVM.mm.mmtk.Scanning.addressOfTestRoot = addrImmortalObjElementZero.toInt();
+
+        System.out.println("addressOfTestRoot = " + Integer.toHexString(addrImmortalObjElementZero.toInt() ) );
+        System.out.println("the root itself is = " + Integer.toHexString(addrLiveObj.toInt()) );
+
+        for (int kk = 0;  kk < 5; kk++)
+        {
+            addrLiveObj = addrImmortalObjElementZero.loadAddress();
+            Address addrLiveElement3 = addrLiveObj.plus(12 + 3*4);
+            addrLiveElement3.store(kk);
+
+            for (int jj = 0; jj < 800000; jj++) 
+            {
+                Address addrDeadObj = mc.alloc(52, 0, 0, Plan.ALLOC_DEFAULT, 0);
+                addrDeadObj.store(vtblPtr);
+                Address addrLenDeadObj = addrDeadObj.plus(8);
+                addrLenDeadObj.store(length);
+            }
+
+            addrLiveObj = addrImmortalObjElementZero.loadAddress();
+            addrLiveElement3 = addrLiveObj.plus(12 + 3*4);
+            int xx = addrLiveElement3.loadInt();
+            if ( xx != kk  )
+                System.out.println("kk = " + kk + " element 3 = " + xx  );
+            System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ single root test, loop = " + kk + " OK");
+        }
+    }
+    static void linkListOfLiveObjectsTest()
+    {
+        Green gr = new Green();
+        ObjectReference orGr = ObjectReference.fromObject(gr);
+        Address addrGr = orGr.toAddress();
+        int vtblPtrGreen = addrGr.loadInt();
+
+        Address addrImmortalObj = TestCopyMS.mc.alloc(52, 0, 0, Plan.ALLOC_IMMORTAL, 0);
+        addrImmortalObj.store(vtblPtrGreen);
+  
+        Address addrImmortalObjFieldZero = addrImmortalObj.plus(8); // stuff the _address_ of the root into element zero of the immortal array
+
+        Address addrLiveObj = mc.alloc(52, 0, 0, Plan.ALLOC_DEFAULT, 0);
+        addrLiveObj.store(vtblPtrGreen);
+
+        addrImmortalObjFieldZero.store(addrLiveObj);  // stuff the _address_ of the array into an element to test enumeration
+        org.apache.HarmonyDRLVM.mm.mmtk.Scanning.addressOfTestRoot = addrImmortalObjFieldZero.toInt();
+
+        System.out.println("addressOfTestRoot = " + Integer.toHexString(addrImmortalObjFieldZero.toInt() ) );
+        System.out.println("the root itself is = " + Integer.toHexString(addrLiveObj.toInt()) );
+
+        Object [] oa = new Object[10];
+        ObjectReference orOa = ObjectReference.fromObject(oa);
+        Address addrOa = orOa.toAddress();
+        int vtblPtrOa = addrOa.loadInt();
+        Address addrLenOa = addrOa.plus(8);
+        int lengthOa = addrLenOa.loadInt();
+        if (lengthOa != 10) System.out.println("TestCopyMS.java -- bad length -------------------" + lengthOa);
+        Address addrLiveArray = mc.alloc(52, 0, 0, Plan.ALLOC_DEFAULT, 0);
+     
+        addrLiveArray.store(vtblPtrOa);
+        Address addrLiveArrayLen = addrLiveArray.plus(8);
+        addrLiveArrayLen.store(lengthOa);
+
+        ObjectReference orGreen = addrLiveObj.toObjectReference();
+        Green oldGreen = (Green)orGreen.toObject();
+        oldGreen.f8 = (Object [])addrLiveArray.toObjectReference().toObject();
+
+        Address addrLeafGreen = mc.alloc(52, 0, 0, Plan.ALLOC_DEFAULT, 0);
+        addrLeafGreen.store(vtblPtrGreen); 
+        oldGreen.f8[3] = addrLeafGreen.toObjectReference().toObject();
+
+        for (int kk = 0;  kk < 500; kk++)  //create 5K *52 = 250KB of live objects
+        {
+            Address addrNext = mc.alloc(52, 0, 0, Plan.ALLOC_DEFAULT, 0);
+            addrNext.store(vtblPtrGreen);
+            ObjectReference or2 = addrNext.toObjectReference();
+            Green newGreen = (Green)or2.toObject();
+            oldGreen.f1 = newGreen;
+            oldGreen.f6 = kk;
+            oldGreen = newGreen;
+        }
+
+        for (int jj = 0; jj < 150000; jj++) // generate lots of dead objects, cause lots of GCs
+        {
+            Address addrDeadObj = mc.alloc(52, 0, 0, Plan.ALLOC_DEFAULT, 0);
+            addrDeadObj.store(vtblPtrGreen);
+        }
+
+        addrLiveObj = addrImmortalObjFieldZero.loadAddress();  //reload the lead object
+        orGreen = addrLiveObj.toObjectReference();
+        Green greenCursor = (Green)orGreen.toObject();   //everything from base object should always be reachable
+
+        System.out.println("greenCursor.f8[3] = " + greenCursor.f8[3]);
+        System.out.println("greenCursor.f8[4] = " + greenCursor.f8[4]);
+
+        for (int rr = 0; rr < 500; rr++) 
+        {
+            if (greenCursor.f6 != rr) System.out.println("oldGreen.f6 = " + oldGreen.f6 + " rr = " + rr); //VM.assertions._assert(false);
+            greenCursor = greenCursor.f1; 
+        }
+        System.out.println("greenCursor = " + greenCursor);
+        System.out.println("linkListOfLiveObjectsTest, the live objects are still intact  OK");
+    }
+ 
+    static void linkListOfLiveObjectsTest2()
+    {
+        System.out.println("linkListOfLiveObjectsTest2, this test should fail real close to 1/2 the size of the java heap");
+        Green gr = new Green();
+        ObjectReference orGr = ObjectReference.fromObject(gr);
+        Address addrGr = orGr.toAddress();
+        int vtblPtrGreen = addrGr.loadInt();
+
+        Address addrImmortalObj = TestCopyMS.mc.alloc(52, 0, 0, Plan.ALLOC_IMMORTAL, 0);
+        addrImmortalObj.store(vtblPtrGreen);
+  
+        Address addrImmortalObjFieldZero = addrImmortalObj.plus(8); // stuff the _address_ of the root into element zero of the immortal array
+
+        Address addrLiveObj = mc.alloc(52, 0, 0, Plan.ALLOC_DEFAULT, 0);
+        addrLiveObj.store(vtblPtrGreen);
+
+        addrImmortalObjFieldZero.store(addrLiveObj);  // stuff the _address_ of the array into an element to test enumeration
+        org.apache.HarmonyDRLVM.mm.mmtk.Scanning.addressOfTestRoot = addrImmortalObjFieldZero.toInt();
+
+        System.out.println("addressOfTestRoot = " + Integer.toHexString(addrImmortalObjFieldZero.toInt() ) );
+        System.out.println("the root itself is = " + Integer.toHexString(addrLiveObj.toInt()) );
+
+        ObjectReference orGreen = addrLiveObj.toObjectReference();
+        Green oldGreen = (Green)orGreen.toObject();
+
+        for (int kk = 0;  kk < 50000000; kk++)  //intentionally grab the entire heap
+        {
+            Address addrNext = mc.alloc(52, 0, 0, Plan.ALLOC_DEFAULT, 0);
+            addrNext.store(vtblPtrGreen);
+            ObjectReference or2 = addrNext.toObjectReference();
+            Green newGreen = (Green)or2.toObject();
+            oldGreen.f1 = newGreen;
+            oldGreen.f6 = kk;
+            oldGreen = newGreen;
+        }
+    }
+
+}

Added: incubator/harmony/enhanced/drlvm/trunk/vm/MMTk/TestGenMS.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/MMTk/TestGenMS.java?rev=439302&view=auto
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/MMTk/TestGenMS.java (added)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/MMTk/TestGenMS.java Fri Sep  1 05:57:56 2006
@@ -0,0 +1,313 @@
+/*
+ *  Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+import org.vmmagic.unboxed.*;
+import org.apache.HarmonyDRLVM.mm.mmtk.*;
+import org.mmtk.vm.*;
+import org.mmtk.plan.Plan;
+import org.mmtk.plan.CollectorContext;
+import org.mmtk.utility.heap.LazyMmapper;
+import org.mmtk.plan.MutatorContext;
+////////////import org.mmtk.plan.marksweep.MS;
+//////////import org.mmtk.plan.nogc.*;
+import org.mmtk.plan.semispace.SS;
+import org.mmtk.utility.options.*;
+import org.mmtk.utility.Log;
+import org.mmtk.utility.heap.*;
+import org.mmtk.plan.copyms.*;
+import org.mmtk.plan.generational.marksweep.GenMS;
+
+public class TestGenMS 
+{
+    static MutatorContext mc;
+    static CollectorContext cc;
+    public static void main(String[] args) 
+    {
+        VM vm_init = new VM();
+        //CopyMS pl2 = (CopyMS)SelectedPlan.get();
+        GenMS pl2 = (GenMS)SelectedPlan.get();
+        Plan pl = SelectedPlan.ap.global();
+
+        pl2.boot();
+        pl.fullyBooted();
+        org.apache.HarmonyDRLVM.mm.mmtk.SynchronizedCounter.boot();
+        LazyMmapper.boot(Address.zero(), 0 );
+        HeapGrowthManager.boot(Extent.fromInt(1024*1024*1), Extent.fromInt(1024*1024*1) ); //set the java heap very small to force collections
+
+        TestGenMS.mc = SelectedPlan.ap.mutator();
+        TestGenMS.cc = SelectedPlan.ap.collector();
+
+        //System.out.println("TestGenMS SS.copySpace0.getName() = " + SS.copySpace0.getName() );
+        //System.out.println("TestGenMS SS.copySpace1.getName() = " + SS.copySpace1.getName() );
+
+
+        int xx = Integer.decode(args[0]);
+        switch (xx)
+        {
+            case 1:
+                test0();
+                test1();
+                test2();
+                testWB();             
+                break;
+            case 2:
+                singleRootTest();
+                break;
+            case 3:
+                linkListOfLiveObjectsTest();
+                break;
+            case 4:
+                linkListOfLiveObjectsTest2();
+                break;
+            default:
+                System.out.println("******************** do nothing, invalid test number  ***********************");
+                break;
+        }
+    }
+
+    static final int arrayLenOffset = 8;
+    static void test0()
+    {
+        Object [] arr = new Object[13];
+        ObjectReference ref = ObjectReference.fromObject(arr);
+        Address addr = ref.toAddress();
+        Address lenAddr = addr.plus(arrayLenOffset);
+        int len = lenAddr.loadInt();
+        if (len != arr.length) 
+        {
+            throw new Error("length does not match");
+        }
+        System.out.println("test0 - ok");
+    }
+    static void test1()
+    {
+        Object [] arr = new Object[17];
+        ObjectReference ref = ObjectReference.fromObject(arr);
+        Address addr = ref.toAddress();
+        Offset off = Offset.fromIntSignExtend(arrayLenOffset);
+        int len = addr.loadInt(off);
+        if (len != arr.length) 
+        {
+            throw new Error("length does not match");
+        }
+        System.out.println("test1 - ok");
+    }
+
+    static void test2()
+    {
+        Object obj = new Object();
+        ObjectReference ref = ObjectReference.fromObject(obj);
+        ObjectReferenceArray arr = ObjectReferenceArray.create(1);
+        arr.set(0, ref);
+        if (arr.get(0) != ref) 
+        {
+            throw new Error("Invalid ref read");
+        }
+        try 
+        {
+            // Even though these are magics, can't allow to 
+            // write outside of array.
+            arr.set(10, ref);
+            // must not be here
+            throw new Error("Bounds check was not performed");
+        }
+        catch(ArrayIndexOutOfBoundsException e) 
+        {
+            // ok
+        }
+        System.out.println("test2 - ok");
+    }
+
+    static Object wbFldStatic = null;
+    Object  wbFldInstance = null;
+    static void testWB()
+    {
+        Object obj = new Object();
+        TestGenMS t = new TestGenMS();
+        Object[] array = new Object[10];
+        //
+        wbFldStatic = obj;
+        //
+        t.wbFldInstance = obj;
+        //
+        array[3] = obj;
+        //
+        System.out.println("testWB - seems ok");
+    }
+    static void singleRootTest()
+    {        
+        int [] ia = new int[10];
+        
+        ObjectReference orIa = ObjectReference.fromObject(ia);
+        Address addrIa = orIa.toAddress();
+        int vtblPtr = addrIa.loadInt();
+        Address addrLenIa = addrIa.plus(8);
+        int length = addrLenIa.loadInt();
+        if (length != 10) System.out.println("TestGenMS.java -- bad length -------------------" + length);
+
+        Address addrImmortalObj = TestGenMS.mc.alloc(52, 0, 0, Plan.ALLOC_IMMORTAL, 0);
+        addrImmortalObj.store(vtblPtr);
+        Address addrLenImmortal = addrImmortalObj.plus(8);
+        addrLenImmortal.store(length);
+  
+        Address addrImmortalObjElementZero = addrImmortalObj.plus(12); // stuff the _address_ of the root into element zero of the immortal array
+
+        Address addrLiveObj = mc.alloc(52, 0, 0, Plan.ALLOC_DEFAULT, 0);
+        addrLiveObj.store(vtblPtr);
+        Address addrLenLive = addrLiveObj.plus(8);
+        addrLenLive.store(length);
+
+        addrImmortalObjElementZero.store(addrLiveObj);  // stuff the _address_ of the array into an element to test enumeration
+        org.apache.HarmonyDRLVM.mm.mmtk.Scanning.addressOfTestRoot = addrImmortalObjElementZero.toInt();
+
+        System.out.println("addressOfTestRoot = " + Integer.toHexString(addrImmortalObjElementZero.toInt() ) );
+        System.out.println("the root itself is = " + Integer.toHexString(addrLiveObj.toInt()) );
+
+        for (int kk = 0;  kk < 5; kk++)
+        {
+            addrLiveObj = addrImmortalObjElementZero.loadAddress();
+            Address addrLiveElement3 = addrLiveObj.plus(12 + 3*4);
+            addrLiveElement3.store(kk);
+
+            for (int jj = 0; jj < 800000; jj++) 
+            {
+                Address addrDeadObj = mc.alloc(52, 0, 0, Plan.ALLOC_DEFAULT, 0);
+                addrDeadObj.store(vtblPtr);
+                Address addrLenDeadObj = addrDeadObj.plus(8);
+                addrLenDeadObj.store(length);
+            }
+
+            addrLiveObj = addrImmortalObjElementZero.loadAddress();
+            addrLiveElement3 = addrLiveObj.plus(12 + 3*4);
+            int xx = addrLiveElement3.loadInt();
+            if ( xx != kk  )
+                System.out.println("kk = " + kk + " element 3 = " + xx  );
+            System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ single root test, loop = " + kk + " OK");
+        }
+    }
+    static void linkListOfLiveObjectsTest()
+    {
+        Green gr = new Green();
+        ObjectReference orGr = ObjectReference.fromObject(gr);
+        Address addrGr = orGr.toAddress();
+        int vtblPtrGreen = addrGr.loadInt();
+
+        Address addrImmortalObj = TestGenMS.mc.alloc(52, 0, 0, Plan.ALLOC_IMMORTAL, 0);
+        addrImmortalObj.store(vtblPtrGreen);
+  
+        Address addrImmortalObjFieldZero = addrImmortalObj.plus(8); // stuff the _address_ of the root into element zero of the immortal array
+
+        Address addrLiveObj = mc.alloc(52, 0, 0, Plan.ALLOC_DEFAULT, 0);
+        addrLiveObj.store(vtblPtrGreen);
+
+        addrImmortalObjFieldZero.store(addrLiveObj);  // stuff the _address_ of the array into an element to test enumeration
+        org.apache.HarmonyDRLVM.mm.mmtk.Scanning.addressOfTestRoot = addrImmortalObjFieldZero.toInt();
+
+        System.out.println("addressOfTestRoot = " + Integer.toHexString(addrImmortalObjFieldZero.toInt() ) );
+        System.out.println("the root itself is = " + Integer.toHexString(addrLiveObj.toInt()) );
+
+        Object [] oa = new Object[10];
+        ObjectReference orOa = ObjectReference.fromObject(oa);
+        Address addrOa = orOa.toAddress();
+        int vtblPtrOa = addrOa.loadInt();
+        Address addrLenOa = addrOa.plus(8);
+        int lengthOa = addrLenOa.loadInt();
+        if (lengthOa != 10) System.out.println("TestGenMS.java -- bad length -------------------" + lengthOa);
+        Address addrLiveArray = mc.alloc(52, 0, 0, Plan.ALLOC_DEFAULT, 0);
+     
+        addrLiveArray.store(vtblPtrOa);
+        Address addrLiveArrayLen = addrLiveArray.plus(8);
+        addrLiveArrayLen.store(lengthOa);
+
+        ObjectReference orGreen = addrLiveObj.toObjectReference();
+        Green oldGreen = (Green)orGreen.toObject();
+        oldGreen.f8 = (Object [])addrLiveArray.toObjectReference().toObject();
+
+        Address addrLeafGreen = mc.alloc(52, 0, 0, Plan.ALLOC_DEFAULT, 0);
+        addrLeafGreen.store(vtblPtrGreen); 
+        oldGreen.f8[3] = addrLeafGreen.toObjectReference().toObject();
+
+        for (int kk = 0;  kk < 500; kk++)  //create 5K *52 = 250KB of live objects
+        {
+            Address addrNext = mc.alloc(52, 0, 0, Plan.ALLOC_DEFAULT, 0);
+            addrNext.store(vtblPtrGreen);
+            ObjectReference or2 = addrNext.toObjectReference();
+            Green newGreen = (Green)or2.toObject();
+            oldGreen.f1 = newGreen;
+            oldGreen.f6 = kk;
+            oldGreen = newGreen;
+        }
+
+        for (int jj = 0; jj < 150000; jj++) // generate lots of dead objects, cause lots of GCs
+        {
+            Address addrDeadObj = mc.alloc(52, 0, 0, Plan.ALLOC_DEFAULT, 0);
+            addrDeadObj.store(vtblPtrGreen);
+        }
+
+        addrLiveObj = addrImmortalObjFieldZero.loadAddress();  //reload the lead object
+        orGreen = addrLiveObj.toObjectReference();
+        Green greenCursor = (Green)orGreen.toObject();   //everything from base object should always be reachable
+
+        System.out.println("greenCursor.f8[3] = " + greenCursor.f8[3]);
+        System.out.println("greenCursor.f8[4] = " + greenCursor.f8[4]);
+
+        for (int rr = 0; rr < 500; rr++) 
+        {
+            if (greenCursor.f6 != rr) System.out.println("oldGreen.f6 = " + oldGreen.f6 + " rr = " + rr); //VM.assertions._assert(false);
+            greenCursor = greenCursor.f1; 
+        }
+        System.out.println("greenCursor = " + greenCursor);
+        System.out.println("linkListOfLiveObjectsTest, the live objects are still intact  OK");
+    }
+ 
+    static void linkListOfLiveObjectsTest2()
+    {
+        System.out.println("linkListOfLiveObjectsTest2, this test should fail real close to 1/2 the size of the java heap");
+        Green gr = new Green();
+        ObjectReference orGr = ObjectReference.fromObject(gr);
+        Address addrGr = orGr.toAddress();
+        int vtblPtrGreen = addrGr.loadInt();
+
+        Address addrImmortalObj = TestGenMS.mc.alloc(52, 0, 0, Plan.ALLOC_IMMORTAL, 0);
+        addrImmortalObj.store(vtblPtrGreen);
+  
+        Address addrImmortalObjFieldZero = addrImmortalObj.plus(8); // stuff the _address_ of the root into element zero of the immortal array
+
+        Address addrLiveObj = mc.alloc(52, 0, 0, Plan.ALLOC_DEFAULT, 0);
+        addrLiveObj.store(vtblPtrGreen);
+
+        addrImmortalObjFieldZero.store(addrLiveObj);  // stuff the _address_ of the array into an element to test enumeration
+        org.apache.HarmonyDRLVM.mm.mmtk.Scanning.addressOfTestRoot = addrImmortalObjFieldZero.toInt();
+
+        System.out.println("addressOfTestRoot = " + Integer.toHexString(addrImmortalObjFieldZero.toInt() ) );
+        System.out.println("the root itself is = " + Integer.toHexString(addrLiveObj.toInt()) );
+
+        ObjectReference orGreen = addrLiveObj.toObjectReference();
+        Green oldGreen = (Green)orGreen.toObject();
+
+        for (int kk = 0;  kk < 50000000; kk++)  //intentionally grab the entire heap
+        {
+            Address addrNext = mc.alloc(52, 0, 0, Plan.ALLOC_DEFAULT, 0);
+            addrNext.store(vtblPtrGreen);
+            ObjectReference or2 = addrNext.toObjectReference();
+            Green newGreen = (Green)or2.toObject();
+            oldGreen.f1 = newGreen;
+            oldGreen.f6 = kk;
+            oldGreen = newGreen;
+        }
+    }
+
+}

Added: incubator/harmony/enhanced/drlvm/trunk/vm/MMTk/TestMarkSweep.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/MMTk/TestMarkSweep.java?rev=439302&view=auto
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/MMTk/TestMarkSweep.java (added)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/MMTk/TestMarkSweep.java Fri Sep  1 05:57:56 2006
@@ -0,0 +1,374 @@
+/*
+ *  Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+import org.vmmagic.unboxed.*;
+import org.apache.HarmonyDRLVM.mm.mmtk.*;
+import org.mmtk.vm.*;
+import org.mmtk.plan.nogc.*;
+import org.mmtk.plan.Plan;
+import org.mmtk.plan.CollectorContext;
+import org.mmtk.utility.heap.LazyMmapper;
+import org.mmtk.plan.MutatorContext;
+import org.mmtk.plan.marksweep.MS;
+import org.mmtk.utility.options.*;
+import org.mmtk.utility.Log;
+import org.mmtk.utility.heap.*;
+
+public class TestMarkSweep 
+{
+    static MutatorContext mc;
+    static CollectorContext cc;
+    public static void main(String[] args) 
+    {
+        VM vm_init = new VM();
+        //NoGC pl2 = (NoGC)SelectedPlan.get();
+        MS pl2 = (MS)SelectedPlan.get();
+        Plan pl = SelectedPlan.ap.global();
+
+        pl2.boot();
+        pl.fullyBooted();
+        org.apache.HarmonyDRLVM.mm.mmtk.SynchronizedCounter.boot();
+        LazyMmapper.boot(Address.zero(), 0 );
+        HeapGrowthManager.boot(Extent.fromInt(1024*1024*1), Extent.fromInt(1024*1024*1) ); //set the java heap very small to force collections
+
+        TestMarkSweep.mc = SelectedPlan.ap.mutator();
+        TestMarkSweep.cc = SelectedPlan.ap.collector();
+
+
+        int xx = Integer.decode(args[0]);
+        switch (xx)
+        {
+            case 1:
+                test0();
+                test1();
+                test2();
+                testWB();             
+                break;
+            case 2:
+                singleRootTest();
+                break;
+            case 3:
+                linkListOfLiveObjectsTest();
+                break;
+            case 4:
+                linkListOfLiveObjectsTest2();
+                break;
+            case 5:
+                linkListOfArraysTest();
+                break;
+            default:
+                System.out.println("do nothing");
+                break;
+        }
+    }
+
+    static final int arrayLenOffset = 8;
+    static void test0()
+    {
+        Object [] arr = new Object[13];
+        ObjectReference ref = ObjectReference.fromObject(arr);
+        Address addr = ref.toAddress();
+        Address lenAddr = addr.plus(arrayLenOffset);
+        int len = lenAddr.loadInt();
+        if (len != arr.length) 
+        {
+            throw new Error("length does not match");
+        }
+        System.out.println("test0 - ok");
+    }
+    static void test1()
+    {
+        Object [] arr = new Object[17];
+        ObjectReference ref = ObjectReference.fromObject(arr);
+        Address addr = ref.toAddress();
+        Offset off = Offset.fromIntSignExtend(arrayLenOffset);
+        int len = addr.loadInt(off);
+        if (len != arr.length) 
+        {
+            throw new Error("length does not match");
+        }
+        System.out.println("test1 - ok");
+    }
+
+    static void test2()
+    {
+        Object obj = new Object();
+        ObjectReference ref = ObjectReference.fromObject(obj);
+        ObjectReferenceArray arr = ObjectReferenceArray.create(1);
+        arr.set(0, ref);
+        if (arr.get(0) != ref) 
+        {
+            throw new Error("Invalid ref read");
+        }
+        try 
+        {
+            // Even though these are magics, can't allow to 
+            // write outside of array.
+            arr.set(10, ref);
+            // must not be here
+            throw new Error("Bounds check was not performed");
+        }
+        catch(ArrayIndexOutOfBoundsException e) 
+        {
+            // ok
+        }
+        System.out.println("test2 - ok");
+    }
+
+    static Object wbFldStatic = null;
+    Object  wbFldInstance = null;
+    static void testWB()
+    {
+        Object obj = new Object();
+        TestMarkSweep t = new TestMarkSweep();
+        Object[] array = new Object[10];
+        //
+        wbFldStatic = obj;
+        //
+        t.wbFldInstance = obj;
+        //
+        array[3] = obj;
+        //
+        System.out.println("testWB - seems ok");
+    }
+    static void singleRootTest()
+    {        
+        Address addr = null;
+        int [] ia = new int[10];
+        
+        ObjectReference or = ObjectReference.fromObject(ia);
+        Address addr2 = or.toAddress();
+        int vtblPtr = addr2.loadInt();
+        Address addr3 = addr2.plus(8);
+        int length = addr3.loadInt();
+        if (length != 10) System.out.println("TestMarkSweep.java -- bad length -------------------" + length);
+        Address addrElementZero = null;
+
+        for (int kk = 10;  kk < 1000000; kk++)
+        {
+            addr = TestMarkSweep.mc.alloc(52, 0, 0, Plan.ALLOC_DEFAULT, 0);
+
+            addr.store(vtblPtr);
+            Address addrLen = addr.plus(8);
+            addrLen.store(length);
+            ObjectReference or2 = addr.toObjectReference();
+
+            Object obj2 = or2.toObject();
+
+            //System.out.println(obj2 + " " + obj2.hashCode() );
+        }
+        addrElementZero = addr.plus(12);
+        addrElementZero.store(addr);  // stuff the _address_ of the array into an element to test enumeration
+ 
+        org.apache.HarmonyDRLVM.mm.mmtk.Scanning.addressOfTestRoot = addrElementZero.toInt();
+        System.out.println("addressOfTestRoot = " + Integer.toHexString(addrElementZero.toInt() ) );
+        System.out.println("the root itself is = " + Integer.toHexString(addr.toInt()) );
+
+        or = addr.toObjectReference();
+         
+        ia = (int []) (or.toObject() );
+
+        for (int kk = 0;  kk < 5; kk++)
+        {
+            ia[3] = ia[4] = ia[5] = ia[6] = ia[7] = ia[8] = kk;
+            for (int jj = 0; jj < 800000; jj++) 
+            {
+                addr = mc.alloc(52, 0, 0, Plan.ALLOC_DEFAULT, 0);
+                addr.store(vtblPtr);
+                Address addrLen = addr.plus(8);
+                addrLen.store(length);
+                ObjectReference or2 = addr.toObjectReference();
+                Object obj2 = or2.toObject();
+            }
+            System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ single root test, loop = " + kk + " OK");
+            if ( (ia[3] != kk) | (ia[4] != kk) | (ia[5] != kk) | (ia[6] != kk) | (ia[7] != kk) | (ia[8] != kk)  )
+                VM.assertions._assert(false);
+        }
+    }
+    static void linkListOfLiveObjectsTest()
+    {
+        Green gr = new Green();
+        ObjectReference orx = ObjectReference.fromObject(gr);
+        Address addrx = orx.toAddress();
+        int vtblPtrGreen = addrx.loadInt();
+
+        Address addrBaseObject = TestMarkSweep.mc.alloc(52, 0, 0, Plan.ALLOC_DEFAULT, 0);
+
+        addrBaseObject.store(vtblPtrGreen);
+ 
+        Address addrGreenFieldZero = addrBaseObject.plus(8);
+        addrGreenFieldZero.store(addrBaseObject);  // stuff the _address_ of the array into field zero to test enumeration
+        org.apache.HarmonyDRLVM.mm.mmtk.Scanning.addressOfTestRoot = addrGreenFieldZero.toInt();
+
+        System.out.println("addressOfTestRoot = " + Integer.toHexString(addrGreenFieldZero.toInt() ) );
+        System.out.println("the root itself is = " + Integer.toHexString(addrBaseObject.toInt()) );
+
+        ObjectReference orBaseObject = addrBaseObject.toObjectReference();         
+        Green oldGreen = (Green)(orBaseObject.toObject() );  //everything from base object should always be reachable
+
+        for (int kk = 0;  kk < 5000; kk++)  //create 5K *52 = 250KB of live objects
+        {
+            Address addrNext = mc.alloc(52, 0, 0, Plan.ALLOC_DEFAULT, 0);
+            addrNext.store(vtblPtrGreen);
+            ObjectReference or2 = addrNext.toObjectReference();
+            Green newGreen = (Green)or2.toObject();
+            oldGreen.f1 = newGreen;
+            oldGreen.f6 = kk;
+            oldGreen = newGreen;
+        }
+
+        oldGreen = null;  // don't let gcv4 see these ref ptrs!
+        System.out.println("linkListOfLiveObjectsTest, allocated 250KB worth of live objects");
+
+        for (int zz = 0; zz < 10; zz++) //allocate a bunch of objects, throw them away to force collections
+        {
+            for (int kk = 0;  kk < 20000; kk++)
+            {
+                Address addr4 = mc.alloc(52, 0, 0, Plan.ALLOC_DEFAULT, 0);
+                addr4.store(vtblPtrGreen);
+            }
+            //System.out.println("linkListOfLiveObjectsTest, allocated and discarded " + zz + "x100KB");
+        }
+        //check if the 50KB of linked objects are still intact       
+
+        oldGreen = (Green)(orBaseObject.toObject() );  //everything from base object should always be reachable
+        for (int rr = 0; rr < 1000; rr++) 
+        {
+            if (oldGreen.f6 != rr) System.out.println("oldGreen.f6 = " + oldGreen.f6 + " rr = " + rr); //VM.assertions._assert(false);
+            oldGreen = oldGreen.f1; 
+        }
+        System.out.println("linkListOfLiveObjectsTest, the live objects are still intact  OK");
+    }
+ 
+    static void linkListOfLiveObjectsTest2()
+    {
+        Green gr = new Green();
+        ObjectReference or = ObjectReference.fromObject(gr);
+        Address addr2 = or.toAddress();
+        int vtblPtr = addr2.loadInt();
+
+        Address addr = TestMarkSweep.mc.alloc(52, 0, 0, Plan.ALLOC_DEFAULT, 0);
+
+        addr.store(vtblPtr);
+ 
+        Address addrFieldZero = addr.plus(8);
+        addrFieldZero.store(addr);  // stuff the _address_ of the array into field zero to test enumeration
+        org.apache.HarmonyDRLVM.mm.mmtk.Scanning.addressOfTestRoot = addrFieldZero.toInt();
+
+        //System.out.println("addressOfTestRoot = " + Integer.toHexString(addrFieldZero.toInt() ) );
+        //System.out.println("the root itself is = " + Integer.toHexString(addr.toInt()) );
+
+        or = addr.toObjectReference();         
+        Green baseGreen = (Green)(or.toObject() );  //everything from baseGreen should always be reachable
+        Green oldGreen = baseGreen;  
+
+        System.out.println("linkListOfLiveObjectsTest2, this test should fail real close to the size of the java heap");
+
+        for (int zz = 0; zz < 10; zz++)
+        {
+            for (int kk = 0;  kk < 2000; kk++)
+            {
+                addr = mc.alloc(52, 0, 0, Plan.ALLOC_DEFAULT, 0);
+                addr.store(vtblPtr);
+                ObjectReference or2 = addr.toObjectReference();
+                Green newGreen = (Green)or2.toObject();
+                oldGreen.f1 = newGreen;
+                oldGreen = newGreen;
+            }
+            System.out.println("linkListOfLiveObjectsTest2, allocated and retaining " + zz + "x100KB");
+        }
+    }
+
+    static void linkListOfArraysTest()
+    {
+        Green gr = new Green();
+        ObjectReference orx = ObjectReference.fromObject(gr);
+        Address addrx = orx.toAddress();
+        int vtblPtrGreen = addrx.loadInt();
+
+        Address addrBaseObject = TestMarkSweep.mc.alloc(52, 0, 0, Plan.ALLOC_DEFAULT, 0);
+
+        addrBaseObject.store(vtblPtrGreen);
+ 
+        Address addrGreenFieldZero = addrBaseObject.plus(8);
+        addrGreenFieldZero.store(addrBaseObject);  // stuff the _address_ of the array into field zero to test enumeration
+        org.apache.HarmonyDRLVM.mm.mmtk.Scanning.addressOfTestRoot = addrGreenFieldZero.toInt();
+
+        System.out.println("addressOfTestRoot = " + Integer.toHexString(addrGreenFieldZero.toInt() ) );
+        System.out.println("the root itself is = " + Integer.toHexString(addrBaseObject.toInt()) );
+
+        ObjectReference orBaseObject = addrBaseObject.toObjectReference();         
+        Green oldGreen = (Green)(orBaseObject.toObject() );  //everything from base object should always be reachable
+
+        for (int kk = 0;  kk < 5000; kk++)  //create 5K *52 = 250KB of live objects
+        {
+            Address addrNext = mc.alloc(52, 0, 0, Plan.ALLOC_DEFAULT, 0);
+            addrNext.store(vtblPtrGreen);
+            ObjectReference or2 = addrNext.toObjectReference();
+            Green newGreen = (Green)or2.toObject();
+            oldGreen.f1 = newGreen;
+            oldGreen.f6 = kk;
+            oldGreen = newGreen;
+        }
+
+        Object oaq [] = new Object[10];        
+        ObjectReference orq = ObjectReference.fromObject(oaq);
+        Address addrq = orq.toAddress();
+        oaq = null;  //aggressively null out unused objects (to keep gcv4 from finding them!)
+        orq = null;
+
+        //allocate one array of objects and link onto the first green
+        int vtblPtrOA = addrq.loadInt();
+        Address addrLen = addrq.plus(8);
+        int length = addrLen.loadInt();
+        if (length != 10) System.out.println("test.java -- bad length -------------------" + length);
+
+        Address addrOA = TestMarkSweep.mc.alloc(52, 0, 0, Plan.ALLOC_DEFAULT, 0);
+        addrOA.store(vtblPtrOA);
+        Address addrOALen = addrOA.plus(8);
+        addrOALen.store(length);
+
+        oldGreen = (Green)(orBaseObject.toObject() );
+        oldGreen.f8 = (Object []) addrOA.toObjectReference().toObject();
+        System.out.println("linkListOfLiveObjectsTest, allocated 250KB worth of live objects");
+        //stuff an object in the array at index 5 (or 12 + 5*4 offset from ref ptr)
+        Address addrElement5 = addrOA.plus(32);
+        addrElement5.store(addrBaseObject.toInt() );
+
+        oldGreen = null;  // don't let gcv4 see these ref ptrs!
+
+        for (int zz = 0; zz < 10; zz++) //allocate a bunch of objects, throw them away to force collections
+        {
+            for (int kk = 0;  kk < 30000; kk++)
+            {
+                Address addr4 = mc.alloc(52, 0, 0, Plan.ALLOC_DEFAULT, 0);
+                addr4.store(vtblPtrGreen);
+            }
+            //System.out.println("linkListOfLiveObjectsTest, allocated and discarded " + zz + "x100KB");
+        }
+        //check if the 50KB of linked objects are still intact       
+
+        oldGreen = (Green)(orBaseObject.toObject() );  //everything from base object should always be reachable
+               System.out.println("oldGreen.f8 = " + oldGreen.f8);
+               System.out.println("oldGreen.f8[5] = " + oldGreen.f8[5]);
+        for (int rr = 0; rr < 1000; rr++) 
+        {
+            if (oldGreen.f6 != rr) System.out.println("oldGreen.f6 = " + oldGreen.f6 + " rr = " + rr); //VM.assertions._assert(false);
+            oldGreen = oldGreen.f1; 
+        }
+        System.out.println("linkListOfArraysTest() is OK");
+    }
+}

Added: incubator/harmony/enhanced/drlvm/trunk/vm/MMTk/TestSemiSpace.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/MMTk/TestSemiSpace.java?rev=439302&view=auto
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/MMTk/TestSemiSpace.java (added)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/MMTk/TestSemiSpace.java Fri Sep  1 05:57:56 2006
@@ -0,0 +1,312 @@
+/*
+ *  Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+import org.vmmagic.unboxed.*;
+import org.apache.HarmonyDRLVM.mm.mmtk.*;
+import org.mmtk.vm.*;
+import org.mmtk.plan.Plan;
+import org.mmtk.plan.CollectorContext;
+import org.mmtk.utility.heap.LazyMmapper;
+import org.mmtk.plan.MutatorContext;
+////////////import org.mmtk.plan.marksweep.MS;
+//////////import org.mmtk.plan.nogc.*;
+import org.mmtk.plan.semispace.SS;
+import org.mmtk.utility.options.*;
+import org.mmtk.utility.Log;
+import org.mmtk.utility.heap.*;
+
+public class TestSemiSpace 
+{
+    static MutatorContext mc;
+    static CollectorContext cc;
+    public static void main(String[] args) 
+    {
+        VM vm_init = new VM();
+        //NoGC pl2 = (NoGC)SelectedPlan.get();
+        //MS pl2 = (MS)SelectedPlan.get();
+        SS pl2 = (SS)SelectedPlan.get();
+        Plan pl = SelectedPlan.ap.global();
+
+        pl2.boot();
+        pl.fullyBooted();
+        org.apache.HarmonyDRLVM.mm.mmtk.SynchronizedCounter.boot();
+        LazyMmapper.boot(Address.zero(), 0 );
+        HeapGrowthManager.boot(Extent.fromInt(1024*1024*1), Extent.fromInt(1024*1024*1) ); //set the java heap very small to force collections
+
+        TestSemiSpace.mc = SelectedPlan.ap.mutator();
+        TestSemiSpace.cc = SelectedPlan.ap.collector();
+
+        //System.out.println("TestSemiSpace SS.copySpace0.getName() = " + SS.copySpace0.getName() );
+        //System.out.println("TestSemiSpace SS.copySpace1.getName() = " + SS.copySpace1.getName() );
+
+
+        int xx = Integer.decode(args[0]);
+        switch (xx)
+        {
+            case 1:
+                test0();
+                test1();
+                test2();
+                testWB();             
+                break;
+            case 2:
+                singleRootTest();
+                break;
+            case 3:
+                linkListOfLiveObjectsTest();
+                break;
+            case 4:
+                linkListOfLiveObjectsTest2();
+                break;
+            default:
+                System.out.println("******************** do nothing, invalid test number  ***********************");
+                break;
+        }
+    }
+
+    static final int arrayLenOffset = 8;
+    static void test0()
+    {
+        Object [] arr = new Object[13];
+        ObjectReference ref = ObjectReference.fromObject(arr);
+        Address addr = ref.toAddress();
+        Address lenAddr = addr.plus(arrayLenOffset);
+        int len = lenAddr.loadInt();
+        if (len != arr.length) 
+        {
+            throw new Error("length does not match");
+        }
+        System.out.println("test0 - ok");
+    }
+    static void test1()
+    {
+        Object [] arr = new Object[17];
+        ObjectReference ref = ObjectReference.fromObject(arr);
+        Address addr = ref.toAddress();
+        Offset off = Offset.fromIntSignExtend(arrayLenOffset);
+        int len = addr.loadInt(off);
+        if (len != arr.length) 
+        {
+            throw new Error("length does not match");
+        }
+        System.out.println("test1 - ok");
+    }
+
+    static void test2()
+    {
+        Object obj = new Object();
+        ObjectReference ref = ObjectReference.fromObject(obj);
+        ObjectReferenceArray arr = ObjectReferenceArray.create(1);
+        arr.set(0, ref);
+        if (arr.get(0) != ref) 
+        {
+            throw new Error("Invalid ref read");
+        }
+        try 
+        {
+            // Even though these are magics, can't allow to 
+            // write outside of array.
+            arr.set(10, ref);
+            // must not be here
+            throw new Error("Bounds check was not performed");
+        }
+        catch(ArrayIndexOutOfBoundsException e) 
+        {
+            // ok
+        }
+        System.out.println("test2 - ok");
+    }
+
+    static Object wbFldStatic = null;
+    Object  wbFldInstance = null;
+    static void testWB()
+    {
+        Object obj = new Object();
+        TestSemiSpace t = new TestSemiSpace();
+        Object[] array = new Object[10];
+        //
+        wbFldStatic = obj;
+        //
+        t.wbFldInstance = obj;
+        //
+        array[3] = obj;
+        //
+        System.out.println("testWB - seems ok");
+    }
+    static void singleRootTest()
+    {        
+        int [] ia = new int[10];
+        
+        ObjectReference orIa = ObjectReference.fromObject(ia);
+        Address addrIa = orIa.toAddress();
+        int vtblPtr = addrIa.loadInt();
+        Address addrLenIa = addrIa.plus(8);
+        int length = addrLenIa.loadInt();
+        if (length != 10) System.out.println("TestSemiSpace.java -- bad length -------------------" + length);
+
+        Address addrImmortalObj = TestSemiSpace.mc.alloc(52, 0, 0, Plan.ALLOC_IMMORTAL, 0);
+        addrImmortalObj.store(vtblPtr);
+        Address addrLenImmortal = addrImmortalObj.plus(8);
+        addrLenImmortal.store(length);
+  
+        Address addrImmortalObjElementZero = addrImmortalObj.plus(12); // stuff the _address_ of the root into element zero of the immortal array
+
+        Address addrLiveObj = mc.alloc(52, 0, 0, Plan.ALLOC_DEFAULT, 0);
+        addrLiveObj.store(vtblPtr);
+        Address addrLenLive = addrLiveObj.plus(8);
+        addrLenLive.store(length);
+
+        addrImmortalObjElementZero.store(addrLiveObj);  // stuff the _address_ of the array into an element to test enumeration
+        org.apache.HarmonyDRLVM.mm.mmtk.Scanning.addressOfTestRoot = addrImmortalObjElementZero.toInt();
+
+        System.out.println("addressOfTestRoot = " + Integer.toHexString(addrImmortalObjElementZero.toInt() ) );
+        System.out.println("the root itself is = " + Integer.toHexString(addrLiveObj.toInt()) );
+
+        for (int kk = 0;  kk < 5; kk++)
+        {
+            addrLiveObj = addrImmortalObjElementZero.loadAddress();
+            Address addrLiveElement3 = addrLiveObj.plus(12 + 3*4);
+            addrLiveElement3.store(kk);
+
+            for (int jj = 0; jj < 800000; jj++) 
+            {
+                Address addrDeadObj = mc.alloc(52, 0, 0, Plan.ALLOC_DEFAULT, 0);
+                addrDeadObj.store(vtblPtr);
+                Address addrLenDeadObj = addrDeadObj.plus(8);
+                addrLenDeadObj.store(length);
+            }
+
+            addrLiveObj = addrImmortalObjElementZero.loadAddress();
+            addrLiveElement3 = addrLiveObj.plus(12 + 3*4);
+            int xx = addrLiveElement3.loadInt();
+            if ( xx != kk  )
+                System.out.println("kk = " + kk + " element 3 = " + xx  );
+            System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ single root test, loop = " + kk + " OK");
+        }
+    }
+    static void linkListOfLiveObjectsTest()
+    {
+        Green gr = new Green();
+        ObjectReference orGr = ObjectReference.fromObject(gr);
+        Address addrGr = orGr.toAddress();
+        int vtblPtrGreen = addrGr.loadInt();
+
+        Address addrImmortalObj = TestSemiSpace.mc.alloc(52, 0, 0, Plan.ALLOC_IMMORTAL, 0);
+        addrImmortalObj.store(vtblPtrGreen);
+  
+        Address addrImmortalObjFieldZero = addrImmortalObj.plus(8); // stuff the _address_ of the root into element zero of the immortal array
+
+        Address addrLiveObj = mc.alloc(52, 0, 0, Plan.ALLOC_DEFAULT, 0);
+        addrLiveObj.store(vtblPtrGreen);
+
+        addrImmortalObjFieldZero.store(addrLiveObj);  // stuff the _address_ of the array into an element to test enumeration
+        org.apache.HarmonyDRLVM.mm.mmtk.Scanning.addressOfTestRoot = addrImmortalObjFieldZero.toInt();
+
+        System.out.println("addressOfTestRoot = " + Integer.toHexString(addrImmortalObjFieldZero.toInt() ) );
+        System.out.println("the root itself is = " + Integer.toHexString(addrLiveObj.toInt()) );
+
+        Object [] oa = new Object[10];
+        ObjectReference orOa = ObjectReference.fromObject(oa);
+        Address addrOa = orOa.toAddress();
+        int vtblPtrOa = addrOa.loadInt();
+        Address addrLenOa = addrOa.plus(8);
+        int lengthOa = addrLenOa.loadInt();
+        if (lengthOa != 10) System.out.println("TestSemiSpace.java -- bad length -------------------" + lengthOa);
+        Address addrLiveArray = mc.alloc(52, 0, 0, Plan.ALLOC_DEFAULT, 0);
+     
+        addrLiveArray.store(vtblPtrOa);
+        Address addrLiveArrayLen = addrLiveArray.plus(8);
+        addrLiveArrayLen.store(lengthOa);
+
+        ObjectReference orGreen = addrLiveObj.toObjectReference();
+        Green oldGreen = (Green)orGreen.toObject();
+        oldGreen.f8 = (Object [])addrLiveArray.toObjectReference().toObject();
+
+        Address addrLeafGreen = mc.alloc(52, 0, 0, Plan.ALLOC_DEFAULT, 0);
+        addrLeafGreen.store(vtblPtrGreen); 
+        oldGreen.f8[3] = addrLeafGreen.toObjectReference().toObject();
+
+        for (int kk = 0;  kk < 500; kk++)  //create 5K *52 = 250KB of live objects
+        {
+            Address addrNext = mc.alloc(52, 0, 0, Plan.ALLOC_DEFAULT, 0);
+            addrNext.store(vtblPtrGreen);
+            ObjectReference or2 = addrNext.toObjectReference();
+            Green newGreen = (Green)or2.toObject();
+            oldGreen.f1 = newGreen;
+            oldGreen.f6 = kk;
+            oldGreen = newGreen;
+        }
+
+        for (int jj = 0; jj < 150000; jj++) // generate lots of dead objects, cause lots of GCs
+        {
+            Address addrDeadObj = mc.alloc(52, 0, 0, Plan.ALLOC_DEFAULT, 0);
+            addrDeadObj.store(vtblPtrGreen);
+        }
+
+        addrLiveObj = addrImmortalObjFieldZero.loadAddress();  //reload the lead object
+        orGreen = addrLiveObj.toObjectReference();
+        Green greenCursor = (Green)orGreen.toObject();   //everything from base object should always be reachable
+
+        System.out.println("greenCursor.f8[3] = " + greenCursor.f8[3]);
+        System.out.println("greenCursor.f8[4] = " + greenCursor.f8[4]);
+
+        for (int rr = 0; rr < 500; rr++) 
+        {
+            if (greenCursor.f6 != rr) System.out.println("oldGreen.f6 = " + oldGreen.f6 + " rr = " + rr); //VM.assertions._assert(false);
+            greenCursor = greenCursor.f1; 
+        }
+        System.out.println("greenCursor = " + greenCursor);
+        System.out.println("linkListOfLiveObjectsTest, the live objects are still intact  OK");
+    }
+ 
+    static void linkListOfLiveObjectsTest2()
+    {
+        System.out.println("linkListOfLiveObjectsTest2, this test should fail real close to 1/2 the size of the java heap");
+        Green gr = new Green();
+        ObjectReference orGr = ObjectReference.fromObject(gr);
+        Address addrGr = orGr.toAddress();
+        int vtblPtrGreen = addrGr.loadInt();
+
+        Address addrImmortalObj = TestSemiSpace.mc.alloc(52, 0, 0, Plan.ALLOC_IMMORTAL, 0);
+        addrImmortalObj.store(vtblPtrGreen);
+  
+        Address addrImmortalObjFieldZero = addrImmortalObj.plus(8); // stuff the _address_ of the root into element zero of the immortal array
+
+        Address addrLiveObj = mc.alloc(52, 0, 0, Plan.ALLOC_DEFAULT, 0);
+        addrLiveObj.store(vtblPtrGreen);
+
+        addrImmortalObjFieldZero.store(addrLiveObj);  // stuff the _address_ of the array into an element to test enumeration
+        org.apache.HarmonyDRLVM.mm.mmtk.Scanning.addressOfTestRoot = addrImmortalObjFieldZero.toInt();
+
+        System.out.println("addressOfTestRoot = " + Integer.toHexString(addrImmortalObjFieldZero.toInt() ) );
+        System.out.println("the root itself is = " + Integer.toHexString(addrLiveObj.toInt()) );
+
+        ObjectReference orGreen = addrLiveObj.toObjectReference();
+        Green oldGreen = (Green)orGreen.toObject();
+
+        for (int kk = 0;  kk < 50000000; kk++)  //intentionally grab the entire heap
+        {
+            Address addrNext = mc.alloc(52, 0, 0, Plan.ALLOC_DEFAULT, 0);
+            addrNext.store(vtblPtrGreen);
+            ObjectReference or2 = addrNext.toObjectReference();
+            Green newGreen = (Green)or2.toObject();
+            oldGreen.f1 = newGreen;
+            oldGreen.f6 = kk;
+            oldGreen = newGreen;
+        }
+    }
+
+}

Added: incubator/harmony/enhanced/drlvm/trunk/vm/MMTk/docopyms.bat
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/MMTk/docopyms.bat?rev=439302&view=auto
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/MMTk/docopyms.bat (added)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/MMTk/docopyms.bat Fri Sep  1 05:57:56 2006
@@ -0,0 +1,4 @@
+@echo off
+
+
+c:\t_harmony\drlvm\trunk\build\win_ia32_msvc_debug\deploy\jre\bin\java.exe -Xbootclasspath/p:.;mmtk.jar -Xem jet: -Xjit jet::wb4j -Xms512m -Xms512m TestCopyMS %1 

Added: incubator/harmony/enhanced/drlvm/trunk/vm/MMTk/dogenms.bat
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/MMTk/dogenms.bat?rev=439302&view=auto
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/MMTk/dogenms.bat (added)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/MMTk/dogenms.bat Fri Sep  1 05:57:56 2006
@@ -0,0 +1,4 @@
+@echo off
+
+
+c:\t_harmony\drlvm\trunk\build\win_ia32_msvc_debug\deploy\jre\bin\java.exe -Xbootclasspath/p:.;mmtk.jar -Xem jet: -Xjit jet::wb4j -Xms512m -Xms512m TestGenMS %1 

Added: incubator/harmony/enhanced/drlvm/trunk/vm/MMTk/doss.bat
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/MMTk/doss.bat?rev=439302&view=auto
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/MMTk/doss.bat (added)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/MMTk/doss.bat Fri Sep  1 05:57:56 2006
@@ -0,0 +1,4 @@
+@echo off
+
+
+c:\t_harmony\drlvm\trunk\build\win_ia32_msvc_debug\deploy\jre\bin\java.exe -Xbootclasspath/p:.;mmtk.jar -Xem jet: -Xjit jet::wb4j -Xms512m -Xms512m TestSemiSpace %1 

Added: incubator/harmony/enhanced/drlvm/trunk/vm/MMTk/dovmmagic.bat
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/MMTk/dovmmagic.bat?rev=439302&view=auto
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/MMTk/dovmmagic.bat (added)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/MMTk/dovmmagic.bat Fri Sep  1 05:57:56 2006
@@ -0,0 +1,13 @@
+@echo off
+
+
+    c:\t_harmony\drlvm\trunk\build\win_ia32_msvc_debug\deploy\jre\bin\java.exe -Xbootclasspath/p:.;mmtk.jar;junit-4.1.jar -Xem jet: org.vmmagic.unboxed.AddressTest
+    
+    c:\t_harmony\drlvm\trunk\build\win_ia32_msvc_debug\deploy\jre\bin\java.exe -Xbootclasspath/p:.;mmtk.jar;junit-4.1.jar -Xem jet: org.vmmagic.unboxed.ExtentTest
+	
+    c:\t_harmony\drlvm\trunk\build\win_ia32_msvc_debug\deploy\jre\bin\java.exe -Xbootclasspath/p:.;mmtk.jar;junit-4.1.jar -Xem jet: org.vmmagic.unboxed.OffsetTest
+
+    c:\t_harmony\drlvm\trunk\build\win_ia32_msvc_debug\deploy\jre\bin\java.exe -Xbootclasspath/p:.;mmtk.jar;junit-4.1.jar -Xem jet: org.vmmagic.unboxed.WordTest
+
+    c:\t_harmony\drlvm\trunk\build\win_ia32_msvc_debug\deploy\jre\bin\java.exe -Xbootclasspath/p:.;mmtk.jar;junit-4.1.jar -Xem jet: org.vmmagic.unboxed.ObjectReferenceTest
+



Mime
View raw message