harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From var...@apache.org
Subject svn commit: r614165 - in /harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java: JavaByteCodeTranslator.cpp JavaByteCodeTranslator.h
Date Tue, 22 Jan 2008 10:31:13 GMT
Author: varlax
Date: Tue Jan 22 02:31:10 2008
New Revision: 614165

URL: http://svn.apache.org/viewvc?rev=614165&view=rev
Log:
Applied HARMONY-5399 [drlvm][jit] Enabling arraycopy optimization for primitive types when
write barriers are enabled

Modified:
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaByteCodeTranslator.cpp
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaByteCodeTranslator.h

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=614165&r1=614164&r2=614165&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
Tue Jan 22 02:31:10 2008
@@ -1645,8 +1645,8 @@
     //
     //  Try some optimizations for System::arraycopy(...), Min, Max, Abs...
     //
-    if (!compilationInterface.needWriteBarriers()    //genArrayCopyRepMove is not ready to
work in WB mode
-        && translationFlags.genArrayCopyRepMove == true 
+
+    if (translationFlags.genArrayCopyRepMove == true 
         && genArrayCopyRepMove(methodDesc,numArgs,srcOpnds)) {
         return;
     } else if (translationFlags.genArrayCopy == true &&
@@ -2361,7 +2361,8 @@
 bool
 JavaByteCodeTranslator::arraycopyOptimizable(MethodDesc * methodDesc, 
                                              uint32       numArgs,
-                                             Opnd **      srcOpnds) {
+                                             Opnd **      srcOpnds,
+                                             bool         usingWriteBarriers) {
 
     //
     //  an ArrayStoreException is thrown and the destination is not modified: 
@@ -2385,32 +2386,56 @@
            srcOpnds[3]->getType()->isInt4() && // 3 - dstPos
            srcOpnds[4]->getType()->isInt4());  // 4 - length
 
-    bool throwsASE = false;
     bool srcIsArray = srcType->isArray() && !srcType->isUnresolvedType();
     bool dstIsArray = dstType->isArray() && !dstType->isUnresolvedType();
-    ArrayType* srcAsArrayType = srcType->asArrayType();
-    ArrayType* dstAsArrayType = dstType->asArrayType();
-    bool srcIsArrOfPrimitive = srcIsArray && VMInterface::isArrayOfPrimitiveElements(srcAsArrayType->getVMTypeHandle());
-    bool dstIsArrOfPrimitive = dstIsArray && VMInterface::isArrayOfPrimitiveElements(dstAsArrayType->getVMTypeHandle());
-    if ( !(srcIsArray && dstIsArray) ) {
-         throwsASE = true;
-    } else if ( srcIsArrOfPrimitive ) {
-        if( !dstIsArrOfPrimitive || srcType != dstType )
-            throwsASE = true;
-    } else if( dstIsArrOfPrimitive ) {
-         throwsASE = true;
-    } else { // the both are of objects
-        // Here is some inaccuracy. If src is a subclass of dst there is no ASE for sure.
-        // If it is not, we should check the assignability of each element being copied.
-        // To avoid this we just reject the inlining of System::arraycopy call in this case.
-        NamedType* srcElemType = srcAsArrayType->getElementType();
-        NamedType* dstElemType = dstAsArrayType->getElementType();
-        throwsASE = srcElemType->getVMTypeHandle() != dstElemType->getVMTypeHandle();
+
+    bool isOptimizable = true;
+
+    if ( srcIsArray && dstIsArray )  {
+        // these are arrays        
+
+        ArrayType* srcAsArrayType = srcType->asArrayType();
+        ArrayType* dstAsArrayType = dstType->asArrayType();
+        bool srcIsArrOfPrimitive = srcIsArray && VMInterface::isArrayOfPrimitiveElements(srcAsArrayType->getVMTypeHandle());
+        bool dstIsArrOfPrimitive = dstIsArray && VMInterface::isArrayOfPrimitiveElements(dstAsArrayType->getVMTypeHandle());
+
+        // are these primitive or reference arrays?
+        if ( srcIsArrOfPrimitive && dstIsArrOfPrimitive ) {
+            // both arrays are primitive
+
+            // if we are dealing with different primitive type arrays, reject optimization
+            // TODO: is that really necessary?
+            isOptimizable = (srcType == dstType); 
+
+        } else if ( srcIsArrOfPrimitive ^ dstIsArrOfPrimitive ) {
+            // arrays are mixed primitive and reference types
+            // reject optimization
+            isOptimizable = false;
+
+        } else {
+            // both arrays are reference
+
+            // if write barriers are enabled, reject optimization
+            // if not, check the types
+            if ( usingWriteBarriers && compilationInterface.needWriteBarriers() )
{ 
+                isOptimizable = false;
+            } else {
+                // Here is some inaccuracy. If src is a subclass of dst there is no ASE for
sure.
+                // If it is not, we should check the assignability of each element being
copied.
+                // To avoid this we just reject the inlining of System::arraycopy call in
this case.
+                NamedType* srcElemType = srcAsArrayType->getElementType();
+                NamedType* dstElemType = dstAsArrayType->getElementType();
+                isOptimizable = (srcElemType->getVMTypeHandle() == dstElemType->getVMTypeHandle());
+            }
+
+        }
+
+    } else {
+        // source or destination are not arrays
+        isOptimizable = false;
     }
-    if ( throwsASE )
-        return false;
-    else
-        return true;
+
+    return isOptimizable;
 }
 
 bool
@@ -2419,7 +2444,7 @@
                                             Opnd **      srcOpnds) {
 
     if( !methodIsArraycopy(methodDesc) ||
-        !arraycopyOptimizable(methodDesc,numArgs,srcOpnds) )
+        !arraycopyOptimizable(methodDesc,numArgs,srcOpnds,true) )
     {
         // reject the inlining of System::arraycopy call
         return false;
@@ -2573,7 +2598,7 @@
                                      Opnd **      srcOpnds) {
 
     if( !methodIsArraycopy(methodDesc) ||
-        !arraycopyOptimizable(methodDesc,numArgs,srcOpnds) )
+        !arraycopyOptimizable(methodDesc,numArgs,srcOpnds,false) )
     {
         // reject the inlining of System::arraycopy call
         return false;

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=614165&r1=614164&r2=614165&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 Tue
Jan 22 02:31:10 2008
@@ -274,7 +274,7 @@
     bool    genVMHelper(const char* mname, uint32 numArgs,Opnd ** srcOpnds,Type * returnType);
     
     bool    methodIsArraycopy(MethodDesc * methodDesc);
-    bool    arraycopyOptimizable(MethodDesc * methodDesc, uint32 numArgs, Opnd ** srcOpnds);
+    bool    arraycopyOptimizable(MethodDesc * methodDesc, uint32 numArgs, Opnd ** srcOpnds,
bool usingWriteBarriers);
 
     bool    genCharArrayCopy(MethodDesc * methodDesc,uint32 numArgs,Opnd ** srcOpnds, Type
* returnType);
     bool    genArrayCopyRepMove(MethodDesc * methodDesc,uint32 numArgs,Opnd ** srcOpnds);



Mime
View raw message