harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfur...@apache.org
Subject svn commit: r577298 - in /harmony/enhanced/drlvm/trunk/vm/jitrino/src: jet/ optimizer/ translator/java/
Date Wed, 19 Sep 2007 13:14:58 GMT
Author: mfursov
Date: Wed Sep 19 06:14:57 2007
New Revision: 577298

URL: http://svn.apache.org/viewvc?rev=577298&view=rev
Log:
Fix for HARMONY-3098 [drlvm][jit] Jitrino fails to compile interlaced subroutines


Modified:
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/compiler.cpp
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/FlowGraph.cpp
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/inliner.cpp
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaByteCodeParser.cpp
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaByteCodeParser.h
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaByteCodeTranslator.cpp
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaByteCodeTranslator.h
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaLabelPrepass.cpp
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaLabelPrepass.h

Modified: harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/compiler.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/compiler.cpp?rev=577298&r1=577297&r2=577298&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/compiler.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/compiler.cpp Wed Sep 19 06:14:57 2007
@@ -921,10 +921,17 @@
                 assert(jsr_lead == pc);
                 // Simply load the state back to the parent's
                 BBState* prevState = m_bbStates[parentPC];
-                assert(m_jsrStates.find(jsr_lead) != m_jsrStates.end());
-                const BBState* jsrState = m_jsrStates[jsr_lead];
-                //prevState.jframe.init(&jsrState.jframe);
-                *prevState = *jsrState;
+//                assert(m_jsrStates.find(jsr_lead) != m_jsrStates.end());
+                if(m_jsrStates.find(jsr_lead) == m_jsrStates.end()) {
+                    // There can be a specific testcase with jsr without respective ret
+                    // In this case we can try to continue if there is a bb_State for jsr_lead
+                    // This is a temporary solution. HARMONY-4740 is devoted to the complete
one.
+                    assert(m_bbStates.find(jsr_lead) != m_bbStates.end());
+                } else {
+                    const BBState* jsrState = m_jsrStates[jsr_lead];
+                    //prevState.jframe.init(&jsrState.jframe);
+                    *prevState = *jsrState;
+                }
             }
             else {
                 // we have a fall through (and not through a JSR) path 
@@ -948,8 +955,15 @@
         // when the parentPC is the real parent, that is in a JSR subroutine
         // with several blocks.
         if (parentBB.jsr_target && jsr_lead != parentPC && jsr_lead != pc)
{
-            assert(m_jsrStates.find(parentPC) != m_jsrStates.end());
-            parentState = m_jsrStates[parentPC];
+            // There can be a specific testcase with jsr without respective ret
+            // In this case we can try to continue if there is a bb_State for parentPC
+            // This is a temporary solution. HARMONY-4740 is devoted to the complete one.
+//            assert(m_jsrStates.find(parentPC) != m_jsrStates.end());
+            if(m_jsrStates.find(parentPC) != m_jsrStates.end()) {
+                parentState = m_jsrStates[parentPC];
+            } else {
+                parentState = m_bbStates[parentPC];
+            }
         }
         else {
             parentState = m_bbStates[parentPC];

Modified: harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/FlowGraph.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/FlowGraph.cpp?rev=577298&r1=577297&r2=577298&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/FlowGraph.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/FlowGraph.cpp Wed Sep 19 06:14:57
2007
@@ -529,8 +529,9 @@
         // JSR never returns.  Convert to jmp.
         //
         saveReturn->unlink();
-        if(retVar != NULL)
-            stVar->unlink();
+        if(retVar != NULL) {
+            irManager->getOpndManager().deleteVar((VarOpnd*)retVar);
+        }
 
         const Edges& inEdges = entryJSR->getInEdges();
         for(eiter = inEdges.begin(); eiter != inEdges.end();) {

Modified: harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/inliner.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/inliner.cpp?rev=577298&r1=577297&r2=577298&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/inliner.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/inliner.cpp Wed Sep 19 06:14:57
2007
@@ -416,7 +416,7 @@
     void if_acmpne(uint32 targetOffset,uint32 nextOffset)  {}
     void goto_(uint32 targetOffset,uint32 nextOffset)  {}
     void jsr(uint32 offset, uint32 nextOffset)  {}
-    void ret(uint16 varIndex)  {}
+    void ret(uint16 varIndex,const uint8* byteCodes)  {}
     void tableswitch(JavaSwitchTargetsIter*)  {}
     void lookupswitch(JavaLookupSwitchTargetsIter*)  {}
     void ireturn(uint32 off)  {}

Modified: harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaByteCodeParser.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaByteCodeParser.cpp?rev=577298&r1=577297&r2=577298&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaByteCodeParser.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaByteCodeParser.cpp Wed
Sep 19 06:14:57 2007
@@ -605,13 +605,13 @@
         linearPassEnd = true; 
         if (labelStack != NULL) {
             // If labelStack is stack then the order of pushes should be reverted.
-            // For now it is line.
+            // For now it is line. (labelStack is a Queue)
             labelStack->push((uint8*)byteCodes + off+si16(bcp+1));
             labelStack->push((uint8*)byteCodes + off+3);
         }
         break;
     case 0xa9:    
-        ret(su8(bcp+1));    
+        ret(su8(bcp+1), byteCodes);    
         linearPassEnd = true;    
         break;
     case 0xaa:    
@@ -682,7 +682,7 @@
         case 0x38: fstore(su16(bcp+2),off);                   break;
         case 0x39: dstore(su16(bcp+2),off);                   break;
         case 0x3a: astore(su16(bcp+2),off);                   break;
-        case 0xa9: ret(su16(bcp+2));    linearPassEnd = true; break;
+        case 0xa9: ret(su16(bcp+2), byteCodes);    linearPassEnd = true; break;
         case 0x84: iinc(su16(bcp+2),si16(bcp+4));             break;
         default:
             assert(0);
@@ -712,7 +712,7 @@
         linearPassEnd = true;
         if (labelStack != NULL) {
             // If labelStack is stack then the order of pushes should be reverted.
-            // For now it is line.
+            // For now it is line. (labelStack is a Queue)
             labelStack->push((uint8*)byteCodes + off+si32(bcp+1));
             labelStack->push((uint8*)byteCodes + off+5);
         }

Modified: harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaByteCodeParser.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaByteCodeParser.h?rev=577298&r1=577297&r2=577298&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaByteCodeParser.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaByteCodeParser.h Wed Sep
19 06:14:57 2007
@@ -205,7 +205,7 @@
     virtual void if_acmpne(uint32 targetOffset,uint32 nextOffset) = 0;
     virtual void goto_(uint32 targetOffset,uint32 nextOffset) = 0;
     virtual void jsr(uint32 offset, uint32 nextOffset) = 0;
-    virtual void ret(uint16 varIndex) = 0;
+    virtual void ret(uint16 varIndex, const uint8* byteCodes) = 0;
     virtual void tableswitch(JavaSwitchTargetsIter*) = 0;
     virtual void lookupswitch(JavaLookupSwitchTargetsIter*) = 0;
     virtual void ireturn(uint32 off) = 0;

Modified: harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaByteCodeTranslator.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaByteCodeTranslator.cpp?rev=577298&r1=577297&r2=577298&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaByteCodeTranslator.cpp
(original)
+++ harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaByteCodeTranslator.cpp
Wed Sep 19 06:14:57 2007
@@ -300,10 +300,14 @@
         // error: invalid local variable id
         invalid();
     VariableIncarnation* varInc = prepass.getVarInc(currentOffset, index);
-    assert(varInc);
-    StateInfo::SlotInfo* slot = &stateInfo->stack[index];
-    slot->vars = new (memManager) SlotVar(varInc);
-    Opnd* var = varInc->getOpnd();
+    Opnd* var = NULL;
+    StateInfo::SlotInfo* slot = NULL;
+    slot = &stateInfo->stack[index];
+    if(varInc) {
+        slot->vars = new (memManager) SlotVar(varInc);
+        var = varInc->getOpnd();
+    }
+
     if (var) {
         assert(var->isVarOpnd());
         return var->asVarOpnd();
@@ -415,9 +419,6 @@
         return;
     }
 
-    // start a new basic block
-    if (Log::isEnabled()) Log::out() << "TRANSLATOR BASICBLOCK " << (int32)offset
<< " " << ::std::endl;
-
     // finish the previous basic block, if any work was required
     if (!lastInstructionWasABranch) {
         checkStack();
@@ -1306,7 +1307,7 @@
 }
 
 void 
-JavaByteCodeTranslator::ret(uint16 varIndex) {
+JavaByteCodeTranslator::ret(uint16 varIndex, const uint8* byteCodes) {
     lastInstructionWasABranch = true;
     checkStack();
     irBuilder.genRet(getVarOpndLdVar(JavaLabelPrepass::RET,varIndex));
@@ -1995,6 +1996,8 @@
         }
     }
     irBuilder.genReturn();
+    // some manually written test case can leave non empty opnd stack after return
+    opndStack.makeEmpty();
 }
 
 //-----------------------------------------------------------------------------

Modified: harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaByteCodeTranslator.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaByteCodeTranslator.h?rev=577298&r1=577297&r2=577298&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaByteCodeTranslator.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaByteCodeTranslator.h Wed
Sep 19 06:14:57 2007
@@ -187,7 +187,7 @@
     void if_acmpne(uint32 targetOffset,uint32 nextOffset);
     void goto_(uint32 targetOffset,uint32 nextOffset);
     void jsr(uint32 offset, uint32 nextOffset);
-    void ret(uint16 varIndex);
+    void ret(uint16 varIndex, const uint8* byteCodes);
     void tableswitch(JavaSwitchTargetsIter*);
     void lookupswitch(JavaLookupSwitchTargetsIter*);
     void ireturn(uint32 off);

Modified: harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaLabelPrepass.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaLabelPrepass.cpp?rev=577298&r1=577297&r2=577298&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaLabelPrepass.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaLabelPrepass.cpp Wed Sep
19 06:14:57 2007
@@ -204,7 +204,6 @@
 {
     if (opnd) return;
     opnd = irBuilder->genVarDef(declaredType, false);
-
     if(Log::isEnabled()) {
         Log::out() << "Create operand for VarIncarnation:" << ::std::endl;
         Log::out() << "    opnd:"; opnd->print(Log::out()); Log::out() <<
::std::endl;
@@ -328,7 +327,7 @@
                          handlerOffset,
                          exceptionType);
         block->addHandler(handler);
-        StateInfo *hi = prepass.stateTable->createStateInfo(handlerOffset, true);
+        StateInfo *hi = prepass.stateTable->createStateInfo(handlerOffset, prepass.getNumVars());
         hi->addCatchHandler(handler);
         StateInfo::SlotInfo* slot;
         if (hi->stackDepth != prepass.getNumVars()) {
@@ -566,7 +565,6 @@
 }
 
 void JavaLabelPrepass::offset(uint32 offset) {
-    if (Log::isEnabled()) Log::out() << std::endl << "PREPASS OFFSET " <<
(int32)offset << ", blockNo=" << blockNumber << std::endl;
     bytecodevisited->setBit(offset,true);
     if (offset==0)
         stateTable->restoreStateInfo(&stateInfo, offset);
@@ -970,7 +968,7 @@
 
     getVisited()->setBit(targetOffset,false);
 }
-void JavaLabelPrepass::ret(uint16 varIndex) { 
+void JavaLabelPrepass::ret(uint16 varIndex, const uint8* byteCodes) { 
     StateInfo::SlotInfo *slot = &stateInfo.stack[varIndex];
     VariableIncarnation* var = slot->vars->getVarIncarnation();
     assert(var);
@@ -985,7 +983,7 @@
     JsrEntryToJsrNextMap::const_iterator iter;
     for (iter = sub_entry_range.first; iter != sub_entry_range.second; iter++) {
         assert((*iter).first == subEntryOffset);
-        uint32 jsrTargetOffset = (*iter).second;
+        uint32 jsrNextOffset = (*iter).second;
 
         // according to JVM Spec:
         //      When executing the ret instruction, which implements a
@@ -997,7 +995,8 @@
         // propagating new objects created in finally section 
         //      to the instruction that follows the JSR
         //
-        stateTable->setStateInfoFromFinally(&stateInfo, jsrTargetOffset);
+        stateTable->setStateInfoFromFinally(&stateInfo, jsrNextOffset);
+        labelStack->push((uint8*)byteCodes + jsrNextOffset);
     }
 }
 
@@ -1824,7 +1823,6 @@
             }
             state->stackDepth = to;
         } else { // needs to merge the states
-            assert(!includeStack || state->stackDepth == stackDepth);
             if(Log::isEnabled()) {
                 Log::out() << " before\n";
                 printState(state);
@@ -1833,11 +1831,22 @@
                 struct StateInfo::SlotInfo *inSlot = &inState->stack[i];
                 struct StateInfo::SlotInfo *slot   = &stack[i];
                 if(Log::isEnabled()) {
-                    Log::out() << " i = " << i << ::std::endl;
-                    Log::out() << "inSlot: ";StateInfo::print(*inSlot, Log::out());Log::out()
<< ::std::endl;
-                    Log::out() << "slot:   ";StateInfo::print(*slot, Log::out());Log::out()
<< ::std::endl;
+                    Log::out() << "    i = " << i << ::std::endl;
+                    Log::out() << "            inSlot: ";StateInfo::print(*inSlot,
Log::out());Log::out() << ::std::endl;
+                    Log::out() << "            slot:   ";StateInfo::print(*slot, Log::out());Log::out()
<< ::std::endl;
+                }
+                if(i < state->stackDepth) {
+                    mergeSlots(inSlot, slot, offset, i < (unsigned)numVars);
+                } else { // inState has more slots. Additional ones should not be merged.
+                    rewriteSlots(inSlot, slot, offset, i < (unsigned)numVars);
+                }
+            }
+            if(includeStack) {
+                assert(state->stackDepth <= stackDepth);
+                if(state->stackDepth < stackDepth) {
+                    prepass.getVisited()->setBit(offset,false);
+                    state->stackDepth = stackDepth;
                 }
-                mergeSlots(inSlot, slot, offset, i < (unsigned)numVars);
             }
         }
         if(Log::isEnabled()) {
@@ -1847,13 +1856,33 @@
     }
 }
 
+void StateTable::rewriteSlots(StateInfo::SlotInfo* inSlot, StateInfo::SlotInfo* slot, uint32
offset, bool isVar) {
+
+    Type *intype = inSlot->type;
+    slot->type = intype;
+
+    assert(inSlot->vars);
+    if(!slot->vars) {
+        VariableIncarnation* var_inc = inSlot->vars->getVarIncarnation();
+        assert(var_inc);
+        slot->vars = new (memManager) SlotVar(var_inc);
+    }
+    slot->vars->addVarIncarnations(inSlot->vars, memManager, offset);
+    if (!isVar) {
+         slot->vars->mergeVarIncarnations(&typeManager);
+    }
+
+    slot->slotFlags = inSlot->slotFlags;
+    slot->jsrLabelOffset = inSlot->jsrLabelOffset;
+}
+
 void StateTable::mergeSlots(StateInfo::SlotInfo* inSlot, StateInfo::SlotInfo* slot, uint32
offset, bool isVar) {
 
     if (!getStateInfo(offset)->isVisited()) {
-        assert(NULL == slot->type);
-        assert(NULL == slot->vars);
-        copySlotInfo(*slot, *inSlot);
-        return;
+        if (!slot->type && !slot->vars) {
+            copySlotInfo(*slot, *inSlot);
+            return;
+        } // else it is an node after (next) jsr. The state was propagated here from ret.
     }
 
     slot->jsrLabelOffset = inSlot->jsrLabelOffset;
@@ -1913,32 +1942,30 @@
         Log::out() << "SETSTATE FROM FINALLY offset=" <<(int)offset <<
" depth=" << inState->stackDepth << ::std::endl;
         printState(inState);
     }
+    unsigned stackDepth = inState->stackDepth;
     StateInfo *state = getStateInfo(offset);
     assert(state);
-    unsigned stackDepth = inState->stackDepth;
+    assert(state->stackDepth <= stackDepth);
+
+    if(state != NULL && Log::isEnabled()) {
+        Log::out() << " before\n";
+        printState(state);
+    }
     if (stackDepth > 0) {
-        if (maxDepth < stackDepth) maxDepth = stackDepth;
-        if (Log::isEnabled()) Log::out() << "MAXDEPTH " << maxDepth <<
::std::endl;
-        struct StateInfo::SlotInfo *stack = state->stack;
-        // stack must be propagated from JSR to jsrNext earlier
-        assert(stack);
-        assert(state->stackDepth == stackDepth);
-        if(Log::isEnabled()) {
-            Log::out() << " before\n";
-            printState(state);
+        if (maxDepth < stackDepth) {
+            maxDepth = stackDepth;
+            if (Log::isEnabled()) Log::out() << "MAXDEPTH " << maxDepth <<
::std::endl;
         }
+        struct StateInfo::SlotInfo *stack = state->stack;
+        state->stackDepth = stackDepth;
         for (unsigned i=0; i < stackDepth; i++) {
             struct StateInfo::SlotInfo *inSlot = &inState->stack[i];
             struct StateInfo::SlotInfo *slot   = &stack[i];
             Type *intype = inSlot->type;
             Type *type  = slot->type;
-            if (Log::isEnabled()) Log::out() << "STACK " << i << ": "<<
type << ::std::endl;
+//            if (Log::isEnabled()) Log::out() << "STACK " << i << ": "<<
type << ::std::endl;
             if (!type && intype) {  // don't merge, just rewrite!
-                slot->type      = intype;
-                // Consider copying not pointers but SlotVat structures.
-                slot->vars      = inSlot->vars;
-                slot->slotFlags = inSlot->slotFlags;
-                slot->jsrLabelOffset = inSlot->jsrLabelOffset;
+                rewriteSlots(inSlot, slot, offset, i < numVars);
                 prepass.getVisited()->setBit(offset,false);
             } else if (!intype) {
                 continue;

Modified: harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaLabelPrepass.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaLabelPrepass.h?rev=577298&r1=577297&r2=577298&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaLabelPrepass.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaLabelPrepass.h Wed Sep
19 06:14:57 2007
@@ -436,7 +436,7 @@
     void if_acmpne(uint32 targetOffset,uint32 nextOffset);
     void goto_(uint32 targetOffset,uint32 nextOffset);
     void jsr(uint32 offset, uint32 nextOffset);
-    void ret(uint16 varIndex);
+    void ret(uint16 varIndex, const uint8* byteCodes);
     void tableswitch(JavaSwitchTargetsIter*);
     void lookupswitch(JavaLookupSwitchTargetsIter*);
     void incrementReturn();
@@ -549,15 +549,15 @@
     StateInfo *getStateInfo(uint32 offset) {
         return hashtable[offset];
     }
-    StateInfo *createStateInfo(uint32 offset, bool createStack = false) {
+    StateInfo *createStateInfo(uint32 offset, unsigned stackDepth = MAX_UINT32) {
         StateInfo *state = hashtable[offset];
         if (state == NULL) {
             state = new (memManager) StateInfo();
             hashtable[offset] = state;
         }
-        if (createStack && state->stack == NULL) {
+        if (stackDepth != MAX_UINT32 && state->stack == NULL) {
             state->stack = new (memManager) StateInfo::SlotInfo[maxDepth];
-            state->stackDepth = numVars;
+            state->stackDepth = stackDepth;
         }
         if(Log::isEnabled()) {
             Log::out() << "CREATESTATE " <<(int)offset << " depth " <<
state->stackDepth << ::std::endl;
@@ -568,6 +568,7 @@
 
     void copySlotInfo(StateInfo::SlotInfo& to, StateInfo::SlotInfo& from);
     void mergeSlots(StateInfo::SlotInfo* inSlot, StateInfo::SlotInfo* slot, uint32 offset,
bool isVar);
+    void rewriteSlots(StateInfo::SlotInfo* inSlot, StateInfo::SlotInfo* slot, uint32 offset,
bool isVar);
     void setStackInfo(StateInfo *inState, uint32 offset, bool includeVars, bool includeStack);
     void setStateInfo(StateInfo *inState, uint32 offset, bool isFallThru, bool varsOnly =
false);
     void setStateInfoFromFinally(StateInfo *inState, uint32 offset);



Mime
View raw message