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
24
25 package org.graalvm.compiler.hotspot.meta;
26
27 import java.lang.invoke.MethodHandle;
28 import java.lang.invoke.MethodHandles;
29 import java.lang.invoke.MethodType;
30 import java.util.function.Supplier;
31
32 import org.graalvm.compiler.core.common.type.ObjectStamp;
33 import org.graalvm.compiler.core.common.type.Stamp;
34 import org.graalvm.compiler.core.common.type.StampFactory;
35 import org.graalvm.compiler.debug.GraalError;
36 import org.graalvm.compiler.hotspot.nodes.aot.InitializeKlassNode;
37 import org.graalvm.compiler.hotspot.nodes.aot.ResolveConstantNode;
38 import org.graalvm.compiler.nodes.ConstantNode;
39 import org.graalvm.compiler.nodes.DeoptimizingFixedWithNextNode;
40 import org.graalvm.compiler.nodes.FrameState;
41 import org.graalvm.compiler.nodes.ValueNode;
42 import org.graalvm.compiler.nodes.graphbuilderconf.ClassInitializationPlugin;
43 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
44
45 import jdk.vm.ci.hotspot.HotSpotResolvedObjectType;
46 import jdk.vm.ci.meta.ConstantPool;
47 import jdk.vm.ci.meta.ResolvedJavaMethod;
48 import jdk.vm.ci.meta.ResolvedJavaType;
49
71 }
72 return false;
73 }
74
75 @Override
76 public boolean apply(GraphBuilderContext builder, ResolvedJavaType type, Supplier<FrameState> frameState, ValueNode[] classInit) {
77 if (shouldApply(builder, type)) {
78 Stamp hubStamp = builder.getStampProvider().createHubStamp((ObjectStamp) StampFactory.objectNonNull());
79 ConstantNode hub = builder.append(ConstantNode.forConstant(hubStamp, ((HotSpotResolvedObjectType) type).klass(), builder.getMetaAccess(), builder.getGraph()));
80 DeoptimizingFixedWithNextNode result = builder.append(type.isArray() ? new ResolveConstantNode(hub) : new InitializeKlassNode(hub));
81 result.setStateBefore(frameState.get());
82 if (classInit != null) {
83 classInit[0] = result;
84 }
85 return true;
86 }
87 return false;
88 }
89
90 private static final Class<? extends ConstantPool> hscp;
91 private static final MethodHandle loadReferencedTypeIIZMH;
92
93 static {
94 MethodHandle m = null;
95 Class<? extends ConstantPool> c = null;
96 try {
97 c = Class.forName("jdk.vm.ci.hotspot.HotSpotConstantPool").asSubclass(ConstantPool.class);
98 m = MethodHandles.lookup().findVirtual(c, "loadReferencedType", MethodType.methodType(void.class, int.class, int.class, boolean.class));
99 } catch (Exception e) {
100 }
101 loadReferencedTypeIIZMH = m;
102 hscp = c;
103 }
104
105 private static boolean isHotSpotConstantPool(ConstantPool cp) {
106 // jdk.vm.ci.hotspot.HotSpotConstantPool is final, so we can
107 // directly compare Classes.
108 return cp.getClass() == hscp;
109 }
110
111 @Override
112 public boolean supportsLazyInitialization(ConstantPool cp) {
113 if (loadReferencedTypeIIZMH != null && isHotSpotConstantPool(cp)) {
114 return true;
115 }
116 return false;
117 }
118
119 @Override
|
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
24
25 package org.graalvm.compiler.hotspot.meta;
26
27 import java.lang.reflect.Method;
28 import java.util.function.Supplier;
29
30 import org.graalvm.compiler.core.common.type.ObjectStamp;
31 import org.graalvm.compiler.core.common.type.Stamp;
32 import org.graalvm.compiler.core.common.type.StampFactory;
33 import org.graalvm.compiler.debug.GraalError;
34 import org.graalvm.compiler.hotspot.nodes.aot.InitializeKlassNode;
35 import org.graalvm.compiler.hotspot.nodes.aot.ResolveConstantNode;
36 import org.graalvm.compiler.nodes.ConstantNode;
37 import org.graalvm.compiler.nodes.DeoptimizingFixedWithNextNode;
38 import org.graalvm.compiler.nodes.FrameState;
39 import org.graalvm.compiler.nodes.ValueNode;
40 import org.graalvm.compiler.nodes.graphbuilderconf.ClassInitializationPlugin;
41 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
42
43 import jdk.vm.ci.hotspot.HotSpotResolvedObjectType;
44 import jdk.vm.ci.meta.ConstantPool;
45 import jdk.vm.ci.meta.ResolvedJavaMethod;
46 import jdk.vm.ci.meta.ResolvedJavaType;
47
69 }
70 return false;
71 }
72
73 @Override
74 public boolean apply(GraphBuilderContext builder, ResolvedJavaType type, Supplier<FrameState> frameState, ValueNode[] classInit) {
75 if (shouldApply(builder, type)) {
76 Stamp hubStamp = builder.getStampProvider().createHubStamp((ObjectStamp) StampFactory.objectNonNull());
77 ConstantNode hub = builder.append(ConstantNode.forConstant(hubStamp, ((HotSpotResolvedObjectType) type).klass(), builder.getMetaAccess(), builder.getGraph()));
78 DeoptimizingFixedWithNextNode result = builder.append(type.isArray() ? new ResolveConstantNode(hub) : new InitializeKlassNode(hub));
79 result.setStateBefore(frameState.get());
80 if (classInit != null) {
81 classInit[0] = result;
82 }
83 return true;
84 }
85 return false;
86 }
87
88 private static final Class<? extends ConstantPool> hscp;
89 private static final Method loadReferencedTypeIIZMH;
90
91 static {
92 Method m = null;
93 Class<? extends ConstantPool> c = null;
94 try {
95 c = Class.forName("jdk.vm.ci.hotspot.HotSpotConstantPool").asSubclass(ConstantPool.class);
96 m = c.getDeclaredMethod("loadReferencedType", int.class, int.class, boolean.class);
97 } catch (Exception e) {
98 throw GraalError.shouldNotReachHere(e);
99 }
100 loadReferencedTypeIIZMH = m;
101 hscp = c;
102 }
103
104 private static boolean isHotSpotConstantPool(ConstantPool cp) {
105 // jdk.vm.ci.hotspot.HotSpotConstantPool is final, so we can
106 // directly compare Classes.
107 return cp.getClass() == hscp;
108 }
109
110 @Override
111 public boolean supportsLazyInitialization(ConstantPool cp) {
112 if (loadReferencedTypeIIZMH != null && isHotSpotConstantPool(cp)) {
113 return true;
114 }
115 return false;
116 }
117
118 @Override
|