annotate graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nfi/NativeCallStubGraphBuilder.java @ 18513:8b87897f5b42

introduced HotSpotGraalRuntimeProvder interface
author Doug Simon <doug.simon@oracle.com>
date Wed, 26 Nov 2014 09:38:46 +0100
parents f0a8b72315c1
children d138867d61c4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13837
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
1 /*
18187
9619ba4daf4c Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents: 16895
diff changeset
2 * Copyright (c) 2014, 2014, Oracle and/or its affiliates. All rights reserved.
13837
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
4 *
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
7 * published by the Free Software Foundation.
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
8 *
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
13 * accompanied this code).
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
14 *
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
18 *
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
21 * questions.
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
22 */
13895
4731c1a0b1f3 consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents: 13872
diff changeset
23 package com.oracle.graal.hotspot.nfi;
4731c1a0b1f3 consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents: 13872
diff changeset
24
4731c1a0b1f3 consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents: 13872
diff changeset
25 import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*;
13837
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
26
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
27 import java.util.*;
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
28
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
29 import com.oracle.graal.api.meta.*;
15193
96bb07a5d667 Spit up and move GraalInternalError.
Josef Eisl <josef.eisl@jku.at>
parents: 15040
diff changeset
30 import com.oracle.graal.compiler.common.*;
15198
2c0cfbf454b5 Move LIRTypeTool and Stamp to graal.compiler.common.
Josef Eisl <josef.eisl@jku.at>
parents: 15193
diff changeset
31 import com.oracle.graal.compiler.common.type.*;
13837
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
32 import com.oracle.graal.hotspot.meta.*;
18401
e7ab82e7cc37 Move metaspace pointer handling to hotspot specific WordTypeRewriter.
Roland Schatz <roland.schatz@oracle.com>
parents: 18187
diff changeset
33 import com.oracle.graal.hotspot.word.*;
13837
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
34 import com.oracle.graal.nodes.*;
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
35 import com.oracle.graal.nodes.extended.*;
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
36 import com.oracle.graal.nodes.java.*;
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
37 import com.oracle.graal.nodes.virtual.*;
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
38
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
39 /**
13895
4731c1a0b1f3 consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents: 13872
diff changeset
40 * Utility creating a graph for a stub used to call a native function.
13837
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
41 */
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
42 public class NativeCallStubGraphBuilder {
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
43
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
44 /**
13895
4731c1a0b1f3 consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents: 13872
diff changeset
45 * Creates a graph for a stub used to call a native function.
15040
288c23143d47 Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents: 15018
diff changeset
46 *
13895
4731c1a0b1f3 consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents: 13872
diff changeset
47 * @param functionPointer a native function pointer
13837
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
48 * @param returnType the type of the return value
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
49 * @param argumentTypes the types of the arguments
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
50 * @return the graph that represents the call stub
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
51 */
15040
288c23143d47 Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents: 15018
diff changeset
52 public static StructuredGraph getGraph(HotSpotProviders providers, RawNativeCallNodeFactory factory, long functionPointer, Class<?> returnType, Class<?>... argumentTypes) {
13837
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
53 try {
13895
4731c1a0b1f3 consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents: 13872
diff changeset
54 ResolvedJavaMethod method = providers.getMetaAccess().lookupJavaMethod(NativeCallStubGraphBuilder.class.getMethod("libCall", Object.class, Object.class, Object.class));
13837
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
55 StructuredGraph g = new StructuredGraph(method);
16895
06c15e88d383 added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents: 16551
diff changeset
56 ParameterNode arg0 = g.unique(ParameterNode.create(0, StampFactory.forKind(Kind.Object)));
06c15e88d383 added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents: 16551
diff changeset
57 ParameterNode arg1 = g.unique(ParameterNode.create(1, StampFactory.forKind(Kind.Object)));
06c15e88d383 added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents: 16551
diff changeset
58 ParameterNode arg2 = g.unique(ParameterNode.create(2, StampFactory.forKind(Kind.Object)));
06c15e88d383 added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents: 16551
diff changeset
59 FrameState frameState = g.add(FrameState.create(null, method, 0, Arrays.asList(new ValueNode[]{arg0, arg1, arg2}), 3, 0, false, false, new ArrayList<MonitorIdNode>(),
13837
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
60 new ArrayList<EscapeObjectState>()));
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
61 g.start().setStateAfter(frameState);
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
62 List<ValueNode> parameters = new ArrayList<>();
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
63 FixedWithNextNode fixedWithNext = getParameters(g, arg0, argumentTypes.length, argumentTypes, parameters, providers);
18187
9619ba4daf4c Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents: 16895
diff changeset
64 JavaConstant functionPointerNode = JavaConstant.forLong(functionPointer);
13837
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
65
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
66 ValueNode[] arguments = new ValueNode[parameters.size()];
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
67
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
68 for (int i = 0; i < arguments.length; i++) {
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
69 arguments[i] = parameters.get(i);
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
70 }
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
71
13895
4731c1a0b1f3 consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents: 13872
diff changeset
72 FixedWithNextNode callNode = g.add(factory.createRawCallNode(getKind(returnType), functionPointerNode, arguments));
13837
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
73
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
74 if (fixedWithNext == null) {
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
75 g.start().setNext(callNode);
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
76 } else {
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
77 fixedWithNext.setNext(callNode);
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
78 }
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
79
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
80 // box result
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
81 BoxNode boxedResult;
14633
da2431cc1506 Rename ValueNode kind() to getKind().
Josef Eisl <josef.eisl@jku.at>
parents: 13905
diff changeset
82 if (callNode.getKind() != Kind.Void) {
da2431cc1506 Rename ValueNode kind() to getKind().
Josef Eisl <josef.eisl@jku.at>
parents: 13905
diff changeset
83 if (callNode.getKind() == Kind.Object) {
13895
4731c1a0b1f3 consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents: 13872
diff changeset
84 throw new IllegalArgumentException("Return type not supported: " + returnType.getName());
4731c1a0b1f3 consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents: 13872
diff changeset
85 }
14633
da2431cc1506 Rename ValueNode kind() to getKind().
Josef Eisl <josef.eisl@jku.at>
parents: 13905
diff changeset
86 ResolvedJavaType type = providers.getMetaAccess().lookupJavaType(callNode.getKind().toBoxedJavaClass());
16895
06c15e88d383 added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents: 16551
diff changeset
87 boxedResult = g.unique(BoxNode.create(callNode, type, callNode.getKind()));
13837
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
88 } else {
16895
06c15e88d383 added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents: 16551
diff changeset
89 boxedResult = g.unique(BoxNode.create(ConstantNode.forLong(0, g), providers.getMetaAccess().lookupJavaType(Long.class), Kind.Long));
13837
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
90 }
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
91
16895
06c15e88d383 added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents: 16551
diff changeset
92 ReturnNode returnNode = g.add(ReturnNode.create(boxedResult));
13837
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
93 callNode.setNext(returnNode);
18465
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18401
diff changeset
94 (new HotSpotWordTypeRewriterPhase(providers.getMetaAccess(), providers.getSnippetReflection(), providers.getConstantReflection(), Kind.Long)).apply(g);
13837
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
95 return g;
13895
4731c1a0b1f3 consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents: 13872
diff changeset
96 } catch (NoSuchMethodException e) {
13837
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
97 throw GraalInternalError.shouldNotReachHere("Call Stub method not found");
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
98 }
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
99 }
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
100
15040
288c23143d47 Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents: 15018
diff changeset
101 private static FixedWithNextNode getParameters(StructuredGraph g, ParameterNode argumentsArray, int numArgs, Class<?>[] argumentTypes, List<ValueNode> args, HotSpotProviders providers) {
13895
4731c1a0b1f3 consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents: 13872
diff changeset
102 assert numArgs == argumentTypes.length;
4731c1a0b1f3 consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents: 13872
diff changeset
103 FixedWithNextNode last = null;
13837
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
104 for (int i = 0; i < numArgs; i++) {
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
105 // load boxed array element:
16895
06c15e88d383 added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents: 16551
diff changeset
106 LoadIndexedNode boxedElement = g.add(LoadIndexedNode.create(argumentsArray, ConstantNode.forInt(i, g), Kind.Object));
13837
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
107 if (i == 0) {
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
108 g.start().setNext(boxedElement);
13895
4731c1a0b1f3 consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents: 13872
diff changeset
109 last = boxedElement;
13837
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
110 } else {
13895
4731c1a0b1f3 consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents: 13872
diff changeset
111 last.setNext(boxedElement);
4731c1a0b1f3 consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents: 13872
diff changeset
112 last = boxedElement;
13837
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
113 }
15040
288c23143d47 Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents: 15018
diff changeset
114 Class<?> type = argumentTypes[i];
13895
4731c1a0b1f3 consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents: 13872
diff changeset
115 Kind kind = getKind(type);
4731c1a0b1f3 consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents: 13872
diff changeset
116 if (kind == Kind.Object) {
13837
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
117 // array value
13895
4731c1a0b1f3 consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents: 13872
diff changeset
118 Kind arrayElementKind = getElementKind(type);
13837
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
119 LocationIdentity locationIdentity = NamedLocationIdentity.getArrayLocation(arrayElementKind);
18513
8b87897f5b42 introduced HotSpotGraalRuntimeProvder interface
Doug Simon <doug.simon@oracle.com>
parents: 18465
diff changeset
120 int displacement = runtime().getArrayBaseOffset(arrayElementKind);
13895
4731c1a0b1f3 consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents: 13872
diff changeset
121 ConstantNode index = ConstantNode.forInt(0, g);
18513
8b87897f5b42 introduced HotSpotGraalRuntimeProvder interface
Doug Simon <doug.simon@oracle.com>
parents: 18465
diff changeset
122 int indexScaling = runtime().getArrayIndexScale(arrayElementKind);
13895
4731c1a0b1f3 consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents: 13872
diff changeset
123 IndexedLocationNode locationNode = IndexedLocationNode.create(locationIdentity, arrayElementKind, displacement, index, g, indexScaling);
4731c1a0b1f3 consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents: 13872
diff changeset
124 Stamp wordStamp = StampFactory.forKind(providers.getCodeCache().getTarget().wordKind);
16895
06c15e88d383 added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents: 16551
diff changeset
125 ComputeAddressNode arrayAddress = g.unique(ComputeAddressNode.create(boxedElement, locationNode, wordStamp));
13837
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
126 args.add(arrayAddress);
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
127 } else {
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
128 // boxed primitive value
13895
4731c1a0b1f3 consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents: 13872
diff changeset
129 try {
4731c1a0b1f3 consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents: 13872
diff changeset
130 ResolvedJavaField field = providers.getMetaAccess().lookupJavaField(kind.toBoxedJavaClass().getDeclaredField("value"));
16895
06c15e88d383 added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents: 16551
diff changeset
131 LoadFieldNode loadFieldNode = g.add(LoadFieldNode.create(boxedElement, field));
13895
4731c1a0b1f3 consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents: 13872
diff changeset
132 last.setNext(loadFieldNode);
4731c1a0b1f3 consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents: 13872
diff changeset
133 last = loadFieldNode;
4731c1a0b1f3 consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents: 13872
diff changeset
134 args.add(loadFieldNode);
4731c1a0b1f3 consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents: 13872
diff changeset
135 } catch (NoSuchFieldException e) {
4731c1a0b1f3 consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents: 13872
diff changeset
136 throw new GraalInternalError(e);
4731c1a0b1f3 consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents: 13872
diff changeset
137 }
13837
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
138 }
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
139 }
13895
4731c1a0b1f3 consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents: 13872
diff changeset
140 return last;
13837
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
141 }
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
142
15040
288c23143d47 Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents: 15018
diff changeset
143 public static Kind getElementKind(Class<?> clazz) {
288c23143d47 Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents: 15018
diff changeset
144 Class<?> componentType = clazz.getComponentType();
13895
4731c1a0b1f3 consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents: 13872
diff changeset
145 if (componentType == null) {
4731c1a0b1f3 consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents: 13872
diff changeset
146 throw new IllegalArgumentException("Parameter type not supported: " + clazz);
13837
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
147 }
13895
4731c1a0b1f3 consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents: 13872
diff changeset
148 if (componentType.isPrimitive()) {
13905
3089e9a7cf44 fixed bug in passing primitive arrays through native function handles
Doug Simon <doug.simon@oracle.com>
parents: 13895
diff changeset
149 return Kind.fromJavaClass(componentType);
13837
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
150 }
13895
4731c1a0b1f3 consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents: 13872
diff changeset
151 throw new IllegalArgumentException("Parameter type not supported: " + clazz);
13837
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
152 }
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
153
15040
288c23143d47 Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents: 15018
diff changeset
154 private static Kind getKind(Class<?> clazz) {
13837
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
155 if (clazz == int.class || clazz == Integer.class) {
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
156 return Kind.Int;
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
157 } else if (clazz == long.class || clazz == Long.class) {
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
158 return Kind.Long;
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
159 } else if (clazz == char.class || clazz == Character.class) {
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
160 return Kind.Char;
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
161 } else if (clazz == byte.class || clazz == Byte.class) {
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
162 return Kind.Byte;
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
163 } else if (clazz == float.class || clazz == Float.class) {
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
164 return Kind.Float;
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
165 } else if (clazz == double.class || clazz == Double.class) {
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
166 return Kind.Double;
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
167 } else if (clazz == int[].class || clazz == long[].class || clazz == char[].class || clazz == byte[].class || clazz == float[].class || clazz == double[].class) {
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
168 return Kind.Object;
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
169 } else if (clazz == void.class) {
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
170 return Kind.Void;
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
171 } else {
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
172 throw new IllegalArgumentException("Type not supported: " + clazz);
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
173 }
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
174 }
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
175
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
176 @SuppressWarnings("unused")
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
177 public static Object libCall(Object argLoc, Object unused1, Object unused2) {
13895
4731c1a0b1f3 consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents: 13872
diff changeset
178 throw GraalInternalError.shouldNotReachHere("GNFI libCall method must not be called");
13837
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
179 }
ed3a1471e133 Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff changeset
180 }