changeset 9747:8e5461c4c82e

replaced NewMultiArrayStub use of ForeignCallStub
author Doug Simon <doug.simon@oracle.com>
date Thu, 16 May 2013 21:26:10 +0200
parents 82e3c8d5c77f
children 3e049a94d391
files graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/NewMultiArrayStubCall.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/ForeignCallStub.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewMultiArrayStub.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ForeignCallNode.java
diffstat 5 files changed, 35 insertions(+), 96 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java	Thu May 16 20:26:46 2013 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java	Thu May 16 21:26:10 2013 +0200
@@ -28,9 +28,9 @@
 import static com.oracle.graal.api.meta.DeoptimizationReason.*;
 import static com.oracle.graal.graph.UnsafeAccess.*;
 import static com.oracle.graal.hotspot.HotSpotBackend.*;
-import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*;
 import static com.oracle.graal.hotspot.HotSpotForeignCallLinkage.RegisterEffect.*;
 import static com.oracle.graal.hotspot.HotSpotForeignCallLinkage.Transition.*;
+import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*;
 import static com.oracle.graal.hotspot.nodes.MonitorEnterStubCall.*;
 import static com.oracle.graal.hotspot.nodes.MonitorExitStubCall.*;
 import static com.oracle.graal.hotspot.nodes.NewArrayStubCall.*;
@@ -48,7 +48,6 @@
 import static com.oracle.graal.hotspot.stubs.LogPrintfStub.*;
 import static com.oracle.graal.hotspot.stubs.NewArrayStub.*;
 import static com.oracle.graal.hotspot.stubs.NewInstanceStub.*;
-import static com.oracle.graal.hotspot.stubs.NewMultiArrayStub.*;
 import static com.oracle.graal.hotspot.stubs.OSRMigrationEndStub.*;
 import static com.oracle.graal.hotspot.stubs.StubUtil.*;
 import static com.oracle.graal.hotspot.stubs.ThreadIsInterruptedStub.*;
@@ -185,7 +184,7 @@
 
     protected HotSpotForeignCallLinkage register(HotSpotForeignCallLinkage linkage) {
         HotSpotForeignCallLinkage oldValue = foreignCalls.put(linkage.getDescriptor(), linkage);
-        assert oldValue == null;
+        assert oldValue == null : "already registered linkage for " + linkage.getDescriptor();
         return linkage;
     }
 
@@ -229,7 +228,6 @@
         registerStubCall(NEW_ARRAY);
         registerStubCall(UNWIND_EXCEPTION_TO_CALLER);
         registerStubCall(NEW_INSTANCE);
-        registerStubCall(NEW_MULTI_ARRAY);
         registerStubCall(LOG_PRIMITIVE);
         registerStubCall(LOG_PRINTF);
         registerStubCall(LOG_OBJECT);
@@ -252,7 +250,6 @@
         registerCRuntimeCall(EXCEPTION_HANDLER_FOR_RETURN_ADDRESS, c.exceptionHandlerForReturnAddressAddress);
         registerCRuntimeCall(NEW_ARRAY_C, c.newArrayAddress);
         registerCRuntimeCall(NEW_INSTANCE_C, c.newInstanceAddress);
-        registerCRuntimeCall(NEW_MULTI_ARRAY_C, c.newMultiArrayAddress);
         registerCRuntimeCall(LOG_PRIMITIVE_C, c.logPrimitiveAddress);
         registerCRuntimeCall(LOG_PRINTF_C, c.logObjectAddress);
         registerCRuntimeCall(VM_MESSAGE_C, c.vmMessageAddress);
@@ -294,7 +291,6 @@
         TargetDescription target = getTarget();
         link(new NewInstanceStub(this, replacements, target, foreignCalls.get(NEW_INSTANCE)));
         link(new NewArrayStub(this, replacements, target, foreignCalls.get(NEW_ARRAY)));
-        link(new NewMultiArrayStub(this, replacements, target, foreignCalls.get(NEW_MULTI_ARRAY)));
         link(new ThreadIsInterruptedStub(this, replacements, target, foreignCalls.get(THREAD_IS_INTERRUPTED)));
         link(new ExceptionHandlerStub(this, replacements, target, foreignCalls.get(EXCEPTION_HANDLER)));
         link(new UnwindExceptionToCallerStub(this, replacements, target, foreignCalls.get(UNWIND_EXCEPTION_TO_CALLER)));
