changeset 5875:000fb0550afe

Add an option to launch the vm from a debugger in mx's commands Differentiate between, 32 and 64 bits BSR
author Gilles Duboscq <duboscq@ssw.jku.at>
date Wed, 25 Jul 2012 13:06:52 +0200
parents f0d4304243ff
children c21886d4e125
files graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/jdk/IntegerBits.java graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/jdk/LongBits.java graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/nodes/BitScanForwardNode.java graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/nodes/BitScanReverseNode.java graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/target/amd64/AMD64BitScanOp.java graal/com.oracle.max.asm/src/com/oracle/max/asm/target/amd64/AMD64Assembler.java mx/commands.py
diffstat 7 files changed, 186 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/jdk/IntegerBits.java	Wed Jul 25 13:06:52 2012 +0200
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.graal.jtt.jdk;
+
+import org.junit.*;
+
+
+public class IntegerBits {
+    @SuppressWarnings("unused")
+    private static int init = Integer.reverseBytes(42);
+    private int original = 0x01020304;
+    private int reversed = 0x04030201;
+    private int v = 0b1000;
+    private int zero = 0;
+
+    public int test(int o) {
+        return Integer.reverseBytes(o);
+    }
+
+    public int test2(int o) {
+        return Integer.numberOfLeadingZeros(o);
+    }
+
+    public int test3(int o) {
+        return Integer.numberOfTrailingZeros(o);
+    }
+
+    @Test
+    public void run0() {
+        Assert.assertEquals(reversed, test(original));
+    }
+
+    @Test
+    public void run1() {
+        Assert.assertEquals(3, test3(v));
+    }
+
+    @Test
+    public void run2() {
+        Assert.assertEquals(28, test2(v));
+    }
+
+    @Test
+    public void run3() {
+        Assert.assertEquals(32, test3(zero));
+    }
+
+    @Test
+    public void run4() {
+        Assert.assertEquals(32, test2(zero));
+    }
+
+    @Test
+    public void run5() {
+        Assert.assertEquals(reversed, test(0x01020304));
+    }
+
+    @Test
+    public void run6() {
+        Assert.assertEquals(3, test3(0b1000));
+    }
+
+    @Test
+    public void run7() {
+        Assert.assertEquals(28, test2(0b1000));
+    }
+
+    @Test
+    public void run8() {
+        Assert.assertEquals(32, test3(0));
+    }
+
+    @Test
+    public void run9() {
+        Assert.assertEquals(32, test2(0));
+    }
+}
--- a/graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/jdk/LongBits.java	Tue Jul 24 17:32:42 2012 +0200
+++ b/graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/jdk/LongBits.java	Wed Jul 25 13:06:52 2012 +0200
@@ -31,6 +31,7 @@
     private long original = 0x0102030405060708L;
     private long reversed = 0x0807060504030201L;
     private long v = 0b1000L;
+    private long v2 = 0x0100000000L;
     private long zero = 0L;
 
     public long test(long o) {
@@ -94,4 +95,24 @@
     public void run9() {
         Assert.assertEquals(64, test2(0L));
     }
+
+    @Test
+    public void run10() {
+        Assert.assertEquals(31, test2(v2));
+    }
+
+    @Test
+    public void run11() {
+        Assert.assertEquals(32, test3(v2));
+    }
+
+    @Test
+    public void run12() {
+        Assert.assertEquals(31, test2(0x0100000000L));
+    }
+
+    @Test
+    public void run13() {
+        Assert.assertEquals(32, test3(0x0100000000L));
+    }
 }
