harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From var...@apache.org
Subject svn commit: r536179 - in /harmony/enhanced/drlvm/trunk: src/test/regression/H3784/ vm/jitrino/src/jet/
Date Tue, 08 May 2007 12:40:33 GMT
Author: varlax
Date: Tue May  8 05:40:32 2007
New Revision: 536179

URL: http://svn.apache.org/viewvc?view=rev&rev=536179
Log:
Applied HARMONY-3784 [drlvm][jit][jet] Incorrect support of vmmagic types and object fields
in JET compiler

Added:
    harmony/enhanced/drlvm/trunk/src/test/regression/H3784/
    harmony/enhanced/drlvm/trunk/src/test/regression/H3784/Test.java
    harmony/enhanced/drlvm/trunk/src/test/regression/H3784/check.cpp   (with props)
    harmony/enhanced/drlvm/trunk/src/test/regression/H3784/run.test.xml
Modified:
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/cg_fld_arr.cpp
    harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/magics.cpp

Added: harmony/enhanced/drlvm/trunk/src/test/regression/H3784/Test.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/H3784/Test.java?view=auto&rev=536179
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/H3784/Test.java (added)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/H3784/Test.java Tue May  8 05:40:32 2007
@@ -0,0 +1,37 @@
+package org.apache.harmony.drlvm.tests.regression.h3784;
+
+import junit.framework.TestCase;
+import org.vmmagic.unboxed.*;
+
+public class Test extends TestCase {
+
+    static {
+        System.loadLibrary("check");
+    }
+
+    public static final Address staticField = Address.fromLong(getAddress());
+
+    public static final long staticVal = -1;
+    public static final Address staticField2 = Address.fromLong(staticVal);
+ 
+    public static void test1() {
+        boolean result = check(staticField.toLong());
+        assertTrue(result);
+    }
+
+
+    public static void test2() {
+        long val = staticField.toLong();
+        int ptrSize = getPointerSize();
+        if (ptrSize == 4) {
+            assertEquals((int)val, (int)staticVal);
+        } else {
+            assertTrue(ptrSize == 8);
+            assertEquals(val, staticVal);
+        }
+    }
+    
+    static native long    getAddress();
+    static native boolean check(long addr);
+    static native int     getPointerSize();
+}

Added: harmony/enhanced/drlvm/trunk/src/test/regression/H3784/check.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/H3784/check.cpp?view=auto&rev=536179
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/H3784/check.cpp (added)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/H3784/check.cpp Tue May  8 05:40:32 2007
@@ -0,0 +1,45 @@
+#include <jni.h>
+#include <assert.h>
+
+#ifndef _CHECK3784_
+#define _CHECK3784_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+static jlong lorig = (jlong)-1;
+static jint  iorig = (jint)-1;
+
+
+JNIEXPORT jint JNICALL 
+Java_org_apache_harmony_drlvm_tests_regression_h3784_Test_getPointerSize(JNIEnv *, jclass)
 {
+    return (jint)sizeof(void*);
+}
+
+JNIEXPORT jlong JNICALL 
+Java_org_apache_harmony_drlvm_tests_regression_h3784_Test_getAddress(JNIEnv *, jclass) 
+{
+    if (sizeof(void*)==4) {
+        return (jlong)iorig;
+    } 
+    assert(sizeof(void*)==8);
+    return lorig;
+}
+
+JNIEXPORT jboolean JNICALL 
+Java_org_apache_harmony_drlvm_tests_regression_h3784_Test_check(JNIEnv *, jclass, jlong val)

+{
+    if (sizeof(void*)==4) {
+        return iorig == (jint)val;
+    }
+    assert(sizeof(void*)==8);
+    return lorig == val;
+}
+
+
+#ifdef __cplusplus
+}
+#endif
+#endif