@@ -313,6 +309,7 @@
         linkForeignCall(MONITOREXIT, config.monitorexitAddress, replacements);
         linkForeignCall(WRITE_BARRIER_PRE, config.writeBarrierPreAddress, replacements);
         linkForeignCall(WRITE_BARRIER_POST, config.writeBarrierPostAddress, replacements);
+        linkForeignCall(NEW_MULTI_ARRAY, config.newMultiArrayAddress, replacements);
     }
 
     private static void link(Stub stub) {
@@ -324,8 +321,8 @@
         HotSpotForeignCallLinkage linkage = stub.getLinkage();
         HotSpotForeignCallLinkage targetLinkage = stub.getTargetLinkage();
         linkage.setCompiledStub(stub);
-        foreignCalls.put(linkage.getDescriptor(), linkage);
-        foreignCalls.put(targetLinkage.getDescriptor(), targetLinkage);
+        register(linkage);
+        register(targetLinkage);
     }
 
     public HotSpotGraalRuntime getGraalRuntime() {
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/NewMultiArrayStubCall.java	Thu May 16 20:26:46 2013 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/NewMultiArrayStubCall.java	Thu May 16 21:26:10 2013 +0200
@@ -22,21 +22,18 @@
  */
 package com.oracle.graal.hotspot.nodes;
 
-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.meta.*;
-import com.oracle.graal.hotspot.stubs.*;
-import com.oracle.graal.lir.*;
 import com.oracle.graal.nodes.*;
+import com.oracle.graal.nodes.extended.*;
+import com.oracle.graal.nodes.spi.*;
 import com.oracle.graal.nodes.type.*;
 import com.oracle.graal.word.*;
 
 /**
- * Node implementing a call to {@link NewMultiArrayStub}.
+ * Node implementing a call to {@code GraalRuntime::new_multi_array}.
  */
-public class NewMultiArrayStubCall extends DeoptimizingStubCall implements LIRGenLowerable {
+public class NewMultiArrayStubCall extends ForeignCallNode {
 
     private static final Stamp defaultStamp = StampFactory.objectNonNull();
 
@@ -47,7 +44,7 @@
     public static final ForeignCallDescriptor NEW_MULTI_ARRAY = new ForeignCallDescriptor("new_multi_array", Object.class, Word.class, int.class, Word.class);
 
     public NewMultiArrayStubCall(ValueNode hub, int rank, ValueNode dims) {
-        super(defaultStamp);
+        super(NEW_MULTI_ARRAY, defaultStamp);
         this.hub = hub;
         this.rank = rank;
         this.dims = dims;
@@ -63,10 +60,8 @@
     }
 
     @Override
-    public void generate(LIRGenerator gen) {
-        ForeignCallLinkage linkage = gen.getRuntime().lookupForeignCall(NewMultiArrayStubCall.NEW_MULTI_ARRAY);
-        Variable result = gen.emitForeignCall(linkage, this, gen.operand(hub), Constant.forInt(rank), gen.operand(dims));
-        gen.setResult(this, result);
+    protected Value[] operands(LIRGeneratorTool gen) {
+        return new Value[]{gen.operand(hub), Constant.forInt(rank), gen.operand(dims)};
     }
 
     @NodeIntrinsic
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/ForeignCallStub.java	Thu May 16 20:26:46 2013 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/ForeignCallStub.java	Thu May 16 21:26:10 2013 +0200
@@ -71,15 +71,15 @@
      * Creates a stub for a call to code at a given address.
      * 
      * @param address the address of the code to call
-     * @param sig the signature of the call to this stub
+     * @param descriptor the signature of the call to this stub
      * @param prependThread true if the JavaThread value for the current thread is to be prepended
      *            to the arguments for the call to {@code address}
      */
-    public ForeignCallStub(long address, ForeignCallDescriptor sig, boolean prependThread, HotSpotRuntime runtime, Replacements replacements) {
-        super(runtime, replacements, HotSpotForeignCallLinkage.create(sig, 0L, PRESERVES_REGISTERS, JavaCallee, NOT_LEAF));
+    public ForeignCallStub(long address, ForeignCallDescriptor descriptor, boolean prependThread, HotSpotRuntime runtime, Replacements replacements) {
+        super(runtime, replacements, HotSpotForeignCallLinkage.create(descriptor, 0L, PRESERVES_REGISTERS, JavaCallee, NOT_LEAF));
         this.prependThread = prependThread;
-        Class[] targetParameterTypes = createTargetParameters(sig);
-        ForeignCallDescriptor targetSig = new ForeignCallDescriptor(sig.getName() + ":C", sig.getResultType(), targetParameterTypes);
+        Class[] targetParameterTypes = createTargetParameters(descriptor);
+        ForeignCallDescriptor targetSig = new ForeignCallDescriptor(descriptor.getName() + ":C", descriptor.getResultType(), targetParameterTypes);
         target = HotSpotForeignCallLinkage.create(targetSig, address, DESTROYS_REGISTERS, NativeCall, NOT_LEAF);
     }
 
@@ -90,8 +90,8 @@
         return target;
     }
 
-    private Class[] createTargetParameters(ForeignCallDescriptor sig) {
-        Class[] parameters = sig.getArgumentTypes();
+    private Class[] createTargetParameters(ForeignCallDescriptor descriptor) {
+        Class[] parameters = descriptor.getArgumentTypes();
         if (prependThread) {
             Class[] newParameters = new Class[parameters.length + 1];
             System.arraycopy(parameters, 0, newParameters, 1, parameters.length);
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewMultiArrayStub.java	Thu May 16 20:26:46 2013 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,60 +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.stubs;
-
-import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*;
-import static com.oracle.graal.hotspot.stubs.StubUtil.*;
-
-import com.oracle.graal.api.code.*;
-import com.oracle.graal.api.meta.*;
-import com.oracle.graal.graph.Node.ConstantNodeParameter;
-import com.oracle.graal.graph.Node.NodeIntrinsic;
-import com.oracle.graal.hotspot.*;
-import com.oracle.graal.hotspot.meta.*;
-import com.oracle.graal.hotspot.nodes.*;
-import com.oracle.graal.nodes.extended.*;
-import com.oracle.graal.nodes.spi.*;
-import com.oracle.graal.replacements.*;
-import com.oracle.graal.word.*;
-
-/**
- * Stub called from {@link NewMultiArrayStubCall}.
- */
-public class NewMultiArrayStub extends CRuntimeStub {
-
-    public NewMultiArrayStub(final HotSpotRuntime runtime, Replacements replacements, TargetDescription target, HotSpotForeignCallLinkage linkage) {
-        super(runtime, replacements, target, linkage);
-    }
-
-    @Snippet
-    private static Object newMultiArray(Word hub, int rank, Word dims) {
-        newMultiArrayC(NEW_MULTI_ARRAY_C, thread(), hub, rank, dims);
-        handlePendingException(true);
-        return verifyObject(getAndClearObjectResult(thread()));
-    }
-
-    public static final ForeignCallDescriptor NEW_MULTI_ARRAY_C = descriptorFor(NewMultiArrayStub.class, "newMultiArrayC");
-
-    @NodeIntrinsic(ForeignCallNode.class)
-    public static native void newMultiArrayC(@ConstantNodeParameter ForeignCallDescriptor newArrayC, Word thread, Word hub, int rank, Word dims);
-}
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ForeignCallNode.java	Thu May 16 20:26:46 2013 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ForeignCallNode.java	Thu May 16 21:26:10 2013 +0200
@@ -46,27 +46,34 @@
         this.descriptor = descriptor;
     }
 
+    protected ForeignCallNode(ForeignCallDescriptor descriptor, Stamp stamp) {
+        super(stamp);
+        this.arguments = new NodeInputList<>(this);
+        this.descriptor = descriptor;
+    }
+
     public ForeignCallDescriptor getDescriptor() {
         return descriptor;
     }
 
-    public NodeInputList<ValueNode> arguments() {
-        return arguments;
-    }
-
     @Override
     public LocationIdentity[] getLocationIdentities() {
         return new LocationIdentity[]{LocationNode.ANY_LOCATION};
     }
 
+    protected Value[] operands(LIRGeneratorTool gen) {
+        Value[] operands = new Value[arguments.size()];
+        for (int i = 0; i < operands.length; i++) {
+            operands[i] = gen.operand(arguments.get(i));
+        }
+        return operands;
+    }
+
     @Override
     public void generate(LIRGeneratorTool gen) {
         ForeignCallLinkage linkage = gen.getRuntime().lookupForeignCall(descriptor);
-        Value[] args = new Value[arguments.size()];
-        for (int i = 0; i < args.length; i++) {
-            args[i] = gen.operand(arguments.get(i));
-        }
-        Value result = gen.emitForeignCall(linkage, this, args);
+        Value[] operands = operands(gen);
+        Value result = gen.emitForeignCall(linkage, this, operands);
         if (result != null) {
             gen.setResult(this, result);
         }