changeset 6482:f0db2c717f6e

modified NewArrayStubCall to use information provided by the (platform independent) backend instead of AMD64 specific nodes for linking the stub call
author Doug Simon <doug.simon@oracle.com>
date Tue, 02 Oct 2012 14:58:13 +0200
parents 6977b54ddba8
children e11b2c8f374b
files graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/NewArrayStubCall.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/target/HotSpotBackend.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/target/amd64/AMD64NewArrayStubCallOp.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/target/amd64/HotSpotAMD64Backend.java
diffstat 4 files changed, 38 insertions(+), 138 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/NewArrayStubCall.java	Tue Oct 02 14:17:40 2012 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/NewArrayStubCall.java	Tue Oct 02 14:58:13 2012 +0200
@@ -22,22 +22,16 @@
  */
 package com.oracle.graal.hotspot.nodes;
 
-import static com.oracle.graal.hotspot.target.amd64.AMD64NewArrayStubCallOp.*;
-
-import com.oracle.graal.api.code.*;
-import com.oracle.graal.api.meta.*;
 import com.oracle.graal.compiler.gen.*;
 import com.oracle.graal.compiler.target.*;
 import com.oracle.graal.hotspot.*;
-import com.oracle.graal.hotspot.target.amd64.*;
+import com.oracle.graal.hotspot.target.*;
 import com.oracle.graal.lir.*;
 import com.oracle.graal.nodes.*;
 import com.oracle.graal.nodes.type.*;
 
 /**
  * Node implementing a call to HotSpot's {@code new_[object|type]_array} stub.
- *
- * @see AMD64NewArrayStubCallOp
  */
 public class NewArrayStubCall extends FixedWithNextNode implements LIRGenLowerable {
 
@@ -66,14 +60,9 @@
 
     @Override
     public void generate(LIRGenerator gen) {
-        RegisterValue hubFixed = HUB.asValue(Kind.Object);
-        RegisterValue lengthFixed = LENGTH.asValue(Kind.Int);
-        RegisterValue resultFixed = RESULT.asValue(Kind.Object);
-        gen.emitMove(gen.operand(length), lengthFixed);
-        gen.emitMove(gen.operand(hub), hubFixed);
-        LIRFrameState info = gen.state();
-        gen.append(new AMD64NewArrayStubCallOp(isObjectArray, resultFixed, hubFixed, lengthFixed, info));
-        Variable result = gen.emitMove(resultFixed);
+        HotSpotBackend backend = (HotSpotBackend) HotSpotGraalRuntime.getInstance().getCompiler().backend;
+        HotSpotStub stub = backend.getStub(isObjectArray ? "new_object_array" : "new_type_array");
+        Variable result = gen.emitCall(stub.address, stub.cc, true, gen.operand(hub), gen.operand(length));
         gen.setResult(this, result);
     }
 
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/target/HotSpotBackend.java	Tue Oct 02 14:17:40 2012 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/target/HotSpotBackend.java	Tue Oct 02 14:58:13 2012 +0200
@@ -51,31 +51,19 @@
 
     /**
      * Registers the details for linking a global stub.
+     *
+     * @param name name of the stub
+     * @param address address of the stub
+     * @param tempRegs temporary registers used (and killed) by the stub (null if none)
+     * @param ret where the stub returns its result
+     * @param args where arguments are passed to the stub
      */
-    protected HotSpotStub addStub(String name, long address, CallingConvention cc) {
-        HotSpotStub stub = new HotSpotStub(name, address, cc);
-        stubsMap.put(name, stub);
-        return stub;
-    }
-
-    protected static Value reg(@SuppressWarnings("unused") String name, Register reg, Kind kind) {
-        return reg.asValue(kind);
-    }
-
-    protected static Register[] temps(Register... regs) {
-        return regs;
-    }
-
-    protected static CallingConvention cc(Value ret, Value... args) {
-        return new CallingConvention(0, ret, args);
-    }
-
-    protected static CallingConvention cc(Register[] tempRegs, Value ret, Value... args) {
-        Value[] temps = new Value[tempRegs.length];
+    protected void addStub(String name, long address, Register[] tempRegs, Value ret, Value... args) {
+        Value[] temps = tempRegs == null || tempRegs.length == 0 ? Value.NONE : new Value[tempRegs.length];
         for (int i = 0; i < temps.length; i++) {
             temps[i] = tempRegs[i].asValue();
         }
-        return new CallingConvention(temps, 0, ret, args);
+        HotSpotStub stub = new HotSpotStub(name, address, new CallingConvention(temps, 0, ret, args));
+        stubsMap.put(name, stub);
     }
-
 }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/target/amd64/AMD64NewArrayStubCallOp.java	Tue Oct 02 14:17:40 2012 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,98 +0,0 @@
-/*
- * Copyright (c) 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.hotspot.target.amd64;
-
-import static com.oracle.graal.api.code.ValueUtil.*;
-
-import com.oracle.graal.api.code.*;
-import com.oracle.graal.api.meta.*;
-import com.oracle.graal.hotspot.*;
-import com.oracle.graal.lir.*;
-import com.oracle.graal.lir.LIRInstruction.Opcode;
-import com.oracle.graal.lir.amd64.*;
-import com.oracle.graal.lir.asm.*;
-import com.oracle.max.asm.target.amd64.*;
-
-/**
- * LIR instruction for calling HotSpot's {@code new_[object|type]_array} stub. This stub is declared in c1_Runtime1.hpp
- * and implemented in Runtime1::generate_code_for() which is located in c1_Runtime1_x86.cpp.
- */
-@Opcode("NEW_ARRAY_STUB")
-public class AMD64NewArrayStubCallOp extends AMD64LIRInstruction {
-
-    /**
-     * The stub places the result in RAX.
-     */
-    public static final Register RESULT = AMD64.rax;
-
-    /**
-     * The stub expects the hub in RDX.
-     */
-    public static final Register HUB = AMD64.rdx;
-
-    /**
-     * The stub expects the length in RBX.
-     */
-    public static final Register LENGTH = AMD64.rbx;
-
-    /**
-     * The stub uses RCX, RSI, and RDI as temps.
-     */
-    public static final Register[] TEMPS = {AMD64.rcx, AMD64.rdi, AMD64.rsi};
-
-    private final boolean isObjectArray;
-
-    @Def protected Value result;
-    @Use protected Value hub;
-    @Use protected Value length;
-    @Temp protected Value[] temps;
-
-    @State protected LIRFrameState state;
-
-    public AMD64NewArrayStubCallOp(boolean isObjectArray, Value result, Value hub, Value length, LIRFrameState state) {
-        this.isObjectArray = isObjectArray;
-        this.result = result;
-        this.hub = hub;
-        this.length = length;
-        this.temps = new Value[TEMPS.length];
-        for (int i = 0; i < temps.length; i++) {
-            temps[i] = TEMPS[i].asValue(Kind.Long);
-        }
-        this.state = state;
-    }
-
-    @Override
-    public void emitCode(TargetMethodAssembler tasm, AMD64MacroAssembler masm) {
-        HotSpotVMConfig config = HotSpotGraalRuntime.getInstance().getConfig();
-        long stub = isObjectArray ? config.newObjectArrayStub : config.newTypeArrayStub;
-        AMD64Call.directCall(tasm, masm, stub, state);
-    }
-
-    @Override
-    protected void verify() {
-        super.verify();
-        assert asRegister(hub) == HUB : "stub expects hub in " + HUB;
-        assert asRegister(length) == LENGTH : "stub expect length in " + LENGTH;
-        assert asRegister(result) == RESULT : "stub places result in " + RESULT;
-    }
-}
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/target/amd64/HotSpotAMD64Backend.java	Tue Oct 02 14:17:40 2012 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/target/amd64/HotSpotAMD64Backend.java	Tue Oct 02 14:58:13 2012 +0200
@@ -61,9 +61,30 @@
         HotSpotVMConfig c = hs.config;
         Kind word = target.wordKind;
 
-        addStub("monitorenter", c.fastMonitorEnterStub, cc(temps(rax, rbx), IllegalValue, reg("object", rsi, Kind.Object), reg("lock", rdx, word)));
-        addStub("monitorexit", c.fastMonitorExitStub, cc(temps(rax, rbx), IllegalValue, reg("object", rsi, Kind.Object), reg("lock", rdx, word)));
-    }
+        addStub("monitorenter", c.fastMonitorEnterStub,
+                /*        temps */ new Register[] {rax, rbx},
+                /*          ret */ IllegalValue,
+                /* arg0: object */ rsi.asValue(Kind.Object),
+                /* arg1:   lock */ rdx.asValue(word));
+
+        addStub("monitorexit", c.fastMonitorExitStub,
+                /*        temps */ new Register[] {rax, rbx},
+                /*          ret */ IllegalValue,
+                /* arg0: object */ rsi.asValue(Kind.Object),
+                /* arg1:   lock */ rdx.asValue(word));
+
+        addStub("new_object_array", c.newObjectArrayStub,
+                /*        temps */ new Register[] {rcx, rdi, rsi},
+                /*          ret */ rax.asValue(Kind.Object),
+                /* arg0:    hub */ rdx.asValue(Kind.Object),
+                /* arg1: length */ rbx.asValue(Kind.Int));
+
+        addStub("new_type_array", c.newTypeArrayStub,
+                /*        temps */ new Register[] {rcx, rdi, rsi},
+                /*          ret */ rax.asValue(Kind.Object),
+                /* arg0:    hub */ rdx.asValue(Kind.Object),
+                /* arg1: length */ rbx.asValue(Kind.Int));
+}
 
     @Override
     public LIRGenerator newLIRGenerator(Graph graph, FrameMap frameMap, ResolvedJavaMethod method, LIR lir) {