Propchange: harmony/enhanced/drlvm/trunk/src/test/regression/H3784/check.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/drlvm/trunk/src/test/regression/H3784/run.test.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/H3784/run.test.xml?view=auto&rev=536179
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/H3784/run.test.xml (added)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/H3784/run.test.xml Tue May  8 05:40:32
2007
@@ -0,0 +1,20 @@
+<project name="RUN HARMONY-3784 Regression Test">
+    <target name="run-test">
+        <run-junit-test 
+            test="org.apache.harmony.drlvm.tests.regression.h3784.Test"
+            vmarg="-Xem:jet">
+            <junit-element>
+              <sysproperty key="java.library.path" value="${reg.test.native.path}/H3784"/>
+            </junit-element>
+        </run-junit-test>
+
+        <!--run-junit-test 
+            test="org.apache.harmony.drlvm.tests.regression.h3784.Test"
+            vmarg="-Xem:opt">
+            <junit-element>
+              <sysproperty key="java.library.path" value="${reg.test.native.path}/H3784"/>
+            </junit-element>
+        </run-junit-test-->
+    </target>
+</project>
+

Modified: harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/cg_fld_arr.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/cg_fld_arr.cpp?view=diff&rev=536179&r1=536178&r2=536179
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/cg_fld_arr.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/cg_fld_arr.cpp Tue May  8 05:40:32 2007
@@ -234,12 +234,17 @@
         gen_call_throw(ci_helper_linkerr, rt_helper_throw_linking_exc, 0,
                        m_klass, jinst.op0, jinst.opcode);
     }
+    
+    bool fieldIsMagic = field_is_magic(fld);
+    if (fieldIsMagic) {
+        jt = iplatf;
+    }
 
