You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by va...@apache.org on 2007/02/07 14:19:33 UTC

svn commit: r504538 - in /harmony/enhanced/drlvm/trunk: src/test/regression/H3121/ vm/em/src/ vm/jitrino/src/dynopt/ vm/jitrino/src/optimizer/

Author: varlax
Date: Wed Feb  7 05:19:33 2007
New Revision: 504538

URL: http://svn.apache.org/viewvc?view=rev&rev=504538
Log:
Applied HARMONY-3121 [drlvm][jit][opt] Dacapo.eclipse crashes on the second iteration in -Xem:server mode.
Tested on SUSE10 ia32

Added:
    harmony/enhanced/drlvm/trunk/src/test/regression/H3121/
    harmony/enhanced/drlvm/trunk/src/test/regression/H3121/H3121.java
    harmony/enhanced/drlvm/trunk/src/test/regression/H3121/run.test.xml
Modified:
    harmony/enhanced/drlvm/trunk/vm/em/src/NValueProfileCollector.cpp
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/dynopt/ValueProfiler.cpp
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/devirtualizer.cpp
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/devirtualizer.h

Added: harmony/enhanced/drlvm/trunk/src/test/regression/H3121/H3121.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/H3121/H3121.java?view=auto&rev=504538
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/H3121/H3121.java (added)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/H3121/H3121.java Wed Feb  7 05:19:33 2007
@@ -0,0 +1,39 @@
+package org.apache.harmony.drlvm.tests.regression.h3121;
+
+import junit.framework.TestCase;
+
+
+/*  The test checks that the JIT correctly optimizes virtual calls
+ *  when the receiver is of interface type. Loops are needed to force
+ *  JIT recompilation. The method vc() contains both an interface call
+ *  and a virtual call, an attempt to devirtualize a virtual call caused
+ *  segfault in the ValueProfileCollector (Harmony-3121 issue).
+ */
+public class H3121 extends TestCase {
+
+    Intf io = new IntfClass(); 
+    Object o = new Object();
+
+    public void test() {
+	boolean b = false;
+        for (int i = 0; i < 10000000; i++) {
+            b = vc();
+        }
+        System.out.println("Test passed");
+    }
+
+    public boolean vc() {
+        io.fake();
+	return io.equals(o);
+    }
+}
+ 
+interface Intf {
+    public void fake();
+}
+
+class IntfClass implements Intf {
+    public void fake() {
+        for (int i = 0; i < 100; i++) {}
+    }
+}

Added: harmony/enhanced/drlvm/trunk/src/test/regression/H3121/run.test.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/H3121/run.test.xml?view=auto&rev=504538
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/H3121/run.test.xml (added)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/H3121/run.test.xml Wed Feb  7 05:19:33 2007
@@ -0,0 +1,8 @@
+<project name="RUN HARMONY-3121 Regression Test">
+  <target name="run-test">
+    <run-junit-test 
+        test="org.apache.harmony.drlvm.tests.regression.h3121.H3121"
+        vmarg="-Xem:server">
+    </run-junit-test>
+  </target>
+</project>

Modified: harmony/enhanced/drlvm/trunk/vm/em/src/NValueProfileCollector.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/em/src/NValueProfileCollector.cpp?view=diff&rev=504538&r1=504537&r2=504538
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/em/src/NValueProfileCollector.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/em/src/NValueProfileCollector.cpp Wed Feb  7 05:19:33 2007
@@ -239,8 +239,13 @@
 {
     lockProfile();
     VPInstructionProfileData* _temp_vp = ValueMap[instructionKey];
+    if (_temp_vp == NULL) {
+        assert(0);
+        unlockProfile();
+        return 0;
+    }
     flushInstProfile(_temp_vp);
-    POINTER_SIZE_INT result = (_temp_vp == NULL) ? 0 : getVPC()->find_max(_temp_vp->TNV_Table);
+    POINTER_SIZE_INT result = getVPC()->find_max(_temp_vp->TNV_Table);
     unlockProfile();
     return result; 
 }

Modified: harmony/enhanced/drlvm/trunk/vm/jitrino/src/dynopt/ValueProfiler.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/jitrino/src/dynopt/ValueProfiler.cpp?view=diff&rev=504538&r1=504537&r2=504538
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/jitrino/src/dynopt/ValueProfiler.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/jitrino/src/dynopt/ValueProfiler.cpp Wed Feb  7 05:19:33 2007
@@ -59,7 +59,8 @@
             Opnd* tauNullChecked = NULL;
             Opnd* tauTypesChecked = NULL;
             uint32 argOffset = 0;
