You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ge...@apache.org on 2006/10/14 14:19:58 UTC

svn commit: r463919 - in /incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src: translator/ translator/java/ vm/ vm/drl/

Author: geirm
Date: Sat Oct 14 05:19:56 2006
New Revision: 463919

URL: http://svn.apache.org/viewvc?view=rev&rev=463919
Log:
HARMONY-1802

jitrino.OPT does not handle unresolved method parameters properly.

Ubuntu 6 - smoke, c-unit, ~kernel


Modified:
    incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/ByteCodeParser.h
    incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaByteCodeParser.h
    incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaByteCodeTranslator.cpp
    incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaLabelPrepass.cpp
    incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaLabelPrepass.h
    incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/vm/VMInterface.h
    incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/vm/drl/DrlVMInterface.cpp
    incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/vm/drl/DrlVMInterface.h

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/ByteCodeParser.h
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/ByteCodeParser.h?view=diff&rev=463919&r1=463918&r2=463919
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/ByteCodeParser.h (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/ByteCodeParser.h Sat Oct 14 05:19:56 2006
@@ -41,6 +41,9 @@
     virtual void parseInit() = 0;
     // called after the parsing ends, but not if an error occurs
     virtual void parseDone() = 0;
+    // if a callback during its construction determines some error
+    // the parsing can be ommitted with help of this:
+    virtual bool skipParsing() {return false;};
     // called when an error occurs during the byte code parsing
     virtual void parseError() = 0;
     uint32       getNextOffset() {return nextOffset;}
@@ -61,12 +64,14 @@
     //
     void parse(ByteCodeParserCallback* cb) {
         cb->parseInit();
-        byteCodeOffset = 0;
-        while (byteCodeOffset < byteCodeLength) {
-            if (cb->parseByteCode(byteCodes,byteCodeOffset) != true) {
-                return;
+        if (!cb->skipParsing()) {
+            byteCodeOffset = 0;
+            while (byteCodeOffset < byteCodeLength) {
+                if (cb->parseByteCode(byteCodes,byteCodeOffset) != true) {
+                    return;
+                }
+                byteCodeOffset = cb->getNextOffset();
             }
-            byteCodeOffset = cb->getNextOffset();
         }
         cb->parseDone();
     }

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaByteCodeParser.h
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaByteCodeParser.h?view=diff&rev=463919&r1=463918&r2=463919
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaByteCodeParser.h (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaByteCodeParser.h Sat Oct 14 05:19:56 2006
@@ -56,6 +56,7 @@
         bytecodevisited = NULL;
         prepassVisited = NULL;
         labelStack = NULL;
+        noNeedToParse = false;
     }
     JavaByteCodeParserCallback(MemoryManager& memManager,uint32 byteCodeLength) {
         currentOffset = 0;
@@ -66,6 +67,7 @@
         bytecodevisited = new (memManager) BitSet(memManager,byteCodeLength);
         prepassVisited = NULL;
         labelStack = new (memManager) Queue<uint8>(memManager);
+        noNeedToParse = false;
     }
     bool parseByteCode(const uint8* byteCodes,uint32 byteCodeOffset);
     BitSet* getVisited()  { return visited; }
@@ -78,6 +80,10 @@
     BitSet*          bytecodevisited;
     BitSet*          prepassVisited;
     Queue<uint8>*    labelStack;
+
+    // for example when some exception type can not be resolved
+    bool noNeedToParse;
+
     // called before each byte code to indicate the next byte code's offset
     virtual void offset(uint32 offset) = 0;
     virtual void offset_done(uint32 offset) = 0;
@@ -228,6 +234,9 @@
     virtual void multianewarray(uint32 constPoolIndex,uint8 dimensions) = 0;
     virtual void ifnull(uint32 targetOffset,uint32 nextOffset) = 0;
     virtual void ifnonnull(uint32 targetOffset,uint32 nextOffset) = 0;
+
+    virtual bool skipParsing() {return noNeedToParse;}
+
 };
 
 

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaByteCodeTranslator.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaByteCodeTranslator.cpp?view=diff&rev=463919&r1=463918&r2=463919
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaByteCodeTranslator.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaByteCodeTranslator.cpp Sat Oct 14 05:19:56 2006
@@ -250,6 +250,13 @@
             genMethodMonitorEnter();
         }
     }
+
+    if(!prepass.allExceptionTypesResolved()) {
+        unsigned problemToken = prepass.getProblemTypeToken();
+        assert(problemToken != MAX_UINT32);
+        linkingException(problemToken,OPCODE_CHECKCAST); // CHECKCAST is suitable here
+        noNeedToParse = true;
+    }
 }
 
 
@@ -314,6 +321,15 @@
     }
     // create a prolog instruction
     irBuilder.genMethodEntryMarker(&methodDesc);