-    if (!get && compilation_params.exe_notify_field_modification)  {
+    if (!get && compilation_params.exe_notify_field_modification && !fieldIsMagic)
 {
         gen_modification_watchpoint(opcode, jt, fld);
     }
 
-    if (!get) {
+    if (!get && ! fieldIsMagic) {
         gen_write_barrier(opcode, fld);
     }
 
@@ -265,7 +270,7 @@
     assert(is_ia32() || g_refs_squeeze);
     
 
-    if (get && compilation_params.exe_notify_field_access) {
+    if (get && compilation_params.exe_notify_field_access && !fieldIsMagic)
{
         gen_access_watchpoint(opcode, jt, fld);
     }
     
@@ -275,23 +280,32 @@
             // pop out ref
             vpop();
         }
-        if (!is_ia32() && g_refs_squeeze && jt == jobj) {
-            AR gr_base = valloc(jobj);
-            rlock(gr_base);
-            AR gr_ref = valloc(jobj);
-            rlock(gr_ref);
-            
-            Opnd where32(i32, where.base(), where.disp(), 
+        if (!is_ia32() && g_refs_squeeze && (jt == jobj || fieldIsMagic))
{
+            if (fieldIsMagic) {
+                AR gr_ref = valloc(jobj);
+                rlock(gr_ref);
+                Opnd obj(jobj, gr_ref);
+                mov(Opnd(jobj, gr_ref), where);
+                runlock(gr_ref);
+                vpush(obj);
+            } else {
+                AR gr_base = valloc(jobj);
+                rlock(gr_base);
+                AR gr_ref = valloc(jobj);
+                rlock(gr_ref);
+
+                Opnd where32(i32, where.base(), where.disp(), 
                               where.index(), where.scale());
-            mov(Opnd(i32, gr_ref), where32);
-            movp(gr_base, OBJ_BASE);
-            Opnd obj(jobj, gr_ref);
-            alu(alu_add, obj, Opnd(jobj, gr_base));
-            //
-            runlock(gr_ref);
-            runlock(gr_base);
-            //
-            vpush(obj);
+                mov(Opnd(i32, gr_ref), where32);
+                movp(gr_base, OBJ_BASE);
+                Opnd obj(jobj, gr_ref);
+                alu(alu_add, obj, Opnd(jobj, gr_base));
+                //
+                runlock(gr_ref);
+                runlock(gr_base);
+                //
+                vpush(obj);
+            }
         }
         else if (jt<i32) {
             AR gr = valloc(i32);
@@ -326,19 +340,23 @@
                           where.index(), where.scale());
         mov(where32, Opnd(ref));
     }
-    else if (!is_ia32() && g_refs_squeeze && jt == jobj) {
+    else if (!is_ia32() && g_refs_squeeze && (jt == jobj || fieldIsMagic))
{
         // have the reference on a register
         Val& s0 = vstack(0, true);
         rlock(s0);
-        // compress the reference
-        AR tmp = valloc(jobj);
-        void * inv_base = (void*)-(int_ptr)OBJ_BASE;
-        movp(tmp, inv_base);
-        alu(alu_add, Opnd(jobj, tmp), s0.as_opnd());
-        // store the resulting int32
-        Opnd where32(i32, where.base(), where.disp(), 
+        if (fieldIsMagic) {
+            mov(where, s0.as_opnd());
+        } else {
+            // compress the reference
+            AR tmp = valloc(jobj);
+            void * inv_base = (void*)-(int_ptr)OBJ_BASE;
+            movp(tmp, inv_base);
+            alu(alu_add, Opnd(jobj, tmp), s0.as_opnd());
+            // store the resulting int32
+            Opnd where32(i32, where.base(), where.disp(), 
                           where.index(), where.scale());
-        mov(where32, Opnd(jobj, tmp)); //s0.as_opnd(i32));
+            mov(where32, Opnd(jobj, tmp)); //s0.as_opnd(i32));
+        }
         runlock(s0);
     }
     else if (jt<i32) {

Modified: harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/magics.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/magics.cpp?view=diff&rev=536179&r1=536178&r2=536179
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/magics.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/jitrino/src/jet/magics.cpp Tue May  8 05:40:32 2007
@@ -54,21 +54,18 @@
     return is_magic(klass);
 }
 
-#ifdef _EM64T_ 
-// sizeof_jt & vstack_replace_top_opnd aren't used on EM64T
-#else
 static size_t sizeof_jt(jtype jt) {
     static size_t sizes[] =  { 
         1, //i8,
         2, //i16, 
         2, //u16,
-        8, //i64,
         4, //i32,
+        8, //i64,
         4, //flt32,
         8, //dbl64,
-        4, //jobj,
-        4, //jvoid,
-        4, //jretAddr,
+        sizeof(POINTER_SIZE_INT), //jobj,
+        sizeof(POINTER_SIZE_INT), //jvoid,
+        sizeof(POINTER_SIZE_INT), //jretAddr,
         0, //jtypes_count, 
     };
     size_t res= sizes[jt];
@@ -78,83 +75,86 @@
 
 /** creates new opnd with the specified type and generates move from old one to new one */
 static void vstack_replace_top_opnd(Compiler* c, jtype jt) {
-    Opnd before = c->vstack(0).as_opnd();
-    assert(sizeof_jt(jt) >= sizeof_jt(before.jt()) && sizeof(jt)<=32);
-    Opnd after(jt, c->valloc(jt));
-    c->mov(after, before);
-    c->vpop(); 
-    c->vpush(after);
+    Opnd src = c->vstack(0).as_opnd();
+    Opnd dst(jt, c->valloc(jt));
+
+    size_t dstSize = sizeof_jt(dst.jt());
+    size_t srcSize = sizeof_jt(src.jt());
+    assert((srcSize==4 || srcSize ==  8) && (dstSize == 4 || dstSize == 8));
+    if (srcSize == dstSize) { //simple mov
+        c->mov(dst, src);
+        c->vpop();  //pop src
+        c->vpush(dst);
+    } else if (srcSize > dstSize) { //truncation
+        c->do_mov(dst, src);
+        c->vpop(); //lo&hi parts are popped with a single pop operation for i64 type
+        c->vpush(dst); //push result
+    } else { // expansion
+        assert(srcSize<dstSize);
+        c->do_mov(dst, src); //fill lower part -> dst
+        Opnd hi(jt, c->g_iconst_0); //fill hi part with 0
+        c->vpop(); //pop old value
+        c->vpush2(dst, hi); //push new value
+    }
 }
-#endif //not em64t
 
 bool Compiler::gen_magic(void)
 {
-#ifdef _EM64T_ 
-    return false; //not tested
-#else
     const JInst& jinst = m_insts[m_pc];
-    if (jinst.opcode != OPCODE_INVOKEVIRTUAL && 
-        jinst.opcode != OPCODE_INVOKESTATIC &&
-        jinst.opcode != OPCODE_INVOKESPECIAL &&
-        jinst.opcode != OPCODE_NEW) {
+    JavaByteCodes opkod = jinst.opcode;
+
+    if (opkod != OPCODE_INVOKEVIRTUAL && 
+        opkod != OPCODE_INVOKESTATIC &&
+        opkod != OPCODE_INVOKESPECIAL)
+    {
         return false;
     }
     
-    if (jinst.opcode == OPCODE_NEW) {
-        // trying to create a magic instance ?
-        Class_Handle klass = NULL;
-        klass = vm_resolve_class_new(m_compileHandle, m_klass, jinst.op0);
-        if (klass == NULL || !is_magic(klass)) {
-            // not a magic - proceed as usual
-            return false;
-        }
-        // Create fake instance on the stack:
-        vpush(jobj);
-        vstack(0).set(VA_NZ);
-        return true;
-    }
-    //
-    //
-    //
-    JavaByteCodes opkod = jinst.opcode;
     vector<jtype> args;
     jtype retType;
     bool is_static = opkod == OPCODE_INVOKESTATIC;
     get_args_info(is_static, jinst.op0, args, &retType);
+
     Method_Handle meth = NULL;
     if (opkod == OPCODE_INVOKESTATIC) {
         meth = resolve_static_method(m_compileHandle, m_klass, jinst.op0);
-    } 
-    else if (opkod == OPCODE_INVOKEVIRTUAL) {
+    } else if (opkod == OPCODE_INVOKEVIRTUAL) {
         meth = resolve_virtual_method(m_compileHandle, m_klass, jinst.op0);
-    }
-    else {
+    } else {
         assert(opkod == OPCODE_INVOKESPECIAL);
         meth = resolve_special_method(m_compileHandle, m_klass, jinst.op0);
     }
     if (meth == NULL || !is_magic(meth)) {
         return false;
     }
-    //
-    // 
-    //
+
+    // This is a magic -> transform it
+
     const char* mname = method_get_name(meth);
-    //
-    // Construction
-    //
-    if (!strcmp(mname, "<init>")) {
-        // Currently only 'new <Magic>()' expected and handled
-        assert(args.size() == 1);
-        vpop();
+    jtype magicType = iplatf;
+
+    if (!strcmp(mname, "fromLong")) {
+        vstack_replace_top_opnd(this, magicType);
         return true;
     }
-    
-    //
+
+    if (!strcmp(mname, "toLong")) {
+        vstack_replace_top_opnd(this, i64);
+        return true;
+    }
+    return false;
+
+
+/**     Old IA32 implementation. This implementation is not GC safe, 
+        it keeps all magic classes as objects and magics becomes a part of GC enumeration
+        This code must be refactored or removed
+
+
     // ADD, SUB, DIFF, etc - 2 args arithmetics
     ALU oper = alu_count;
     
     if (!strcmp(mname, "add"))          { oper = alu_add; }
-    else if (!strcmp(mname, "plus"))          { oper = alu_add; }
+    else if (!strcmp(mname, "plus"))    { oper = alu_add; }
     else if (!strcmp(mname, "sub"))     { oper = alu_sub; }
     else if (!strcmp(mname, "minus"))     { oper = alu_sub; }
     else if (!strcmp(mname, "diff"))    { oper = alu_sub; }
@@ -267,10 +267,9 @@
     //
     // fromXXX - static creation from something
     //
-    if (!strcmp(mname, "fromInt")) {
-        vstack_replace_top_opnd(this, jobj);
-        return true;
-    }
+    if (strcmp(mname, "fromLong")) {
+        assert(0);
+    } 
     else if (!strcmp(mname, "fromIntSignExtend")) {
         vstack_replace_top_opnd(this, jobj);
         return true;
@@ -528,7 +527,7 @@
     //assert(false);
     return false;
 
-#endif //not em64t
+*/
 }
 
 }};             // ~namespace Jitrino::Jet



Mime
View raw message