--- a/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/nodes/BitScanForwardNode.java	Tue Jul 24 17:32:42 2012 +0200
+++ b/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/nodes/BitScanForwardNode.java	Wed Jul 25 13:06:52 2012 +0200
@@ -46,21 +46,16 @@
     public ValueNode canonical(CanonicalizerTool tool) {
         if (value.isConstant()) {
             long v = value.asConstant().asLong();
-            if (kind().isInt()) {
+            if (value.kind().isInt()) {
                 return ConstantNode.forInt(Integer.numberOfTrailingZeros((int) v), graph());
-            } else if (kind().isLong()) {
-                return ConstantNode.forLong(Long.numberOfTrailingZeros(v), graph());
+            } else if (value.kind().isLong()) {
+                return ConstantNode.forInt(Long.numberOfTrailingZeros(v), graph());
             }
         }
         return this;
     }
 
     @NodeIntrinsic
-    public static int scan(@SuppressWarnings("unused") int v) {
-        throw new UnsupportedOperationException("This method may only be compiled with the Graal compiler");
-    }
-
-    @NodeIntrinsic
     public static int scan(@SuppressWarnings("unused") long v) {
         throw new UnsupportedOperationException("This method may only be compiled with the Graal compiler");
     }
--- a/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/nodes/BitScanReverseNode.java	Tue Jul 24 17:32:42 2012 +0200
+++ b/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/nodes/BitScanReverseNode.java	Wed Jul 25 13:06:52 2012 +0200
@@ -25,6 +25,7 @@
 import com.oracle.graal.api.meta.*;
 import com.oracle.graal.compiler.gen.*;
 import com.oracle.graal.compiler.target.*;
+import com.oracle.graal.graph.*;
 import com.oracle.graal.lir.*;
 import com.oracle.graal.nodes.*;
 import com.oracle.graal.nodes.calc.*;
@@ -46,10 +47,10 @@
     public ValueNode canonical(CanonicalizerTool tool) {
         if (value.isConstant()) {
             long v = value.asConstant().asLong();
-            if (kind().isInt()) {
+            if (value.kind().isInt()) {
                 return ConstantNode.forInt(31 - Integer.numberOfLeadingZeros((int) v), graph());
-            } else if (kind().isLong()) {
-                return ConstantNode.forLong(63 - Long.numberOfLeadingZeros(v), graph());
+            } else if (value.kind().isLong()) {
+                return ConstantNode.forInt(63 - Long.numberOfLeadingZeros(v), graph());
             }
         }
         return this;
@@ -68,7 +69,15 @@
     @Override
     public void generate(LIRGenerator gen) {
         Variable result = gen.newVariable(Kind.Int);
-        gen.append(new AMD64BitScanOp(IntrinsicOpcode.BSR, result, gen.operand(value)));
+        IntrinsicOpcode opcode;
+        if (value.kind().isInt()) {
+            opcode = IntrinsicOpcode.IBSR;
+        } else if (value.kind().isLong()) {
+            opcode = IntrinsicOpcode.LBSR;
+        } else {
+            throw GraalInternalError.shouldNotReachHere();
+        }
+        gen.append(new AMD64BitScanOp(opcode, result, gen.operand(value)));
         gen.setResult(this, result);
     }
 
--- a/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/target/amd64/AMD64BitScanOp.java	Tue Jul 24 17:32:42 2012 +0200
+++ b/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/target/amd64/AMD64BitScanOp.java	Wed Jul 25 13:06:52 2012 +0200
@@ -31,8 +31,8 @@
 
 public class AMD64BitScanOp extends AMD64LIRInstruction {
     public enum IntrinsicOpcode  {
-        BSF,
-        BSR;
+        IBSR, LBSR,
+        BSF;
     }
 
     @Opcode private final IntrinsicOpcode opcode;
@@ -47,21 +47,33 @@
 
     @Override
     public void emitCode(TargetMethodAssembler tasm, AMD64MacroAssembler masm) {
-        switch(opcode) {
-            case BSF:
-                if (ValueUtil.isAddress(input)) {
-                    masm.bsfq(ValueUtil.asIntReg(result), ValueUtil.asAddress(input));
-                } else {
-                    masm.bsfq(ValueUtil.asIntReg(result), ValueUtil.asRegister(input));
-                }
-                break;
-            case BSR:
-                if (ValueUtil.isAddress(input)) {
-                    masm.bsrq(ValueUtil.asIntReg(result), ValueUtil.asAddress(input));
-                } else {
-                    masm.bsrq(ValueUtil.asIntReg(result), ValueUtil.asRegister(input));
-                }
-                break;
+        Register dst = ValueUtil.asIntReg(result);
+        if (ValueUtil.isAddress(input)) {
+            Address src = ValueUtil.asAddress(input);
+            switch(opcode) {
+                case BSF:
+                    masm.bsfq(dst, src);
+                    break;
+                case IBSR:
+                    masm.bsrl(dst, src);
+                    break;
+                case LBSR:
+                    masm.bsrq(dst, src);
+                    break;
+            }
+        } else {
+            Register src = ValueUtil.asRegister(input);
+            switch(opcode) {
+                case BSF:
+                    masm.bsfq(dst, src);
+                    break;
+                case IBSR:
+                    masm.bsrl(dst, src);
+                    break;
+                case LBSR:
+                    masm.bsrq(dst, src);
+                    break;
+            }
         }
     }
 
--- a/graal/com.oracle.max.asm/src/com/oracle/max/asm/target/amd64/AMD64Assembler.java	Tue Jul 24 17:32:42 2012 +0200
+++ b/graal/com.oracle.max.asm/src/com/oracle/max/asm/target/amd64/AMD64Assembler.java	Wed Jul 25 13:06:52 2012 +0200
@@ -446,6 +446,20 @@
         emitOperandHelper(dst, src);
     }
 
+    public final void bsrl(Register dst, Register src) {
+        int encode = prefixAndEncode(dst.encoding, src.encoding);
+        emitByte(0x0F);
+        emitByte(0xBD);
+        emitByte(0xC0 | encode);
+    }
+
+
+    public final void bsrl(Register dst, Address src) {
+        prefix(src, dst);
+        emitByte(0xBD);
+        emitOperandHelper(dst, src);
+    }
+
     public final void bswapl(Register reg) { // bswap
         int encode = prefixAndEncode(reg.encoding);
         emitByte(0x0F);
--- a/mx/commands.py	Tue Jul 24 17:32:42 2012 +0200
+++ b/mx/commands.py	Wed Jul 25 13:06:52 2012 +0200
@@ -49,6 +49,8 @@
 
 _jacoco = 'off'
 
+_native_dbg = None
+
 _make_eclipse_launch = False
 
 _copyrightTemplate = """/*
@@ -588,7 +590,8 @@
         }
         args = ['-javaagent:' + jacocoagent.get_path(True) + '=' + ','.join([k + '=' + v for k, v in agentOptions.items()])] + args
     exe = join(jdk, 'bin', mx.exe_suffix('java'))
-    return mx.run([exe, '-' + vm] + args, nonZeroIsFatal=nonZeroIsFatal, out=out, err=err, cwd=cwd, timeout=timeout)
+    dbg = _native_dbg.split() if _native_dbg is not None else []
+    return mx.run(dbg + [exe, '-' + vm] + args, nonZeroIsFatal=nonZeroIsFatal, out=out, err=err, cwd=cwd, timeout=timeout)
 
 def _find_classes_with_annotations(p, pkgRoot, annotations, includeInnerClasses=False):
     """
@@ -1006,6 +1009,9 @@
         mx.add_argument('--debug', action='store_const', dest='vmbuild', const='debug', help='select the debug build of the VM')
         mx.add_argument('--fastdebug', action='store_const', dest='vmbuild', const='fastdebug', help='select the fast debug build of the VM')
         mx.add_argument('--ecl', action='store_true', dest='make_eclipse_launch', help='create launch configuration for running VM execution(s) in Eclipse')
+        mx.add_argument('--native-dbg', action='store', dest='native_dbg', help='Start the vm inside a debugger', metavar='<debugger>')
+        mx.add_argument('--gdb', action='store_const', const='/usr/bin/gdb --args', dest='native_dbg', help='alias for --native-dbg /usr/bin/gdb -- args')
+        
 
         commands.update({
             'export': [export, '[-options] [zipfile]'],
@@ -1034,3 +1040,5 @@
         _make_eclipse_launch = getattr(opts, 'make_eclipse_launch', False)
     global _jacoco
     _jacoco = opts.jacoco
+    global _native_dbg
+    _native_dbg = opts.native_dbg