+
+    if(!prepass.allExceptionTypesResolved()) {
+        unsigned problemToken = prepass.getProblemTypeToken();
+        assert(problemToken != MAX_UINT32);
+        linkingException(problemToken,OPCODE_CHECKCAST); // CHECKCAST is suitable here
+        noNeedToParse = true;
+        return;
+    }
+
     initLocalVars();
     initArgs();
     assert(numActualArgs == numArgs);
@@ -402,7 +418,10 @@
     argTypes = new (memManager) Type*[numArgs];
     args = new (memManager) Opnd*[numArgs];
     for (uint16 i=0; i<numArgs; i++) {
-        argTypes[i] = methodSignatureDesc->getParamType(i);
+        Type* argType = methodSignatureDesc->getParamType(i);
+        // argType == NULL if it fails to be resolved. Respective exception
+        // will be thrown at the point of usage
+        argTypes[i] = argType != NULL ? argType : typeManager.getNullObjectType();
     }
 }
 

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaLabelPrepass.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaLabelPrepass.cpp?view=diff&rev=463919&r1=463918&r2=463919
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaLabelPrepass.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaLabelPrepass.cpp Sat Oct 14 05:19:56 2006
@@ -295,13 +295,7 @@
     void addHandlerForCatchBlock(CatchBlock* block, 
                                       uint32 handlerOffset,
                                       uint32 handlerLength,
-                                      uint32 exceptionTypeToken) {
-        Type* exceptionType = NULL;
-        if (exceptionTypeToken != 0) {
-            exceptionType = compilationInterface.resolveNamedType(enclosingMethod,exceptionTypeToken);
-        } else {
-            exceptionType = prepass.typeManager.getSystemObjectType();
-        }
+                                      Type*  exceptionType) {
         jitrino_assert(compilationInterface, exceptionType);
         Log::out() << "Catch Exception Type = " << exceptionType->getName() << ::std::endl;
 
@@ -348,7 +342,7 @@
         return newBlock;
     }
 
