harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfur...@apache.org
Subject svn commit: r617509 - in /harmony/enhanced/drlvm/trunk/vm: jitrino/src/jet/ jitrino/src/optimizer/ jitrino/src/translator/java/ vmcore/build/ vmcore/include/ vmcore/src/kernel_classes/javasrc/java/lang/ vmcore/src/kernel_classes/javasrc/org/apache/harm...
Date Fri, 01 Feb 2008 14:43:12 GMT
Author: mfursov
Date: Fri Feb  1 06:43:01 2008
New Revision: 617509

URL: http://svn.apache.org/viewvc?rev=617509&view=rev
Log:
Fix for HARMONY-5409 [drlvm][opt] Object.getClass() VMMagic based implementation


Modified:
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/cg_meth.cpp
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/FlowGraph.cpp
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/escanalyzer.cpp
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/inliner.cpp
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/inliner.h
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/translator/java/JavaByteCodeTranslator.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/build/vmcore.exp
    harmony/enhanced/drlvm/trunk/vm/vmcore/include/Class.h
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/VMClassRegistry.java
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/org/apache/harmony/drlvm/VMHelper.java
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/org/apache/harmony/drlvm/VMHelperFastPath.java
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMClassRegistry.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMClassRegistry.h
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_drlvm_VMHelper.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_drlvm_VMHelper.h
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_drlvm_VMHelperFastPath.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_drlvm_VMHelperFastPath.h

Modified: harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/cg_meth.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/cg_meth.cpp?rev=617509&r1=617508&r2=617509&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/cg_meth.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/cg_meth.cpp Fri Feb  1 06:43:01 2008
@@ -848,6 +848,7 @@
             mov(cs_vtbl.get(0), thiz.as_opnd());
         }
         gen_call_vm(cs_vtbl, rt_helper_get_vtable, 1, klass);
+
         //
         // Method's vtable is in gr_ret now, prepare stack
         //

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=617509&r1=617508&r2=617509&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/FlowGraph.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/FlowGraph.cpp Fri Feb  1 06:43:01
2008
@@ -35,6 +35,7 @@
 #include "deadcodeeliminator.h"
 #include "TranslatorIntfc.h"
 #include "LoopTree.h"
+#include "inliner.h"
 
 #include <stdlib.h>
 #include <string.h>
@@ -1158,6 +1159,7 @@
             }
         }
     }
+    
     // Remove extra PseudoThrow insts
     if (irm.getOptimizerFlags().rept_aggressive) {
         DeadCodeEliminator dce(irm);
@@ -1166,19 +1168,29 @@
         normalizePseudoThrow(irm);
     }
 
+
+    //process all methods marked with @Inline pragma
+    if (Log::isLogEnabled(LogStream::IRDUMP)) {
+        LogStream& irdump = Log::log(LogStream::IRDUMP);
+        Log::printIRDumpBegin(irdump.out(), id, stage, "before_pragma_inline");
+        printHIR(irdump.out(), irm.getFlowGraph(), irm.getMethodDesc());
+        Log::printIRDumpEnd(irdump.out(), id, stage, "before_pragma_inline");
+    }
+    Inliner::processInlinePragmas(irm);
+
+
     //
     // a quick cleanup of unreachable and empty basic blocks
     //
     fg.purgeUnreachableNodes();
     fg.purgeEmptyNodes(false);
-    
+
     if (Log::isLogEnabled(LogStream::IRDUMP)) {
         LogStream& irdump = Log::log(LogStream::IRDUMP);
         Log::printStageEnd(irdump.out(), id, "TRANS", stage, stage);
     }
-}
-
 
+}
 
 void FlowGraph::printHIR(std::ostream& os, ControlFlowGraph& fg, MethodDesc&
methodDesc) {
     const char* methodName = methodDesc.getName();

Modified: harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/escanalyzer.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/escanalyzer.cpp?rev=617509&r1=617508&r2=617509&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/escanalyzer.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/escanalyzer.cpp Fri Feb  1 06:43:01
2008
@@ -341,6 +341,7 @@
                 break;
 
             case Op_Conv:     // conv
+            case Op_ConvUnmanaged:
                 if (inst->getDst()->getType()->isObject()) {
                     type=inst->getDst()->getType();
                     assert(findCnGNode_op(inst->getDst()->getId())==NULL);

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=617509&r1=617508&r2=617509&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/inliner.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/inliner.cpp Fri Feb  1 06:43:01
2008
@@ -67,8 +67,6 @@
 #define INLINE_EXACT_ALL_BONUS 0
 #define INLINE_SKIP_EXCEPTION_PATH false
 
-#define PRAGMA_INLINE_BENEFIT (2*1000*1000*1000)
-
 DEFINE_SESSION_ACTION(InlinePass, inline, "Method Inlining");
 
 Inliner::Inliner(SessionAction* argSource, MemoryManager& mm, IRManager& irm, 
@@ -80,7 +78,7 @@
       _inlineCandidates(mm), _initByteSize(irm.getMethodDesc().getByteCodeSize()), 
       _currentByteSize(irm.getMethodDesc().getByteCodeSize()), 
       _inlineTree(new (mm) InlineNode(irm, 0, 0)),
-      translatorAction(NULL), inlinePragma(NULL), 
+      translatorAction(NULL), 
       usePriorityQueue(_usePriorityQueue), inlinerPipelineName(inlinePipeline),
       connectEarly(true), isPseudoThrowInserted(false)
 {
@@ -158,9 +156,6 @@
     }
 
     _usesOptimisticBalancedSync = argSource->getBoolArg("sync_optimistic", false) ? argSource->getBoolArg("sync_optcatch",
true) : false;
-    
-    // Avoid class resolution during compilation. VMMagic package should be loaded &
resolved at start up.  
-    inlinePragma = irm.getCompilationInterface().findClassUsingBootstrapClassloader(PRAGMA_INLINE_TYPE_NAME);
 }
 
 int32 
@@ -173,11 +168,6 @@
                                << methodDesc.getParentType()->getName()
                                << "." << methodDesc.getName() << ::std::endl;
     }
-    if (inlinePragma!=NULL && methodDesc.hasAnnotation(inlinePragma)) {
-        //methods marked with inline pragma processed separately and are always inlined
-        //regardless of it benefits and size limitations.
-        assert(0);
-    }
     if (_inlineBonusMethodTable!=NULL && _inlineBonusMethodTable->accept_this_method(methodDesc))
{
         benefit+=1000;
         if (Log::isEnabled()) {
@@ -834,7 +824,7 @@
         scaleBlockCounts(callNode, inlinedIRM);
     }
     
-    // Update priority queue with calls in this region and check @Inline pragmas
+    // Update priority queue with calls in this region
     processRegion(inlineNode, dtree, ltree);
     
     // If top level flowgraph 
@@ -916,7 +906,6 @@
         call = ((Inst*)callNode->getLastInst())->asMethodCallInst();
         assert(call != NULL);
         methodDesc = call->getMethodDesc();
-        bool isPragmaInline = inlinePragma != NULL && methodDesc->hasAnnotation(inlinePragma);;
 
         // If candidate would cause top level method to exceed size threshold, throw away.
         
@@ -924,7 +913,7 @@
         methodByteSize = (methodByteSize <= CALL_COST) ? 1 : methodByteSize-CALL_COST;
         newByteSize = _currentByteSize + methodByteSize;
         double factor = ((double) newByteSize) / ((double) _initByteSize);
-        if(isPragmaInline || newByteSize < _minInlineStop || factor <= _maxInlineGrowthFactor
|| (methodByteSize < _inlineSmallMaxByteSize)) {
+        if(newByteSize < _minInlineStop || factor <= _maxInlineGrowthFactor || (methodByteSize
< _inlineSmallMaxByteSize)) {
             found = true;
         } else {
             Log::out() << "Skip inlining " << methodDesc->getParentType()->getName()
<< "." << methodDesc->getName() << ::std::endl;
@@ -959,9 +948,7 @@
 InlineNode* Inliner::createInlineNode(CompilationContext& inlineCC, MethodCallInst* call)
{
     MethodDesc *methodDesc = call->getMethodDesc();
     IRManager* inlinedIRM = new (_tmpMM) IRManager(_tmpMM, _toplevelIRM, *methodDesc, NULL);
-    // Augment inline tree
-    bool forceInline = inlinePragma != NULL && methodDesc->hasAnnotation(inlinePragma);
-    InlineNode *inlineNode = new (_tmpMM) InlineNode(*inlinedIRM, call, call->getNode(),
forceInline);
+    InlineNode *inlineNode = new (_tmpMM) InlineNode(*inlinedIRM, call, call->getNode(),
false);
     
     inlineCC.setHIRManager(inlinedIRM);
     
@@ -998,19 +985,12 @@
             MethodDesc* methodDesc = call->getMethodDesc();
 
             Log::out() << "Considering inlining instruction I" << (int)call->getId()
<< ::std::endl;
-            if (inlinePragma != NULL && methodDesc->hasAnnotation(inlinePragma))
{
-                assert(!methodDesc->isSynchronized()); //not tested!
-                if (Log::isEnabled()) {
-                    Log::out()<<"Found Inline pragma, adding to the queue:";call->print(Log::out());Log::out()<<std::endl;
-                }
-                _inlineCandidates.push(CallSite(PRAGMA_INLINE_BENEFIT, node, inlineNode));
-            } else if (usePriorityQueue && canInlineInto(*methodDesc)) {
+            if (usePriorityQueue && canInlineInto(*methodDesc)) {
                 uint32 size = methodDesc->getByteCodeSize();
                 int32 benefit = computeInlineBenefit(node, *methodDesc, inlineNode, ltree->getLoopDepth(node));
                 assert(size > 0);
                 Log::out() << "Inline benefit " << methodDesc->getParentType()->getName()
<< "." << methodDesc->getName() << " == " << (int) benefit <<
::std::endl;
                 if(0 < size && benefit > _minBenefitThreshold) {
-                    assert(benefit < PRAGMA_INLINE_BENEFIT);
                     // Inline candidate
                     Log::out() << "Add to queue" << std::endl;
                     _inlineCandidates.push(CallSite(benefit, node, inlineNode));
@@ -1173,20 +1153,22 @@
         }
         //inline current region
         inlineRegion(regionNode);
-        // Limit inlining by node count. All @Inline methods still must be inlined.
-        if (!regionNode->isForced() && _toplevelIRM.getFlowGraph().getNodeCount()
> _inlineMaxNodeThreshold) {
+        // Limit inlining by node count. 
+        if (_toplevelIRM.getFlowGraph().getNodeCount() > _inlineMaxNodeThreshold) {
             break;
         }
     } while (true);
 
 
     // Clean up phase.
-    DeadCodeEliminator dce(_toplevelIRM);
-    dce.eliminateUnreachableCode();
-    assert(_toplevelIRM.getInSsa());
-    OptPass::fixupSsa(_toplevelIRM);
-    if (isPseudoThrowInserted && _toplevelIRM.getOptimizerFlags().rept_aggressive)
{
-        dce.removeExtraPseudoThrow();
+    if (_toplevelIRM.getInSsa()) {
+        DeadCodeEliminator dce(_toplevelIRM);
+        dce.eliminateUnreachableCode();
+        assert(_toplevelIRM.getInSsa());
+        OptPass::fixupSsa(_toplevelIRM);
+        if (isPseudoThrowInserted && _toplevelIRM.getOptimizerFlags().rept_aggressive)
{
+            dce.removeExtraPseudoThrow();
+        }
     }
 }
 
@@ -1202,10 +1184,12 @@
         }
 
         // Optimize inlined region before splicing
-        CompilationContext* topCC = regionManager.getCompilationContext();
-        inlineCC.stageId = topCC->stageId;
-        Inliner::runInlinerPipeline(inlineCC, inlinerPipelineName);
-        topCC->stageId = inlineCC.stageId;
+        if (inlinerPipelineName!=NULL) {
+            CompilationContext* topCC = regionManager.getCompilationContext();
+            inlineCC.stageId = topCC->stageId;
+            Inliner::runInlinerPipeline(inlineCC, inlinerPipelineName);
+            topCC->stageId = inlineCC.stageId;
+        }
 
         // Splice into flow graph and find next region.
         if(!connectEarly) {
@@ -1213,6 +1197,46 @@
         }
         OptPass::computeDominatorsAndLoops(regionManager);
     } 
+}
+
+void Inliner::processInlinePragmas(IRManager& irm) {
+    // VMMagic package should be loaded & resolved at start up.  
+    NamedType* inlinePragma = irm.getCompilationInterface().findClassUsingBootstrapClassloader(PRAGMA_INLINE_TYPE_NAME);
+    if (inlinePragma == NULL) {
+        if (Log::isEnabled()) {
+            Log::out()<<"@Inline is not resolved. Skipping @Inline check."<<std::endl;
+        }
+        return; //pragma inline is not resolved -> nothing to check
+    }
+
+    MemoryManager tmpMM("processInlinePragmas");
+    Inliner inliner(irm.getCompilationContext()->getCurrentSessionAction(), tmpMM, irm,
false, false, NULL);
+    StlVector<MethodCallInst*> callsToInline(tmpMM);
+
+    //find all methods with @Inline
+    const Nodes& nodes = irm.getFlowGraph().getNodes();
+    for (Nodes::const_iterator it = nodes.begin(), end = nodes.end(); it!=end; ++it) {
+        Node* node = *it;
+        for (Inst* inst = (Inst*)node->getFirstInst(); inst!=NULL; inst = inst->getNextInst())
{
+            if (!inst->isMethodCall()) {
+                continue;
+            }
+            MethodCallInst* mci = inst->asMethodCallInst();
+            MethodDesc* md = mci->getMethodDesc();
+            if (md != NULL && md->hasAnnotation(inlinePragma)) {
+                callsToInline.push_back(mci);
+                if (Log::isEnabled()) {
+                    Log::out()<<"found @Inline :";mci->print(Log::out()); Log::out()<<std::endl;
+                }
+            }
+        }
+    }
+
+    //now inline all all @Inline methods found 
+    for(StlVector<MethodCallInst*>::const_iterator it = callsToInline.begin(), end
= callsToInline.end(); it!=end; ++it) {
+        MethodCallInst* call = *it;
+        inliner.runInliner(call);
+    }
 }
 
 void InlinePass::_run(IRManager& irm) {

Modified: harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/inliner.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/inliner.h?rev=617509&r1=617508&r2=617509&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/inliner.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/inliner.h Fri Feb  1 06:43:01 2008
@@ -60,21 +60,19 @@
 class InlineNode : public TreeNode {
 public:
     InlineNode(IRManager& irm, Inst *callInst, Node *callNode, bool forced = false)
-        : _irm(irm), _callInst(callInst), _callNode(callNode), _forceInline(forced) {}
+        : _irm(irm), _callInst(callInst), _callNode(callNode) {}
     InlineNode* getChild()    {return (InlineNode*) child;}
     InlineNode* getSiblings() {return (InlineNode*) siblings;}
     InlineNode* getParent()   {return (InlineNode*) parent;}
     IRManager&  getIRManager()      { return _irm; }
     Inst*       getCallInst() { return _callInst; }
     Node*       getCallNode() { return _callNode; }
-    bool        isForced() { return _forceInline; }
     void print(::std::ostream& os);
     void printTag(::std::ostream& os);
 private:
     IRManager&  _irm;
     Inst*       _callInst;
     Node*       _callNode;
-    bool        _forceInline;
 };
 
 class InlineTree : public Tree {
@@ -125,6 +123,11 @@
 
     void setConnectEarly(bool early) {connectEarly = early;}
 
+    /** Inlines all methods annotated with @Inline. 
+        Does not run any pipeline for inlined methods
+    */
+    static void processInlinePragmas(IRManager& irm);
+
 private:
 
     class CallSite {
@@ -206,7 +209,6 @@
     bool isBCmapRequired;
     void* bc2HIRMapHandler;
     TranslatorAction* translatorAction;
-    NamedType* inlinePragma;
     bool usePriorityQueue;
     const char* inlinerPipelineName;
     bool connectEarly;

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=617509&r1=617508&r2=617509&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
Fri Feb  1 06:43:01 2008
@@ -2325,9 +2325,10 @@
         assert(res);
         return;
     } else if (isVMHelperClass(kname) && !methodDesc->isNative()) {
-        UNUSED bool res = genVMHelper(mname, numArgs, srcOpnds, returnType);
-            assert(res);
-        return;
+        bool res = genVMHelper(mname, numArgs, srcOpnds, returnType);
+        if (res) {
+            return;
+        }
     }
     Opnd *tauNullChecked = irBuilder.genTauSafe(); // always safe, is a static method call
     Type* resType = returnType;
@@ -3714,6 +3715,15 @@
     if (!strcmp(mname,"getFastTypeCheckDepth")) {
         assert(numArgs == 1 && srcOpnds[0]->getType()->isUnmanagedPtr());
         Opnd* res = irBuilder.genJitHelperCall(ClassGetFastCheckDepth, resType, numArgs,
srcOpnds);
+        pushOpnd(res);
+        return true;
+    }
+
+    if (!strcmp(mname,"isVMMagicPackageSupported")) {
+        assert(numArgs == 0);
+        ObjectType* base = compilationInterface.findClassUsingBootstrapClassloader(VMHELPER_TYPE_NAME);
+        int ready = base!=NULL && !base->needsInitialization() ? 1 : 0;
+        Opnd* res = irBuilder.genLdConstant((int32)ready);
         pushOpnd(res);
         return true;
     }

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/build/vmcore.exp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/build/vmcore.exp?rev=617509&r1=617508&r2=617509&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/build/vmcore.exp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/build/vmcore.exp Fri Feb  1 06:43:01 2008
@@ -205,7 +205,7 @@
     Java_java_lang_System_setErrUnsecure;
     Java_java_lang_System_setInUnsecure;
     Java_java_lang_System_setOutUnsecure;
-    Java_java_lang_VMClassRegistry_getClass;
+    Java_java_lang_VMClassRegistry_getClassNative;
     Java_java_lang_VMClassRegistry_getClassLoader0;
     Java_java_lang_VMClassRegistry_getComponentType;
     Java_java_lang_VMClassRegistry_getDeclaredClasses;
@@ -273,8 +273,6 @@
     Java_java_util_concurrent_locks_LockSupport_unpark;
     Java_org_apache_harmony_drlvm_thread_ThreadHelper_getThreadIdOffset;
     Java_org_apache_harmony_drlvm_thread_ThreadHelper_getLockWordOffset;
-    Java_org_apache_harmony_drlvm_VMHelperFastPath_getObjectVtableOffset;
-    Java_org_apache_harmony_drlvm_VMHelperFastPath_getVtableClassOffset;
     Java_org_apache_harmony_drlvm_VMHelperFastPath_getVtableIntfTableOffset;
     Java_org_apache_harmony_drlvm_VMHelperFastPath_getVtableIntfTypeOffset;
     Java_org_apache_harmony_drlvm_VMHelperFastPath_getVtableSuperclassesOffset;
@@ -283,6 +281,9 @@
     Java_org_apache_harmony_drlvm_VMHelper_getPointerTypeSize;
     Java_org_apache_harmony_drlvm_VMHelper_isCompressedRefsMode;
     Java_org_apache_harmony_drlvm_VMHelper_isCompressedVTableMode;
+    Java_org_apache_harmony_drlvm_VMHelper_getObjectVtableOffset;
+    Java_org_apache_harmony_drlvm_VMHelper_getVtableClassOffset;
+    Java_org_apache_harmony_drlvm_VMHelper_getClassJLCHanldeOffset;
     Java_org_apache_harmony_kernel_vm_VM_getClassLoader;
     Java_org_apache_harmony_lang_management_ClassLoadingMXBeanImpl_getLoadedClassCountImpl;
     Java_org_apache_harmony_lang_management_ClassLoadingMXBeanImpl_getTotalLoadedClassCountImpl;

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/include/Class.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/include/Class.h?rev=617509&r1=617508&r2=617509&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/include/Class.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/include/Class.h Fri Feb  1 06:43:01 2008
@@ -1168,7 +1168,7 @@
     unsigned get_number_of_virtual_method_entries() const {
         return m_num_virtual_method_entries;
     }
-
+   
     /** Gets the first subclass for Class Hierarchy Analysis.
      * @return The first subclass.*/
     Class* get_first_child() const { return m_cha_first_child; }
@@ -1230,6 +1230,13 @@
         Class* dummy = NULL;
         assert(sizeof(dummy->m_array_element_class) == sizeof(void*));
         return (size_t)((char*)(&dummy->m_array_element_class) - (char*)dummy);
+    }
+
+    /** Gets an offset of <code>m_class_handle</code> in the class.
+     * @note It used by VMHelper class*/
+    static size_t get_offset_of_jlc_handle () {
+        Class* dummy=NULL;       
+        return (size_t)((char*)(&dummy->m_class_handle) - (char*)dummy);
     }
 
     /** Gets the number of array dimensions.

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/VMClassRegistry.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/VMClassRegistry.java?rev=617509&r1=617508&r2=617509&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/VMClassRegistry.java
(original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/VMClassRegistry.java
Fri Feb  1 06:43:01 2008
@@ -25,6 +25,7 @@
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.lang.reflect.Member;
+import org.apache.harmony.drlvm.VMHelper;
 
 
 /**
@@ -103,7 +104,15 @@
      * {@link Object#getClass() Object.getClass()} method.
      * @api2vm
      */
-    static native Class<? extends Object> getClass(Object obj);
+    static native Class<? extends Object> getClassNative(Object obj);
+
+    static Class<? extends Object> getClass(Object obj) {
+        if (VMHelper.isVMMagicPackageSupported()) {
+            return (Class<? extends Object>)VMHelper.getManagedClass(obj).toObjectReference().toObject();
+        }
+        return getClassNative(obj);
+    }
+
 
     /**
      * This method satisfies the requirements of the specification for the

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/org/apache/harmony/drlvm/VMHelper.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/org/apache/harmony/drlvm/VMHelper.java?rev=617509&r1=617508&r2=617509&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/org/apache/harmony/drlvm/VMHelper.java
(original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/org/apache/harmony/drlvm/VMHelper.java
Fri Feb  1 06:43:01 2008
@@ -47,20 +47,19 @@
 
     public static final long COMPRESSED_REFS_OBJ_BASE_OFFSET  = getCompressedModeObjectBaseOffset();
 
-    public static final int OBJ_VTABLE_OFFSET = 0;
+    public static final int OBJ_VTABLE_OFFSET = getObjectVtableOffset();
 
     public static final int VTABLE_GCPRIVATE_OFFSET = 0;
 
+    public static final int VTABLE_CLASS_OFFSET = getVtableClassOffset();
+
     public static final int OBJ_INFO_OFFSET = 4;
 
+    public static final int CLASS_JLC_HANDLE_OFFSET = getClassJLCHanldeOffset();
 
-    // Force loading of magic classes.
-    static {
-        try {
-            Class.forName(Inline.class.getName(), true, null);
-        } catch (ClassNotFoundException e) {}
-    }
 
+    // preload @Inline vmmagic class
+    static final Class pragmaInline = org.vmmagic.pragma.Inline.class;
 
 
     //Slow path versions of helpers
@@ -92,6 +91,8 @@
 
     //utility magics supported by JIT
 
+    public static boolean isVMMagicPackageSupported() {return false;}
+
     public static Address getTlsBaseAddress() {fail(); return null;}
 
     public static boolean isArray(Address classHandle) {VMHelper.fail(); return false;}
@@ -129,11 +130,29 @@
     }
 
 
+    @Inline
+    public static Address getNativeClass(Object obj) {                
+        Address nativeClass = getVTable(obj).loadAddress(Offset.fromIntZeroExtend(VTABLE_CLASS_OFFSET));
               
+        return nativeClass;
+    }
+    
+    @Inline
+    public static Address getManagedClass(Object obj) {                
+        //accessing to ManagedObject** m_class_handle field + 1 dereference in Class.h
+        Address moAddr = getNativeClass(obj).loadAddress(Offset.fromIntZeroExtend(CLASS_JLC_HANDLE_OFFSET)).loadAddress();
                
+        return moAddr;
+    } 
+
+
+
 
     // private area
 
     private VMHelper() {}
 
+    /** @return vtable offset in managed object structure */
+    private static native int getObjectVtableOffset();
+
     /** @return pointer-type size. 4 or 8 */
     private static native int getPointerTypeSize();
 
@@ -148,6 +167,13 @@
 
     /** @return object base offset if is in compressed-refs mode or -1*/
     private static native long getCompressedModeObjectBaseOffset();
+
+    /** @return native Class* struct offset in vtable*/
+    private static native int getVtableClassOffset();
+
+    /** @return managed object field offset in vtable*/
+    private static native int getClassJLCHanldeOffset();
+
 }
 
 

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/org/apache/harmony/drlvm/VMHelperFastPath.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/org/apache/harmony/drlvm/VMHelperFastPath.java?rev=617509&r1=617508&r2=617509&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/org/apache/harmony/drlvm/VMHelperFastPath.java
(original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/org/apache/harmony/drlvm/VMHelperFastPath.java
Fri Feb  1 06:43:01 2008
@@ -24,10 +24,8 @@
 import org.vmmagic.unboxed.*;
 import org.vmmagic.pragma.*;
 
-public class VMHelperFastPath {
+class VMHelperFastPath {
 
-    private static final int OBJ_VTABLE_OFFSET   = getObjectVtableOffset();
-    private static final int VTABLE_CLASS_OFFSET = getVtableClassOffset();
     private static final int VTABLE_SUPERCLASSES_OFFSET = getVtableSuperclassesOffset();
     private static final int CLASS_INF_TYPE_0_OFFSET  = getVtableIntfTypeOffset(0);
     private static final int CLASS_INF_TABLE_0_OFFSET = getVtableIntfTableOffset(0);
@@ -38,25 +36,13 @@
 
     private VMHelperFastPath() {}
 
-    @Inline
-    public static Address getVTableAddress(Object obj) {
-        Address objAddr = ObjectReference.fromObject(obj).toAddress();
-        if (VMHelper.COMPRESSED_VTABLE_MODE) {
-            int vtableOffset = objAddr.loadInt(Offset.fromIntZeroExtend(OBJ_VTABLE_OFFSET));
-            Address res = Address.fromLong(VMHelper.COMPRESSED_VTABLE_BASE_OFFSET + vtableOffset);
-            return res;
-        }
-        return objAddr.loadAddress(Offset.fromIntZeroExtend(OBJ_VTABLE_OFFSET));
-        
-    }
-
 
 //TODO: leave only one version 
 //TODO: refactor code to use getVtableIntfTableOffset method (+ avoid extra comparisons while
refactoring)
 
     @Inline
     public static Address getInterfaceVTable3(Address intfType, Object obj)  {
-        Address vtableAddr = getVTableAddress(obj);
+        Address vtableAddr = VMHelper.getVTable(obj);
 
         Address inf0Type = vtableAddr.loadAddress(Offset.fromIntZeroExtend(CLASS_INF_TYPE_0_OFFSET));
         if (inf0Type.EQ(intfType)) {
@@ -78,7 +64,7 @@
 
     @Inline
     public static Address getInterfaceVTable2(Address intfType, Object obj)  {
-        Address vtableAddr = getVTableAddress(obj);
+        Address vtableAddr = VMHelper.getVTable(obj);
 
         Address inf0Type = vtableAddr.loadAddress(Offset.fromIntZeroExtend(CLASS_INF_TYPE_0_OFFSET));
         if (inf0Type.EQ(intfType)) {
@@ -96,7 +82,7 @@
 
     @Inline
     public static Address getInterfaceVTable1(Address intfType, Object obj)  {
-        Address vtableAddr = getVTableAddress(obj);
+        Address vtableAddr = VMHelper.getVTable(obj);
 
         Address inf0Type = vtableAddr.loadAddress(Offset.fromIntZeroExtend(CLASS_INF_TYPE_0_OFFSET));
         if (inf0Type.EQ(intfType)) {
@@ -113,7 +99,7 @@
             return false;
         }
         if (VMHelper.isInterface(castType)) {
-            Address vtableAddr = getVTableAddress(obj);
+            Address vtableAddr = VMHelper.getVTable(obj);
 
             Address inf0Type = vtableAddr.loadAddress(Offset.fromIntZeroExtend(CLASS_INF_TYPE_0_OFFSET));
             if (inf0Type.EQ(castType)) {
@@ -140,7 +126,7 @@
             return;
         }
         if (VMHelper.isInterface(castType)) {
-            Address vtableAddr = getVTableAddress(obj);
+            Address vtableAddr = VMHelper.getVTable(obj);
 
             Address inf0Type = vtableAddr.loadAddress(Offset.fromIntZeroExtend(CLASS_INF_TYPE_0_OFFSET));
             if (inf0Type.EQ(castType)) {
@@ -162,8 +148,8 @@
 
     @Inline
     public static boolean fastClassInstanceOf(Object obj, Address castType, int fastCheckDepth)
{
-        Address objVtableAddr = getVTableAddress(obj);
-        Address objClassType  = objVtableAddr.loadAddress(Offset.fromIntZeroExtend(VTABLE_CLASS_OFFSET));
+        Address objVtableAddr = VMHelper.getVTable(obj);
+        Address objClassType  = objVtableAddr.loadAddress(Offset.fromIntZeroExtend(VMHelper.VTABLE_CLASS_OFFSET));
 
         if (objClassType.EQ(castType)) {
             return true;
@@ -178,9 +164,7 @@
     }
 
 
-    private static native int getObjectVtableOffset();
     private static native int getVtableIntfTypeOffset(int n);
     private static native int getVtableIntfTableOffset(int n);
-    private static native int getVtableClassOffset();
     private static native int getVtableSuperclassesOffset();
 }

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMClassRegistry.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMClassRegistry.cpp?rev=617509&r1=617508&r2=617509&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMClassRegistry.cpp
(original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMClassRegistry.cpp
Fri Feb  1 06:43:01 2008
@@ -130,7 +130,7 @@
  * Method:    getClass
  * Signature: (Ljava/lang/Object;)Ljava/lang/Class;
  */
-JNIEXPORT jclass JNICALL Java_java_lang_VMClassRegistry_getClass
+JNIEXPORT jclass JNICALL Java_java_lang_VMClassRegistry_getClassNative
   (JNIEnv *jenv, jclass, jobject jobj)
 {
     // use JNI API function

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMClassRegistry.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMClassRegistry.h?rev=617509&r1=617508&r2=617509&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMClassRegistry.h
(original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMClassRegistry.h
Fri Feb  1 06:43:01 2008
@@ -45,10 +45,10 @@
     jstring);
 
 /*
- * Method: java.lang.VMClassRegistry.getClass(Ljava/lang/Object;)Ljava/lang/Class;
+ * Method: java.lang.VMClassRegistry.getClassNative(Ljava/lang/Object;)Ljava/lang/Class;
  */
 JNIEXPORT jclass JNICALL
-Java_java_lang_VMClassRegistry_getClass(JNIEnv *, jclass, 
+Java_java_lang_VMClassRegistry_getClassNative(JNIEnv *, jclass, 
     jobject);
 
 /*

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_drlvm_VMHelper.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_drlvm_VMHelper.cpp?rev=617509&r1=617508&r2=617509&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_drlvm_VMHelper.cpp
(original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_drlvm_VMHelper.cpp
Fri Feb  1 06:43:01 2008
@@ -59,3 +59,22 @@
         return -1;
     }
 }
+
+JNIEXPORT jint JNICALL Java_org_apache_harmony_drlvm_VMHelper_getObjectVtableOffset(JNIEnv
*e, jclass c)
+{
+    return object_get_vtable_offset();
+}
+
+JNIEXPORT jint JNICALL Java_org_apache_harmony_drlvm_VMHelper_getClassJLCHanldeOffset(JNIEnv
*e, jclass c)
+{
+   return (jint)Class::get_offset_of_jlc_handle();
+}
+
+JNIEXPORT jint JNICALL Java_org_apache_harmony_drlvm_VMHelper_getVtableClassOffset(JNIEnv
*e, jclass c)
+{
+    return static_cast<jint>(reinterpret_cast<jlong>(&((VTable*)0)->clss));
+}
+
+
+
+

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_drlvm_VMHelper.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_drlvm_VMHelper.h?rev=617509&r1=617508&r2=617509&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_drlvm_VMHelper.h
(original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_drlvm_VMHelper.h
Fri Feb  1 06:43:01 2008
@@ -47,6 +47,17 @@
   (JNIEnv *, jclass);
 
 
+JNIEXPORT jint JNICALL Java_org_apache_harmony_drlvm_VMHelper_getObjectVtableOffset
+  (JNIEnv *, jclass);
+
+
+JNIEXPORT jint JNICALL Java_org_apache_harmony_drlvm_VMHelper_getClassJLCHanldeOffset
+  (JNIEnv *, jclass);
+
+JNIEXPORT jint JNICALL Java_org_apache_harmony_drlvm_VMHelper_getVtableClassOffset
+  (JNIEnv *, jclass);
+
+
 #ifdef __cplusplus
 }
 #endif

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_drlvm_VMHelperFastPath.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_drlvm_VMHelperFastPath.cpp?rev=617509&r1=617508&r2=617509&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_drlvm_VMHelperFastPath.cpp
(original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_drlvm_VMHelperFastPath.cpp
Fri Feb  1 06:43:01 2008
@@ -23,10 +23,6 @@
 #include "open/vm.h"
 #include <assert.h>
 
-JNIEXPORT jint JNICALL Java_org_apache_harmony_drlvm_VMHelperFastPath_getObjectVtableOffset(JNIEnv
*e, jclass c)
-{
-    return object_get_vtable_offset();
-}
 
 JNIEXPORT jint JNICALL Java_org_apache_harmony_drlvm_VMHelperFastPath_getVtableIntfTypeOffset(JNIEnv
*e, jclass c, jint i)
 {
@@ -57,10 +53,6 @@
 #endif
 }
 
-JNIEXPORT jint JNICALL Java_org_apache_harmony_drlvm_VMHelperFastPath_getVtableClassOffset(JNIEnv
*e, jclass c)
-{
-    return static_cast<jint>(reinterpret_cast<jlong>(&((VTable*)0)->clss));
-}
 
 JNIEXPORT jint JNICALL Java_org_apache_harmony_drlvm_VMHelperFastPath_getVtableSuperclassesOffset(JNIEnv
*e, jclass c)
 {

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_drlvm_VMHelperFastPath.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_drlvm_VMHelperFastPath.h?rev=617509&r1=617508&r2=617509&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_drlvm_VMHelperFastPath.h
(original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_drlvm_VMHelperFastPath.h
Fri Feb  1 06:43:01 2008
@@ -28,13 +28,6 @@
 #endif
 
 
-/*
- * Class:     org_apache_harmony_drlvm_VMHelperFastPath
- * Method:    getObjectVtableOffset
- * Signature: ()I
- */
-JNIEXPORT jint JNICALL Java_org_apache_harmony_drlvm_VMHelperFastPath_getObjectVtableOffset
-  (JNIEnv *, jclass);
 
 /*
  * Class:     org_apache_harmony_drlvm_VMHelperFastPath
@@ -51,14 +44,6 @@
  */
 JNIEXPORT jint JNICALL Java_org_apache_harmony_drlvm_VMHelperFastPath_getVtableIntfTableOffset
   (JNIEnv *, jclass, jint);
-
-/*
- * Class:     org_apache_harmony_drlvm_VMHelperFastPath
- * Method:    getVtableClassOffset
- * Signature: ()I
- */
-JNIEXPORT jint JNICALL Java_org_apache_harmony_drlvm_VMHelperFastPath_getVtableClassOffset
-  (JNIEnv *, jclass);
 
 /*
  * Class:     org_apache_harmony_drlvm_VMHelperFastPath



Mime
View raw message