Mercurial > hg > graal-jvmci-8
annotate graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ObjectCloneNode.java @ 16811:5d468add216f
added @NodeInfo annotations to all Node classes
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 13 Aug 2014 18:25:45 +0200 |
parents | e6622e77e8c7 |
children | cbd42807a31f |
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.*; |
13554
83fd2094ff66
rework of monitorenter/exit (use MonitorIdNode)
Lukas Stadler <lukas.stadler@jku.at>
parents:
13197
diff
changeset
|
28 import java.util.*; |
7764
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
29 |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
30 import com.oracle.graal.api.code.*; |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
31 import com.oracle.graal.api.meta.*; |
15198
2c0cfbf454b5
Move LIRTypeTool and Stamp to graal.compiler.common.
Josef Eisl <josef.eisl@jku.at>
parents:
13614
diff
changeset
|
32 import com.oracle.graal.compiler.common.type.*; |
11716
bffe5758c209
Snippets processing in ArrayCopyNode and ObjectCloneNode need proper scoping
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11496
diff
changeset
|
33 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
|
34 import com.oracle.graal.debug.Debug.Scope; |
16811
5d468add216f
added @NodeInfo annotations to all Node classes
Doug Simon <doug.simon@oracle.com>
parents:
16290
diff
changeset
|
35 import com.oracle.graal.graph.*; |
7764
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
36 import com.oracle.graal.nodes.*; |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
37 import com.oracle.graal.nodes.java.*; |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
38 import com.oracle.graal.nodes.spi.*; |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
39 import com.oracle.graal.nodes.type.*; |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
40 import com.oracle.graal.nodes.virtual.*; |
8415
2361bf148c06
rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents:
8398
diff
changeset
|
41 import com.oracle.graal.replacements.nodes.*; |
7764
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
42 |
16811
5d468add216f
added @NodeInfo annotations to all Node classes
Doug Simon <doug.simon@oracle.com>
parents:
16290
diff
changeset
|
43 @NodeInfo |
16290
e6622e77e8c7
split MacroNode into MacroNode and MacroStateSplitNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16075
diff
changeset
|
44 public class ObjectCloneNode extends MacroStateSplitNode implements VirtualizableAllocation, ArrayLengthProvider { |
7764
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 public ObjectCloneNode(Invoke invoke) { |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
47 super(invoke); |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
48 } |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
49 |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
50 @Override |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
51 public boolean inferStamp() { |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
52 return updateStamp(getObject().stamp()); |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
53 } |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
54 |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
55 private ValueNode getObject() { |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
56 return arguments.get(0); |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
57 } |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
58 |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
59 @Override |
11754
6e734982f89f
fixed concurrency issue in lowering of MacroNode replacement graphs
Doug Simon <doug.simon@oracle.com>
parents:
11716
diff
changeset
|
60 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
|
61 if (!shouldIntrinsify(getTargetMethod())) { |
7902
14fedab0419e
improved arraycopy and Object.clone snippets
Lukas Stadler <lukas.stadler@jku.at>
parents:
7872
diff
changeset
|
62 return null; |
7764
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
63 } |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
64 |
15260
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
65 ResolvedJavaType type = StampTool.typeOrNull(getObject()); |
11871
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
66 if (type != null) { |
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
67 if (type.isArray()) { |
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
68 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
|
69 if (method != null) { |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11871
diff
changeset
|
70 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
|
71 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
|
72 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
|
73 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
|
74 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
|
75 } 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
|
76 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
|
77 } |
11871
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
78 |
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
79 assert snippetGraph != null : "ObjectCloneSnippets should be installed"; |
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
80 return lowerReplacement(snippetGraph.copy(), tool); |
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
81 } |
16075
77783d8a45ef
handle other primitive array types in clone
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15260
diff
changeset
|
82 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
|
83 } else { |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11871
diff
changeset
|
84 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
|
85 if (type != null) { |
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
86 StructuredGraph newGraph = new StructuredGraph(); |
13614
0774f3303c2e
rename LocalNode to ParameterNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
13554
diff
changeset
|
87 ParameterNode param = newGraph.unique(new ParameterNode(0, getObject().stamp())); |
11871
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
88 NewInstanceNode newInstance = newGraph.add(new NewInstanceNode(type, true)); |
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
89 newGraph.addAfterFixed(newGraph.start(), newInstance); |
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
90 ReturnNode returnNode = newGraph.add(new ReturnNode(newInstance)); |
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
91 newGraph.addAfterFixed(newInstance, returnNode); |
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
92 |
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
93 for (ResolvedJavaField field : type.getInstanceFields(true)) { |
13614
0774f3303c2e
rename LocalNode to ParameterNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
13554
diff
changeset
|
94 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
|
95 newGraph.addBeforeFixed(returnNode, load); |
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
96 newGraph.addBeforeFixed(returnNode, newGraph.add(new StoreFieldNode(newInstance, field, load))); |
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
97 } |
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
98 return lowerReplacement(newGraph, tool); |
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
99 } |
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
100 } |
7902
14fedab0419e
improved arraycopy and Object.clone snippets
Lukas Stadler <lukas.stadler@jku.at>
parents:
7872
diff
changeset
|
101 } |
11871
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
102 return null; |
7764
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
103 } |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
104 |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
105 private static boolean isCloneableType(ResolvedJavaType type, MetaAccessProvider metaAccess) { |
11871
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
106 return metaAccess.lookupJavaType(Cloneable.class).isAssignableFrom(type); |
7764
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
107 } |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
108 |
11871
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
109 /* |
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
110 * Looks at the given stamp and determines if it is an exact type (or can be assumed to be an |
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
111 * exact type) and if it is a cloneable type. |
16290
e6622e77e8c7
split MacroNode into MacroNode and MacroStateSplitNode
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16075
diff
changeset
|
112 * |
11871
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
113 * If yes, then the exact type is returned, otherwise it returns null. |
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
114 */ |
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
115 private static ResolvedJavaType getConcreteType(Stamp stamp, Assumptions assumptions, MetaAccessProvider metaAccess) { |
11265 | 116 if (!(stamp instanceof ObjectStamp)) { |
117 return null; | |
118 } | |
119 ObjectStamp objectStamp = (ObjectStamp) stamp; | |
11871
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
120 if (objectStamp.type() == null) { |
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
121 return null; |
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
122 } else if (objectStamp.isExactType()) { |
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
123 return isCloneableType(objectStamp.type(), metaAccess) ? objectStamp.type() : null; |
7764
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
124 } else { |
11265 | 125 ResolvedJavaType type = objectStamp.type().findUniqueConcreteSubtype(); |
11871
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
126 if (type != null && isCloneableType(type, metaAccess)) { |
11265 | 127 assumptions.recordConcreteSubtype(objectStamp.type(), type); |
11871
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
128 return type; |
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
129 } else { |
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
130 return null; |
7764
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
131 } |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
132 } |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
133 } |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
134 |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
135 @Override |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
136 public void virtualize(VirtualizerTool tool) { |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
137 State originalState = tool.getObjectState(getObject()); |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
138 if (originalState != null && originalState.getState() == EscapeState.Virtual) { |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
139 VirtualObjectNode originalVirtual = originalState.getVirtualObject(); |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
140 if (isCloneableType(originalVirtual.type(), tool.getMetaAccessProvider())) { |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
141 ValueNode[] newEntryState = new ValueNode[originalVirtual.entryCount()]; |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
142 for (int i = 0; i < newEntryState.length; i++) { |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
143 newEntryState[i] = originalState.getEntry(i); |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
144 } |
7765
f20c2b1f5289
fix for Object.clone virtualization
Lukas Stadler <lukas.stadler@jku.at>
parents:
7764
diff
changeset
|
145 VirtualObjectNode newVirtual = originalVirtual.duplicate(); |
13554
83fd2094ff66
rework of monitorenter/exit (use MonitorIdNode)
Lukas Stadler <lukas.stadler@jku.at>
parents:
13197
diff
changeset
|
146 tool.createVirtualObject(newVirtual, newEntryState, Collections.<MonitorIdNode> emptyList()); |
7764
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
147 tool.replaceWithVirtual(newVirtual); |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
148 } |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
149 } else { |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
150 ValueNode obj; |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
151 if (originalState != null) { |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
152 obj = originalState.getMaterializedValue(); |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
153 } else { |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
154 obj = tool.getReplacedValue(getObject()); |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
155 } |
11871
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
156 ResolvedJavaType type = getConcreteType(obj.stamp(), tool.getAssumptions(), tool.getMetaAccessProvider()); |
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
157 if (type != null && !type.isArray()) { |
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
158 VirtualInstanceNode newVirtual = new VirtualInstanceNode(type, true); |
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
159 ResolvedJavaField[] fields = newVirtual.getFields(); |
8398
2d1b0b20f89d
small change VirtualInstanceNode constructor
Lukas Stadler <lukas.stadler@jku.at>
parents:
7902
diff
changeset
|
160 |
11871
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
161 ValueNode[] state = new ValueNode[fields.length]; |
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
162 final LoadFieldNode[] loads = new LoadFieldNode[fields.length]; |
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
163 for (int i = 0; i < fields.length; i++) { |
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
164 state[i] = loads[i] = new LoadFieldNode(obj, fields[i]); |
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
165 tool.addNode(loads[i]); |
7764
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
166 } |
13554
83fd2094ff66
rework of monitorenter/exit (use MonitorIdNode)
Lukas Stadler <lukas.stadler@jku.at>
parents:
13197
diff
changeset
|
167 tool.createVirtualObject(newVirtual, state, Collections.<MonitorIdNode> emptyList()); |
11871
69a527047c40
fix, simplify and enable ObjectClone intrinsification
Lukas Stadler <lukas.stadler@jku.at>
parents:
11754
diff
changeset
|
168 tool.replaceWithVirtual(newVirtual); |
7764
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
169 } |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
170 } |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
171 } |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
172 |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
173 @Override |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
174 public ValueNode length() { |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
175 if (getObject() instanceof ArrayLengthProvider) { |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
176 return ((ArrayLengthProvider) getObject()).length(); |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
177 } else { |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
178 return null; |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
179 } |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
180 } |
cff55cdeea48
implement Object.clone snippets and macro node
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
181 } |