-    virtual void catchBlock(uint32 tryOffset,
+    virtual bool catchBlock(uint32 tryOffset,
                             uint32 tryLength,
                             uint32 handlerOffset,
                             uint32 handlerLength,
@@ -367,9 +361,20 @@
   
         bool unnested_try_regions_found = false;
         CatchBlock* catchBlock;
+
+        Type* exceptionType = NULL;
+        if (exceptionTypeToken != 0) {
+            exceptionType = compilationInterface.resolveNamedType(enclosingMethod,exceptionTypeToken);
+            if(!exceptionType) { // the type can not be resolved. LinkingException must be thrown
+                return 0;
+            }
+        } else {
+            exceptionType = prepass.typeManager.getSystemObjectType();
+        }
+
         if (prevCatch != NULL && prevCatch->equals(tryOffset, endOffset) == true) {
             catchBlock = prevCatch;
-            addHandlerForCatchBlock(catchBlock, handlerOffset, handlerLength, exceptionTypeToken);
+            addHandlerForCatchBlock(catchBlock, handlerOffset, handlerLength, exceptionType);
         } else {
             prepass.stateTable->createStateInfo(tryOffset);
             // 
@@ -410,8 +415,9 @@
                 new (memManager) CatchBlock(nextRegionId++, tryOffset, endOffset, numCatch++);
             prepass.stateTable->getStateInfo(tryOffset)->addExceptionInfo(catchBlock);
             prepass.exceptionTable.push_back(catchBlock);
-            addHandlerForCatchBlock(catchBlock, handlerOffset, handlerLength, exceptionTypeToken);
+            addHandlerForCatchBlock(catchBlock, handlerOffset, handlerLength, exceptionType);
         }
+        return 1; // all exceptionTypes are OK
     }
     virtual void finallyBlock(uint32 tryOffset,
                             uint32 tryLength,
@@ -451,7 +457,8 @@
    localVars(mm),
    jsrEntriesMap(mm),
    retToSubEntryMap(mm),
-   exceptionTable(mm)
+   exceptionTable(mm),
+   problemTypeToken(MAX_UINT32)
 {
     uint32 numByteCodes = methodDesc.getByteCodeSize();
     //nextIsLabel = false;
@@ -483,8 +490,15 @@
     // parse and create exception info
     JavaExceptionParser exceptionTypes(irManager,*this,compilationInterface,&methodDesc);
     // fix exception handlers
-    methodDesc.parseJavaHandlers(exceptionTypes);
-    numCatchHandlers = exceptionTypes.numCatch;
+    unsigned problemToken = methodDesc.parseJavaHandlers(exceptionTypes);
+    if(problemToken != MAX_UINT32)
+    {
+        problemTypeToken = problemToken;
+        noNeedToParse = true;
+        numCatchHandlers = 0;
+    } else {
+        numCatchHandlers = exceptionTypes.numCatch;
+    }
 
     hasJsrLabels = false;
     isFallThruLabel = true;
@@ -511,7 +525,12 @@
             if (Simplifier::isExactType(actual))       StateInfo::setExactType(slot);
         } else {
             type = methodSig->getParamType(i);
-            slot->type = typeManager.toInternalType(methodSig->getParamType(i));
+            if (!type) {
+                // linkage error will happen at the usage point of this parameter
+                // here we just keep it as NullObj
+                type = typeManager.getNullObjectType();
+            }
+            slot->type = typeManager.toInternalType(type);
         }
         slot->vars  = new (memManager) SlotVar(getOrCreateVarInc(0, j, slot->type, NULL));
         JavaVarType javaType = getJavaType(type);

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaLabelPrepass.h
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaLabelPrepass.h?view=diff&rev=463919&r1=463918&r2=463919
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaLabelPrepass.h (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaLabelPrepass.h Sat Oct 14 05:19:56 2006
@@ -259,6 +259,10 @@
     void                    pushType(Type *type);
     bool isCategory2(struct StateInfo::SlotInfo slot) { return slot.type == int64Type || slot.type == doubleType; }
 
+    //
+    bool        allExceptionTypesResolved() {return problemTypeToken == MAX_UINT32;}
+    unsigned    getProblemTypeToken() {return problemTypeToken;}
+
     // cut and paste from Java_Translator.cpp
     // field, method, and type resolution
     //
@@ -527,6 +531,9 @@
     // helpers
     Type           *int32Type, *int64Type, *singleType, *doubleType;
     ExceptionTable exceptionTable;
+
+    // if an exception type can not be resolved, its token is being kept here
+    unsigned       problemTypeToken;
 
     // private helper methods
     void setLabel(uint32 offset);

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/vm/VMInterface.h
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/vm/VMInterface.h?view=diff&rev=463919&r1=463918&r2=463919
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/vm/VMInterface.h (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/vm/VMInterface.h Sat Oct 14 05:19:56 2006
@@ -61,7 +61,7 @@
 public:
     virtual ~ExceptionCallback() {}
 
-    virtual void catchBlock(uint32 tryOffset,
+    virtual bool catchBlock(uint32 tryOffset,
                             uint32 tryLength,
                             uint32 handlerOffset,
                             uint32 handlerLength,
@@ -160,7 +160,7 @@
     virtual uint32      getNumHandlers()    = 0;
     
     // Exception handler and signature parsing API
-    virtual void        parseJavaHandlers(ExceptionCallback&) = 0;
+    virtual unsigned    parseJavaHandlers(ExceptionCallback&) = 0;
     virtual void        parseCliHandlers(ExceptionCallback&) = 0;
     virtual bool        isVarPinned(uint32 varIndex) = 0;
     virtual Type*       getVarType(uint32 varType) = 0;

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/vm/drl/DrlVMInterface.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/vm/drl/DrlVMInterface.cpp?view=diff&rev=463919&r1=463918&r2=463919
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/vm/drl/DrlVMInterface.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/vm/drl/DrlVMInterface.cpp Sat Oct 14 05:19:56 2006
@@ -347,16 +347,22 @@
     return typeManager.getObjectType(parentClassHandle);
 }
 
-void 
+unsigned 
 DrlVMMethodDesc::parseJavaHandlers(ExceptionCallback& callback) {
     uint32 numHandlers = getNumHandlers();
     for (uint32 i=0; i<numHandlers; i++) {
         unsigned beginOffset,endOffset,handlerOffset,handlerClassIndex;
         method_get_handler_info(drlMethod,i,&beginOffset,&endOffset,
                              &handlerOffset,&handlerClassIndex);
-        callback.catchBlock(beginOffset,endOffset-beginOffset,
-                            handlerOffset,0,handlerClassIndex);
+        if (!callback.catchBlock(beginOffset,endOffset-beginOffset,
+                                 handlerOffset,0,handlerClassIndex))
+        {
+            // handlerClass failed to be resolved. LinkingException throwing helper
+            // will be generated instead of method's body
+            return handlerClassIndex;
+        }
     }
+    return MAX_UINT32; // all catchBlocks were processed successfully
 }
 
 void 

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/vm/drl/DrlVMInterface.h
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/vm/drl/DrlVMInterface.h?view=diff&rev=463919&r1=463918&r2=463919
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/vm/drl/DrlVMInterface.h (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/vm/drl/DrlVMInterface.h Sat Oct 14 05:19:56 2006
@@ -293,8 +293,8 @@
     //
     // Signature and handler parsing
     //
-    void parseJavaHandlers(ExceptionCallback&);
-    void parseCliHandlers(ExceptionCallback&);
+    unsigned parseJavaHandlers(ExceptionCallback&);
+    void     parseCliHandlers(ExceptionCallback&);
     
     uint32    getNumVars()            {return method_vars_get_number(drlMethod);}
     bool      isVarPinned(uint32 varIndex);