-            if(Devirtualizer::isGuardableVirtualCall(lastInst, methodInst, base, tauNullChecked, tauTypesChecked, argOffset)) {
+            bool isIntfCall = false;
+            if(Devirtualizer::isGuardableVirtualCall(lastInst, methodInst, base, tauNullChecked, tauTypesChecked, argOffset, isIntfCall)) {
                 assert(methodInst && base && tauNullChecked && tauTypesChecked && argOffset);
                 assert(base->getType()->isObject());
 
@@ -75,17 +76,7 @@
                 }
 
                 Inst* vtableInst = methodInst->getSrc(0)->getInst();
-                Opcode vtableInstOpcode = vtableInst->getOpcode();
-                if (vtableInstOpcode == Op_TauLdVTableAddr) {
-                    // That is what we are looking for
-                    if (debug) {
-                        Log::out() << "\tFound ldVTable instruction to instrument: ";
-                        vtableInst->print(Log::out());
-                        Log::out() << std::endl;
-                    }
-                    // Don't profile virtual calls so far
-                    continue;
-                } else if (vtableInstOpcode == Op_TauLdIntfcVTableAddr) {
+                if (isIntfCall) {
                     // Need to generate VTable loading
                     Opnd* vTable = opndManager.createSsaTmpOpnd(typeManager.getVTablePtrType(typeManager.getSystemObjectType()));
                     Inst* ldVtableInst = instFactory.makeTauLdVTableAddr(vTable, base, tauNullChecked);
@@ -97,6 +88,13 @@
                         Log::out() << std::endl;
                     }
                 } else {
+                    // That is what we are looking for
+                    if (debug) {
+                        Log::out() << "\tFound ldVTable instruction to instrument: ";
+                        vtableInst->print(Log::out());
+                        Log::out() << std::endl;
+                    }
+                    // Don't profile virtual calls so far
                     continue;
                 }
                 VectorHandler* bc2HIRMapHandler = new VectorHandler(bcOffset2HIRHandlerName, &md);

Modified: harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/devirtualizer.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/devirtualizer.cpp?view=diff&rev=504538&r1=504537&r2=504538
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/devirtualizer.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/devirtualizer.cpp Wed Feb  7 05:19:33 2007
@@ -69,7 +69,7 @@
 }
 
 bool
-Devirtualizer::isGuardableVirtualCall(Inst* inst, MethodInst*& methodInst, Opnd*& base, Opnd*& tauNullChecked, Opnd *&tauTypesChecked, uint32 &argOffset)
+Devirtualizer::isGuardableVirtualCall(Inst* inst, MethodInst*& methodInst, Opnd*& base, Opnd*& tauNullChecked, Opnd *&tauTypesChecked, uint32 &argOffset, bool &isIntfCall)
 {
     //
     // Returns true if this call site may be considered for guarded devirtualization
@@ -120,10 +120,14 @@
             (methodOpcode == Op_TauLdVirtFunAddr)) {
             Inst *vtableInst = methodSrc0->getInst();
             Opcode vtableInstOpcode = vtableInst->getOpcode();
-            if ((vtableInstOpcode == Op_TauLdVTableAddr) ||
-                (vtableInstOpcode == Op_TauLdIntfcVTableAddr)) {
+            if (vtableInstOpcode == Op_TauLdVTableAddr) {
+                isIntfCall = false;
+            } else if (vtableInstOpcode == Op_TauLdIntfcVTableAddr) {
+                isIntfCall = true;
             } else {
-                // must be a copy or something, too hard to check
+                // Need a real example when this assertion fires
+                // This can be handled with copy propagation
+                assert(0);
             }
         } else {
             assert(base == methodInst->getSrc(0));
@@ -404,17 +408,17 @@
         Opnd* tauNullChecked = 0;
         Opnd* tauTypesChecked = 0;
         uint32 argOffset = 0;
-        if(isGuardableVirtualCall(last, methodInst, base, tauNullChecked, tauTypesChecked, argOffset)) {
+        bool isIntfCall = false;
+        if(isGuardableVirtualCall(last, methodInst, base, tauNullChecked, tauTypesChecked, argOffset, isIntfCall)) {
             assert(methodInst && base && tauNullChecked && tauTypesChecked && argOffset);
 
             assert(base->getType()->isObject());
             ObjectType* baseType = (ObjectType*) base->getType();
-            bool intfCall = baseType->isInterface();
-            if (! ((_devirtInterfaceCalls && intfCall) || (_devirtVirtualCalls && !intfCall))) {
+            if (! ((_devirtInterfaceCalls && isIntfCall) || (_devirtVirtualCalls && !isIntfCall))) {
                 return;
             }
             // If base type is concrete, consider an explicit guarded test against it
-            if(!baseType->isNullObject() && ((_devirtInterfaceCalls && intfCall) || !baseType->isAbstract() || baseType->isArray())) {
+            if(!baseType->isNullObject() && ((_devirtInterfaceCalls && isIntfCall) || !baseType->isAbstract() || baseType->isArray())) {
                 MethodDesc* origMethodDesc = methodInst->getMethodDesc();
                 MethodDesc* candidateMeth = NULL;
                 int candidateExecCount = 0;

Modified: harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/devirtualizer.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/devirtualizer.h?view=diff&rev=504538&r1=504537&r2=504538
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/devirtualizer.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/devirtualizer.h Wed Feb  7 05:19:33 2007
@@ -38,7 +38,7 @@
     void unguardCallsInRegion(IRManager& irm);
 
     static bool isGuardableVirtualCall(Inst* inst, MethodInst*& methodInst, Opnd*& base, 
-        Opnd* & tauNullChecked, Opnd*&tauTypesChecked, uint32 &argOffset);
+        Opnd* & tauNullChecked, Opnd*&tauTypesChecked, uint32 &argOffset, bool &isIntfCall);
 
 
 private: