harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wjwashb...@apache.org
Subject svn commit: r465093 - in /incubator/harmony/enhanced/drlvm/trunk/vm: jitrino/src/jet/ vmcore/src/util/ia32/base/
Date Tue, 17 Oct 2006 23:19:25 GMT
Author: wjwashburn
Date: Tue Oct 17 16:19:24 2006
New Revision: 465093

URL: http://svn.apache.org/viewvc?view=rev&rev=465093
Log:
HARMONY-1785, Jitrino.JET write barrier for garbage collector written in C

Modified:
    incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/cg.h
    incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/cg_fld_arr.cpp
    incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/cg_instr.cpp
    incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/cg_meth.cpp
    incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/compiler.cpp
    incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/jet.cpp
    incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/ia32/base/jit_runtime_support_ia32.cpp

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/cg.h
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/cg.h?view=diff&rev=465093&r1=465092&r2=465093
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/cg.h (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/cg.h Tue Oct 17 16:19:24 2006
@@ -457,6 +457,16 @@
      * For debugging only.
      */
     void gen_dbg_rt(bool save_regs, const char * fmt, ...);
+
+    
+    /**
+     * The opcode may be one of AASTORE, PUTFIELD or PUTSTATIC.
+     *
+     * For AASTORE \c fieldHandle must be \b NULL.
+     */
+    void gen_write_barrier(JavaByteCodes opcode, Field_Handle fieldHandle);
+
+
     /**
      * @brief Prints out an argument's (or return value's) type and value.
      *

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/cg_fld_arr.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/cg_fld_arr.cpp?view=diff&rev=465093&r1=465092&r2=465093
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/cg_fld_arr.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/cg_fld_arr.cpp Tue Oct 17 16:19:24
2006
@@ -129,6 +129,7 @@
     vunref(jt);
     // stack: [.., aref, idx, val]
     if (jt == jobj && helperOk) {
+        gen_write_barrier(m_curr_inst->opcode, NULL);
         static const CallSig cs_aastore(CCONV_HELPERS, jobj, i32, jobj);
         unsigned stackFix = gen_stack_to_args(true, cs_aastore, 0);
 #ifdef _EM64T_
@@ -237,6 +238,11 @@
     if (!get && compilation_params.exe_notify_field_modification)  {
         gen_modification_watchpoint(opcode, jt, fld);
     }
+
+    if (!get) {
+        gen_write_barrier(opcode, fld);
+    }
+
     
     Opnd where;
     if (field_op) {

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/cg_instr.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/cg_instr.cpp?view=diff&rev=465093&r1=465092&r2=465093
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/cg_instr.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/cg_instr.cpp Tue Oct 17 16:19:24
2006
@@ -25,6 +25,7 @@
  
 #include "cg.h"
 #include "trace.h"
+#include "jit_runtime_support.h"
 
 namespace Jitrino {
 namespace Jet {
@@ -297,4 +298,141 @@
 //
 }
 
+void CodeGen::gen_write_barrier(JavaByteCodes opcode, Field_Handle fieldHandle)
+{
+    //
+    // TODO: the WB implementation is expected to perform the write
+    // so, we can skip the code e.g. AASTORE after the succesfull
+    // write barrier.
+    //
+    const bool doGenWB4J = get_bool_arg("wb4j", false);
+    const bool doGenWB4C = get_bool_arg("wb4c", false);
+
+    bool doWB = compilation_params.exe_insert_write_barriers;
+    doWB = doWB || doGenWB4J || doGenWB4C;
+    
+    // No request to generate WBs - nothing to do
+    if (!doWB) {
+        return;
+    }
+
+    if (doGenWB4J && doGenWB4C) {
+        // Can't have both 
+        assert(false);
+        return;
+    }
+
+    if (doGenWB4J) {
+        assert(false && "Sorry, not implemented yet.");
+        return;
+    }
+    
+    if (m_jframe->top() != jobj) {
+        // Item on top is not Object - GC does not care, nothing to do.
+        return;
+    }
+
+    if ((opcode == OPCODE_PUTFIELD || opcode == OPCODE_PUTSTATIC) && 
+         fieldHandle == NULL) {
+        // Resolution error ? - nothing to report
+        return;
+    }
+    const bool wb4c_skip_statics = get_bool_arg("wb4c.skip_statics", true);
+    if (doGenWB4C && (opcode == OPCODE_PUTSTATIC) && wb4c_skip_statics) {
+        // Currently, in DRLVM, statics are allocated outside of GC heap, 
+        // no need to report them
+        return;        
+    }
+
+    // WB4C has the following signature:
+    //(object written to, slot written to, value written to slot)
+    static const CallSig wb4c_sig(CCONV_CDECL, jobj, jobj, jobj);
+    //static char* wb4c_helper = xxx_gc_heap_slot_write_ref
+    static char* wb4c_helper = (char*)vm_get_rt_support_addr(VM_RT_GC_HEAP_WRITE_REF);
+
+    if (doGenWB4C && (NULL == wb4c_helper)) {
+        // WB4C requested, but VM knows nothing about such helper
+        assert(false);
+        return;
+    }
+    // WB4J has the following signature:
+    //(object written to, slot written to, value written to slot, metaA, metaB, mode)
+    static const CallSig wb4j_sig(CCONV_CDECL, jobj, jobj, jobj, i32, i32, i32);
+    static char* wb4j_helper = NULL;
+    
+    const CallSig& csig = doGenWB4C ? wb4c_sig : wb4j_sig;
+    void* wb_helper = doGenWB4C ? wb4c_helper : wb4j_helper;
+    
+    Val baseObject, slotAddress, value;
+    // operand stack for ASTORE:    arr, idx, ref
+    // operand stack for PUTFIELD:  base, ref
+    // operand stack for PUTSTATIC: ref
+    rlock(csig);
+    if (is_set(DBG_TRACE_CG)) { dbg(";;> write.barrier\n"); }
+    
+    int mode = -1;
+    
+    if (opcode == OPCODE_PUTFIELD) {
+        //
+        mode = 0;
+        //
+        unsigned f_offset = field_get_offset(fieldHandle);
+        baseObject = vstack(1, true);
+        rlock(baseObject);
+        slotAddress = Val(jobj, valloc(jobj));
+        Opnd address(jobj, baseObject.reg(), f_offset);
+        lea(slotAddress.as_opnd(), address);
+        rlock(slotAddress);
+    }
+    else if (opcode == OPCODE_PUTSTATIC) {
+        //
+        mode = 1;
+        //
+        baseObject = Val(jobj, NULL_REF);
+        rlock(baseObject);
+        void* fieldAddress = field_get_addr(fieldHandle);
+        slotAddress = Opnd(jobj, (jlong)(int_ptr)fieldAddress);
+        rlock(slotAddress);
+    }
+    else if (opcode == OPCODE_AASTORE) {
+        //
+        mode = 2;
+        //
+        baseObject = vstack(2, true);
+        rlock(baseObject);
+        
+        const Val& idx = vstack(1, vis_mem(1));
+        
+        AR base = baseObject.reg();
+        jtype jt = jobj;
+        int disp = jtypes[jt].rt_offset + (idx.is_imm() ? jtypes[jt].size*idx.ival() : 0);
+        AR index = idx.is_imm() ? ar_x : idx.reg();
+        unsigned scale = idx.is_imm() ? 0 : jtypes[jt].size;
+        slotAddress = Val(jobj, valloc(jobj));
+        Opnd address(jobj, base, disp, index, scale);
+        lea(slotAddress.as_opnd(), address);
+        rlock(slotAddress);
+    }
+    else {
+        // must not happen
+        assert(false);
+        return;
+    }
+
+    value = vstack(0);
+    runlock(slotAddress);
+    runlock(baseObject);
+    
+    Val modeArg((int)mode);
+    Val metaAArg((int)0);
+    Val metaBArg((int)0);
+    
+    gen_args(csig, 0, &baseObject, &slotAddress, &value,  &metaAArg, &metaBArg,
&modeArg);
+    // according to contract with CG guys, the WB code neither 
+    // throws an exception nor may lead to GC - may use gen_call_novm.
+    runlock(csig);
+//gen_brk();
+    gen_call_novm(csig, wb_helper, csig.count());
+    if (is_set(DBG_TRACE_CG)) { dbg(";;> ~write.barrier\n"); }
+}
 }}; // ~namespace Jitrino::Jet

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/cg_meth.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/cg_meth.cpp?view=diff&rev=465093&r1=465092&r2=465093
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/cg_meth.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/cg_meth.cpp Tue Oct 17 16:19:24
2006
@@ -845,6 +845,14 @@
     
     const Val* args[] = {parg0, parg1, parg2, parg3, parg4, parg5, parg6};
     unsigned steps = min((int)COUNTOF(args), (int)cs.count()-(int)idx);
+    // 1st, lock'em all
+    for (unsigned i=0; i<steps; i++) {
+        if (args[i] == 0) {
+            break;
+        }
+        rlock(*args[0]);
+    }
+    // 2nd, generate moves
     for (unsigned i=0; i<steps; i++) {
         if (args[i] == 0) {
             break;
@@ -852,6 +860,8 @@
         unsigned id = idx + i;
         Opnd arg = cs.get(id);
         do_mov(arg, *args[i]);
+        // 3d, unlock when not needed anymore
+        runlock(*args[0]);
     }
 }
 

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/compiler.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/compiler.cpp?view=diff&rev=465093&r1=465092&r2=465093
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/compiler.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/compiler.cpp Tue Oct 17 16:19:24
2006
@@ -432,7 +432,7 @@
     }
 
     const unsigned total_code_size = m_codeStream.size();
-        
+
     if (m_bEmulation) {
         m_vmCode = (char*)malloc(total_code_size);
     }

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/jet.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/jet.cpp?view=diff&rev=465093&r1=465092&r2=465093
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/jet.cpp (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/jet.cpp Tue Oct 17 16:19:24
2006
@@ -286,6 +286,22 @@
  "Note: you may need to pass -XcleanupOnExit to VM to view the stats.   \n"
 },
 #endif  // ~JIT_STATS
+
+{"wb4c", 
+ "type: bool; default: off; scope: method                               \n"
+ "Generates code with write barriers (C-based GC).                      \n"
+
+},
+{"wb4c.skip_statics", 
+"type: bool; default: TRUE; scope: method                               \n"
+"If true (default) then do NOT report PUTSTATIC into write barrier.     \n"
+},
+
+{"wb4j", 
+"type: bool; default: off; scope: method                                \n"
+"Generates code with write barriers (Java-based GC).                    \n"
+},
+
 //-------------------------------------------------------------------------
 // "                                                                      \n"
 // "                                                                      \n"

Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/ia32/base/jit_runtime_support_ia32.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/ia32/base/jit_runtime_support_ia32.cpp?view=diff&rev=465093&r1=465092&r2=465093
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/ia32/base/jit_runtime_support_ia32.cpp
(original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/ia32/base/jit_runtime_support_ia32.cpp
Tue Oct 17 16:19:24 2006
@@ -1246,7 +1246,8 @@
     case VM_RT_IREM:
     case VM_RT_CHAR_ARRAYCOPY_NO_EXC:
         return get_generic_rt_support_addr_ia32(f);
-
+    case VM_RT_GC_HEAP_WRITE_REF:
+        return (void*)gc_heap_slot_write_ref;
     default:
         ABORT("Unexpected helper id");
         return 0;



Mime
View raw message