annotate graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ObjectCloneNode.java @ 18845:f57d86eb036f

removed Node factory methods
author Doug Simon <doug.simon@oracle.com>
date Mon, 12 Jan 2015 20:39:04 +0100
parents 45b45f902bed
children 8ab925a6f724
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7764
cff55cdeea48 implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
1 /*
cff55cdeea48 implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
cff55cdeea48 implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
cff55cdeea48 implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
4 *
cff55cdeea48 implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
cff55cdeea48 implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
cff55cdeea48 implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
7 * published by the Free Software Foundation.
cff55cdeea48 implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
8 *
cff55cdeea48 implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
cff55cdeea48 implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
cff55cdeea48 implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
cff55cdeea48 implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
cff55cdeea48 implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
13 * accompanied this code).
cff55cdeea48 implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
14 *
cff55cdeea48 implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
cff55cdeea48 implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
cff55cdeea48 implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
cff55cdeea48 implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
18 *
cff55cdeea48 implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
cff55cdeea48 implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
cff55cdeea48 implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
21 * questions.
cff55cdeea48 implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
22 */
8415
2361bf148c06 rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents: 8398
diff changeset
23 package com.oracle.graal.hotspot.replacements;
7764
cff55cdeea48 implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
24
11491
a03452edfc4d made enabling/disabling of intrinsifications extensible (GRAAL-111)
Doug Simon <doug.simon@oracle.com>
parents: 11265
diff changeset
25 import static com.oracle.graal.compiler.GraalCompiler.*;
9864
063a712fe8d8 converted remaining options in GraalOptions to new system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 9838
diff changeset
26
7764
cff55cdeea48 implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
27 import java.lang.reflect.*;
cff55cdeea48 implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
28
cff55cdeea48 implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
29 import com.oracle.graal.api.meta.*;
11716
bffe5758c209 Snippets processing in ArrayCopyNode and ObjectCloneNode need proper scoping
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11496
diff changeset
30 import com.oracle.graal.debug.*;
13197
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13193
diff changeset
31 import com.oracle.graal.debug.Debug.Scope;
16841
cbd42807a31f moved NodeInfo and friends into separate com.oracle.graal.nodeinfo project so that annotation processor can be applied to the base Node class
Doug Simon <doug.simon@oracle.com>
parents: 16811
diff changeset
32 import com.oracle.graal.nodeinfo.*;
7764
cff55cdeea48 implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
33 import com.oracle.graal.nodes.*;
cff55cdeea48 implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
34 import com.oracle.graal.nodes.java.*;
cff55cdeea48 implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
35 import com.oracle.graal.nodes.spi.*;
cff55cdeea48 implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
36 import com.oracle.graal.nodes.type.*;
8415
2361bf148c06 rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents: 8398
diff changeset
37 import com.oracle.graal.replacements.nodes.*;
7764
cff55cdeea48 implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
38
16811
5d468add216f added @NodeInfo annotations to all Node classes
Doug Simon <doug.simon@oracle.com>
parents: 16290
diff changeset
39 @NodeInfo
17130
f396d15ddce2 Factor out HotSpot-independent parts of ArrayCopy and ObjectClone nodes
Christian Wimmer <christian.wimmer@oracle.com>
parents: 16919
diff changeset
40 public class ObjectCloneNode extends BasicObjectCloneNode implements VirtualizableAllocation, ArrayLengthProvider {
7764
cff55cdeea48 implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
41
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 17450
diff changeset
42 public ObjectCloneNode(Invoke invoke) {
7764
cff55cdeea48 implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
43 super(invoke);
cff55cdeea48 implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
44 }
cff55cdeea48 implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
45
cff55cdeea48 implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
46 @Override
11754
6e734982f89f fixed concurrency issue in lowering of MacroNode replacement graphs
Doug Simon <doug.simon@oracle.com>
parents: 11716
diff changeset
47 protected StructuredGraph getLoweredSnippetGraph(LoweringTool tool) {
11491
a03452edfc4d made enabling/disabling of intrinsifications extensible (GRAAL-111)
Doug Simon <doug.simon@oracle.com>
parents: 11265
diff changeset
48 if (!shouldIntrinsify(getTargetMethod())) {
7902
14fedab0419e improved arraycopy and Object.clone snippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 7872
diff changeset
49 return null;
7764
cff55cdeea48 implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
50 }
cff55cdeea48 implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
51
15260
61363577a184 Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents: 15198
diff changeset
52 ResolvedJavaType type = StampTool.typeOrNull(getObject());
11871
69a527047c40 fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents: 11754
diff changeset
53 if (type != null) {
69a527047c40 fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents: 11754
diff changeset
54 if (type.isArray()) {
69a527047c40 fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents: 11754
diff changeset
55 Method method = ObjectCloneSnippets.arrayCloneMethods.get(type.getComponentType().getKind());
69a527047c40 fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents: 11754
diff changeset
56 if (method != null) {
11959
23ccaa863eda made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11871
diff changeset
57 final ResolvedJavaMethod snippetMethod = tool.getMetaAccess().lookupJavaMethod(method);
11871
69a527047c40 fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents: 11754
diff changeset
58 final Replacements replacements = tool.getReplacements();
13197
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13193
diff changeset
59 StructuredGraph snippetGraph = null;
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13193
diff changeset
60 try (Scope s = Debug.scope("ArrayCopySnippet", snippetMethod)) {
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13193
diff changeset
61 snippetGraph = replacements.getSnippet(snippetMethod);
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13193
diff changeset
62 } catch (Throwable e) {
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13193
diff changeset
63 throw Debug.handle(e);
8569b9e047cd change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents: 13193
diff changeset
64 }
11871
69a527047c40 fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents: 11754
diff changeset
65
69a527047c40 fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents: 11754
diff changeset
66 assert snippetGraph != null : "ObjectCloneSnippets should be installed";
69a527047c40 fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents: 11754
diff changeset
67 return lowerReplacement(snippetGraph.copy(), tool);
69a527047c40 fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents: 11754
diff changeset
68 }
16075
77783d8a45ef handle other primitive array types in clone
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15260
diff changeset
69 assert false : "unhandled array type " + type.getComponentType().getKind();
11871
69a527047c40 fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents: 11754
diff changeset
70 } else {
11959
23ccaa863eda made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11871
diff changeset
71 type = getConcreteType(getObject().stamp(), tool.assumptions(), tool.getMetaAccess());
11871
69a527047c40 fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents: 11754
diff changeset
72 if (type != null) {
69a527047c40 fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents: 11754
diff changeset
73 StructuredGraph newGraph = new StructuredGraph();
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 17450
diff changeset
74 ParameterNode param = newGraph.unique(new ParameterNode(0, getObject().stamp()));
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 17450
diff changeset
75 NewInstanceNode newInstance = newGraph.add(new NewInstanceNode(type, true));
11871
69a527047c40 fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents: 11754
diff changeset
76 newGraph.addAfterFixed(newGraph.start(), newInstance);
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 17450
diff changeset
77 ReturnNode returnNode = newGraph.add(new ReturnNode(newInstance));
11871
69a527047c40 fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents: 11754
diff changeset
78 newGraph.addAfterFixed(newInstance, returnNode);
69a527047c40 fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents: 11754
diff changeset
79
69a527047c40 fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents: 11754
diff changeset
80 for (ResolvedJavaField field : type.getInstanceFields(true)) {
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 17450
diff changeset
81 LoadFieldNode load = newGraph.add(new LoadFieldNode(param, field));
11871
69a527047c40 fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents: 11754
diff changeset
82 newGraph.addBeforeFixed(returnNode, load);
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 17450
diff changeset
83 newGraph.addBeforeFixed(returnNode, newGraph.add(new StoreFieldNode(newInstance, field, load)));
11871
69a527047c40 fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents: 11754
diff changeset
84 }
69a527047c40 fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents: 11754
diff changeset
85 return lowerReplacement(newGraph, tool);
69a527047c40 fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents: 11754
diff changeset
86 }
69a527047c40 fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents: 11754
diff changeset
87 }
7902
14fedab0419e improved arraycopy and Object.clone snippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 7872
diff changeset
88 }
11871
69a527047c40 fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents: 11754
diff changeset
89 return null;
7764
cff55cdeea48 implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
90 }
cff55cdeea48 implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
91 }