Mercurial > hg > truffle
annotate graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ReflectionGetCallerClassNode.java @ 15489:d0e3f6963ed7
mx: made parallel Java builds interact correctly with management of subprocesses upon abort/quit
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Sun, 04 May 2014 01:26:50 +0200 |
parents | 96bb07a5d667 |
children | c5b2a3c22318 |
rev | line source |
---|---|
9416 | 1 /* |
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 package com.oracle.graal.hotspot.replacements; | |
24 | |
11491
a03452edfc4d
made enabling/disabling of intrinsifications extensible (GRAAL-111)
Doug Simon <doug.simon@oracle.com>
parents:
9864
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:
9602
diff
changeset
|
26 |
9416 | 27 import com.oracle.graal.api.meta.*; |
15193
96bb07a5d667
Spit up and move GraalInternalError.
Josef Eisl <josef.eisl@jku.at>
parents:
15018
diff
changeset
|
28 import com.oracle.graal.compiler.common.*; |
9416 | 29 import com.oracle.graal.graph.*; |
11881
da9db8331658
moved Canonicalizable and Simplifiable to the com.oracle.graal.graph project (GRAAL-506)
Doug Simon <doug.simon@oracle.com>
parents:
11880
diff
changeset
|
30 import com.oracle.graal.graph.spi.*; |
9416 | 31 import com.oracle.graal.hotspot.meta.*; |
32 import com.oracle.graal.nodes.*; | |
33 import com.oracle.graal.nodes.spi.*; | |
34 import com.oracle.graal.replacements.nodes.*; | |
35 | |
36 public class ReflectionGetCallerClassNode extends MacroNode implements Canonicalizable, Lowerable { | |
37 | |
38 public ReflectionGetCallerClassNode(Invoke invoke) { | |
39 super(invoke); | |
40 } | |
41 | |
42 @Override | |
11880
9a747d8e0d0f
broadened types in Canonicalizable interface so that it can be moved to the com.oracle.graal.graph project (GRAAL-506)
Doug Simon <doug.simon@oracle.com>
parents:
11798
diff
changeset
|
43 public Node canonical(CanonicalizerTool tool) { |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11881
diff
changeset
|
44 ConstantNode callerClassNode = getCallerClassNode(tool.getMetaAccess()); |
9416 | 45 if (callerClassNode != null) { |
46 return callerClassNode; | |
47 } | |
48 return this; | |
49 } | |
50 | |
51 @Override | |
11579
ae619d70bf4b
Rename LoweringType to GuardsPhase and make it an attribute of StructuredGraphs
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11491
diff
changeset
|
52 public void lower(LoweringTool tool) { |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11881
diff
changeset
|
53 ConstantNode callerClassNode = getCallerClassNode(tool.getMetaAccess()); |
9416 | 54 |
55 if (callerClassNode != null) { | |
9602
19c5a07c7843
Introduce a graph() method that returns a StructuredGraph, to make many explicit casts unnecessary
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9416
diff
changeset
|
56 graph().replaceFixedWithFloating(this, callerClassNode); |
9416 | 57 } else { |
11798
2fbb9fd55dde
made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents:
11579
diff
changeset
|
58 InvokeNode invoke = createInvoke(); |
2fbb9fd55dde
made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents:
11579
diff
changeset
|
59 graph().replaceFixedWithFixed(this, invoke); |
2fbb9fd55dde
made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents:
11579
diff
changeset
|
60 invoke.lower(tool); |
9416 | 61 } |
62 } | |
63 | |
64 /** | |
65 * If inlining is deep enough this method returns a {@link ConstantNode} of the caller class by | |
66 * walking the the stack. | |
67 * | |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11881
diff
changeset
|
68 * @param metaAccess |
9416 | 69 * @return ConstantNode of the caller class, or null |
70 */ | |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
11881
diff
changeset
|
71 private ConstantNode getCallerClassNode(MetaAccessProvider metaAccess) { |
11491
a03452edfc4d
made enabling/disabling of intrinsifications extensible (GRAAL-111)
Doug Simon <doug.simon@oracle.com>
parents:
9864
diff
changeset
|
72 if (!shouldIntrinsify(getTargetMethod())) { |
9416 | 73 return null; |
74 } | |
75 | |
76 // Walk back up the frame states to find the caller at the required depth. | |
77 FrameState state = stateAfter(); | |
78 | |
79 // Cf. JVM_GetCallerClass | |
80 // NOTE: Start the loop at depth 1 because the current frame state does | |
81 // not include the Reflection.getCallerClass() frame. | |
82 for (int n = 1; state != null; state = state.outerFrameState(), n++) { | |
83 HotSpotResolvedJavaMethod method = (HotSpotResolvedJavaMethod) state.method(); | |
84 switch (n) { | |
85 case 0: | |
86 throw GraalInternalError.shouldNotReachHere("current frame state does not include the Reflection.getCallerClass frame"); | |
87 case 1: | |
88 // Frame 0 and 1 must be caller sensitive (see JVM_GetCallerClass). | |
89 if (!method.isCallerSensitive()) { | |
90 return null; // bail-out; let JVM_GetCallerClass do the work | |
91 } | |
92 break; | |
93 default: | |
94 if (!method.ignoredBySecurityStackWalk()) { | |
95 // We have reached the desired frame; return the holder class. | |
14089
280332c0180e
removed unnecessary explicit cast by tightening return type of overloaded method
Doug Simon <doug.simon@oracle.com>
parents:
11959
diff
changeset
|
96 HotSpotResolvedObjectType callerClass = method.getDeclaringClass(); |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
14089
diff
changeset
|
97 return ConstantNode.forConstant(HotSpotObjectConstant.forObject(callerClass.mirror()), metaAccess, graph()); |
9416 | 98 } |
99 break; | |
100 } | |
101 } | |
102 return null; // bail-out; let JVM_GetCallerClass do the work | |
103 } | |
104 | |
105 } |