1 /*
   2  * Copyright (c) 2011, 2018, 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 
  24 
  25 package org.graalvm.compiler.hotspot.meta;
  26 
  27 import static jdk.vm.ci.services.Services.IS_IN_NATIVE_IMAGE;
  28 import static org.graalvm.compiler.core.common.GraalOptions.AlwaysInlineVTableStubs;
  29 import static org.graalvm.compiler.core.common.GraalOptions.GeneratePIC;
  30 import static org.graalvm.compiler.core.common.GraalOptions.InlineVTableStubs;
  31 import static org.graalvm.compiler.core.common.GraalOptions.OmitHotExceptionStacktrace;
  32 import static org.graalvm.compiler.hotspot.meta.HotSpotForeignCallsProviderImpl.OSR_MIGRATION_END;
  33 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.CLASS_KLASS_LOCATION;
  34 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.CLASS_MIRROR_HANDLE_LOCATION;
  35 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.CLASS_MIRROR_LOCATION;
  36 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.COMPRESSED_HUB_LOCATION;
  37 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.DISPLACED_MARK_WORD_LOCATION;
  38 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.HUB_LOCATION;
  39 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.HUB_WRITE_LOCATION;
  40 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.KLASS_LAYOUT_HELPER_LOCATION;
  41 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.OBJ_ARRAY_KLASS_ELEMENT_KLASS_LOCATION;
  42 import static jdk.internal.vm.compiler.word.LocationIdentity.any;
  43 
  44 import java.lang.ref.Reference;
  45 import java.util.EnumMap;
  46 
  47 import org.graalvm.compiler.api.directives.GraalDirectives;
  48 import org.graalvm.compiler.core.common.CompressEncoding;
  49 import org.graalvm.compiler.core.common.GraalOptions;
  50 import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor;
  51 import org.graalvm.compiler.core.common.spi.ForeignCallsProvider;
  52 import org.graalvm.compiler.core.common.type.ObjectStamp;
  53 import org.graalvm.compiler.core.common.type.Stamp;
  54 import org.graalvm.compiler.core.common.type.StampFactory;
  55 import org.graalvm.compiler.core.common.type.StampPair;
  56 import org.graalvm.compiler.debug.DebugCloseable;
  57 import org.graalvm.compiler.debug.DebugHandlersFactory;
  58 import org.graalvm.compiler.debug.GraalError;
  59 import org.graalvm.compiler.graph.Node;
  60 import org.graalvm.compiler.graph.NodeInputList;
  61 import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
  62 import org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider;
  63 import org.graalvm.compiler.hotspot.gc.g1.G1ArrayRangePostWriteBarrier;
  64 import org.graalvm.compiler.hotspot.gc.g1.G1ArrayRangePreWriteBarrier;
  65 import org.graalvm.compiler.hotspot.gc.g1.G1PostWriteBarrier;
  66 import org.graalvm.compiler.hotspot.gc.g1.G1PreWriteBarrier;
  67 import org.graalvm.compiler.hotspot.gc.g1.G1ReferentFieldReadBarrier;
  68 import org.graalvm.compiler.hotspot.gc.shared.SerialArrayRangeWriteBarrier;
  69 import org.graalvm.compiler.hotspot.gc.shared.SerialWriteBarrier;
  70 import org.graalvm.compiler.hotspot.nodes.BeginLockScopeNode;
  71 import org.graalvm.compiler.hotspot.nodes.HotSpotCompressionNode;
  72 import org.graalvm.compiler.hotspot.nodes.HotSpotDirectCallTargetNode;
  73 import org.graalvm.compiler.hotspot.nodes.HotSpotIndirectCallTargetNode;
  74 import org.graalvm.compiler.hotspot.nodes.aot.InitializeKlassNode;
  75 import org.graalvm.compiler.hotspot.nodes.aot.ResolveConstantNode;
  76 import org.graalvm.compiler.hotspot.nodes.aot.ResolveDynamicConstantNode;
  77 import org.graalvm.compiler.hotspot.nodes.aot.ResolveMethodAndLoadCountersNode;
  78 import org.graalvm.compiler.hotspot.nodes.profiling.ProfileNode;
  79 import org.graalvm.compiler.hotspot.nodes.type.HotSpotNarrowOopStamp;
  80 import org.graalvm.compiler.hotspot.nodes.type.KlassPointerStamp;
  81 import org.graalvm.compiler.hotspot.nodes.type.MethodPointerStamp;
  82 import org.graalvm.compiler.hotspot.replacements.AssertionSnippets;
  83 import org.graalvm.compiler.hotspot.replacements.ClassGetHubNode;
  84 import org.graalvm.compiler.hotspot.replacements.HashCodeSnippets;
  85 import org.graalvm.compiler.hotspot.replacements.HubGetClassNode;
  86 import org.graalvm.compiler.hotspot.replacements.IdentityHashCodeNode;
  87 import org.graalvm.compiler.hotspot.replacements.InstanceOfSnippets;
  88 import org.graalvm.compiler.hotspot.replacements.KlassLayoutHelperNode;
  89 import org.graalvm.compiler.hotspot.replacements.LoadExceptionObjectSnippets;
  90 import org.graalvm.compiler.hotspot.replacements.MonitorSnippets;
  91 import org.graalvm.compiler.hotspot.replacements.NewObjectSnippets;
  92 import org.graalvm.compiler.hotspot.replacements.ObjectCloneSnippets;
  93 import org.graalvm.compiler.hotspot.replacements.StringToBytesSnippets;
  94 import org.graalvm.compiler.hotspot.replacements.UnsafeLoadSnippets;
  95 import org.graalvm.compiler.hotspot.replacements.WriteBarrierSnippets;
  96 import org.graalvm.compiler.hotspot.replacements.aot.ResolveConstantSnippets;
  97 import org.graalvm.compiler.hotspot.replacements.arraycopy.HotSpotArraycopySnippets;
  98 import org.graalvm.compiler.hotspot.replacements.profiling.ProfileSnippets;
  99 import org.graalvm.compiler.hotspot.stubs.ForeignCallSnippets;
 100 import org.graalvm.compiler.hotspot.word.KlassPointer;
 101 import org.graalvm.compiler.nodes.AbstractBeginNode;
 102 import org.graalvm.compiler.nodes.AbstractDeoptimizeNode;
 103 import org.graalvm.compiler.nodes.CompressionNode.CompressionOp;
 104 import org.graalvm.compiler.nodes.ComputeObjectAddressNode;
 105 import org.graalvm.compiler.nodes.ConstantNode;
 106 import org.graalvm.compiler.nodes.FixedNode;
 107 import org.graalvm.compiler.nodes.GetObjectAddressNode;
 108 import org.graalvm.compiler.nodes.Invoke;
 109 import org.graalvm.compiler.nodes.LogicNode;
 110 import org.graalvm.compiler.nodes.LoweredCallTargetNode;
 111 import org.graalvm.compiler.nodes.NodeView;
 112 import org.graalvm.compiler.nodes.ParameterNode;
 113 import org.graalvm.compiler.nodes.SafepointNode;
 114 import org.graalvm.compiler.nodes.StartNode;
 115 import org.graalvm.compiler.nodes.StructuredGraph;
 116 import org.graalvm.compiler.nodes.UnwindNode;
 117 import org.graalvm.compiler.nodes.ValueNode;
 118 import org.graalvm.compiler.nodes.calc.AddNode;
 119 import org.graalvm.compiler.nodes.calc.FloatingNode;
 120 import org.graalvm.compiler.nodes.calc.IntegerDivRemNode;
 121 import org.graalvm.compiler.nodes.calc.IsNullNode;
 122 import org.graalvm.compiler.nodes.calc.RemNode;
 123 import org.graalvm.compiler.nodes.debug.StringToBytesNode;
 124 import org.graalvm.compiler.nodes.debug.VerifyHeapNode;
 125 import org.graalvm.compiler.nodes.extended.BytecodeExceptionNode;
 126 import org.graalvm.compiler.nodes.extended.BytecodeExceptionNode.BytecodeExceptionKind;
 127 import org.graalvm.compiler.nodes.extended.ForeignCallNode;
 128 import org.graalvm.compiler.nodes.extended.GetClassNode;
 129 import org.graalvm.compiler.nodes.extended.GuardedUnsafeLoadNode;
 130 import org.graalvm.compiler.nodes.extended.LoadHubNode;
 131 import org.graalvm.compiler.nodes.extended.LoadMethodNode;
 132 import org.graalvm.compiler.nodes.extended.OSRLocalNode;
 133 import org.graalvm.compiler.nodes.extended.OSRLockNode;
 134 import org.graalvm.compiler.nodes.extended.OSRMonitorEnterNode;
 135 import org.graalvm.compiler.nodes.extended.OSRStartNode;
 136 import org.graalvm.compiler.nodes.extended.RawLoadNode;
 137 import org.graalvm.compiler.nodes.extended.StoreHubNode;
 138 import org.graalvm.compiler.nodes.java.ClassIsAssignableFromNode;
 139 import org.graalvm.compiler.nodes.java.DynamicNewArrayNode;
 140 import org.graalvm.compiler.nodes.java.DynamicNewInstanceNode;
 141 import org.graalvm.compiler.nodes.java.InstanceOfDynamicNode;
 142 import org.graalvm.compiler.nodes.java.InstanceOfNode;
 143 import org.graalvm.compiler.nodes.java.LoadExceptionObjectNode;
 144 import org.graalvm.compiler.nodes.java.MethodCallTargetNode;
 145 import org.graalvm.compiler.nodes.java.MonitorExitNode;
 146 import org.graalvm.compiler.nodes.java.MonitorIdNode;
 147 import org.graalvm.compiler.nodes.java.NewArrayNode;
 148 import org.graalvm.compiler.nodes.java.NewInstanceNode;
 149 import org.graalvm.compiler.nodes.java.NewMultiArrayNode;
 150 import org.graalvm.compiler.nodes.java.RawMonitorEnterNode;
 151 import org.graalvm.compiler.nodes.memory.FloatingReadNode;
 152 import org.graalvm.compiler.nodes.memory.HeapAccess.BarrierType;
 153 import org.graalvm.compiler.nodes.memory.ReadNode;
 154 import org.graalvm.compiler.nodes.memory.WriteNode;
 155 import org.graalvm.compiler.nodes.memory.address.AddressNode;
 156 import org.graalvm.compiler.nodes.spi.LoweringProvider;
 157 import org.graalvm.compiler.nodes.spi.LoweringTool;
 158 import org.graalvm.compiler.nodes.spi.StampProvider;
 159 import org.graalvm.compiler.nodes.type.StampTool;
 160 import org.graalvm.compiler.nodes.util.GraphUtil;
 161 import org.graalvm.compiler.options.OptionValues;
 162 import org.graalvm.compiler.replacements.DefaultJavaLoweringProvider;
 163 import org.graalvm.compiler.replacements.arraycopy.ArrayCopyNode;
 164 import org.graalvm.compiler.replacements.arraycopy.ArrayCopySnippets;
 165 import org.graalvm.compiler.replacements.arraycopy.ArrayCopyWithDelayedLoweringNode;
 166 import org.graalvm.compiler.replacements.nodes.AssertionNode;
 167 import org.graalvm.compiler.serviceprovider.JavaVersionUtil;
 168 import jdk.internal.vm.compiler.word.LocationIdentity;
 169 
 170 import jdk.vm.ci.code.TargetDescription;
 171 import jdk.vm.ci.hotspot.HotSpotCallingConventionType;
 172 import jdk.vm.ci.hotspot.HotSpotConstantReflectionProvider;
 173 import jdk.vm.ci.hotspot.HotSpotResolvedJavaField;
 174 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
 175 import jdk.vm.ci.meta.JavaConstant;
 176 import jdk.vm.ci.meta.JavaKind;
 177 import jdk.vm.ci.meta.JavaType;
 178 import jdk.vm.ci.meta.MetaAccessProvider;
 179 import jdk.vm.ci.meta.ResolvedJavaField;
 180 import jdk.vm.ci.meta.ResolvedJavaType;
 181 
 182 /**
 183  * HotSpot implementation of {@link LoweringProvider}.
 184  */
 185 public class DefaultHotSpotLoweringProvider extends DefaultJavaLoweringProvider implements HotSpotLoweringProvider {
 186 
 187     protected final HotSpotGraalRuntimeProvider runtime;
 188     protected final HotSpotRegistersProvider registers;
 189     protected final HotSpotConstantReflectionProvider constantReflection;
 190 
 191     protected InstanceOfSnippets.Templates instanceofSnippets;
 192     protected NewObjectSnippets.Templates newObjectSnippets;
 193     protected MonitorSnippets.Templates monitorSnippets;
 194     protected WriteBarrierSnippets.Templates writeBarrierSnippets;
 195     protected LoadExceptionObjectSnippets.Templates exceptionObjectSnippets;
 196     protected UnsafeLoadSnippets.Templates unsafeLoadSnippets;
 197     protected AssertionSnippets.Templates assertionSnippets;
 198     protected ArrayCopySnippets.Templates arraycopySnippets;
 199     protected StringToBytesSnippets.Templates stringToBytesSnippets;
 200     protected HashCodeSnippets.Templates hashCodeSnippets;
 201     protected ResolveConstantSnippets.Templates resolveConstantSnippets;
 202     protected ProfileSnippets.Templates profileSnippets;
 203 
 204     protected ObjectCloneSnippets.Templates objectCloneSnippets;
 205     protected ForeignCallSnippets.Templates foreignCallSnippets;
 206 
 207     public DefaultHotSpotLoweringProvider(HotSpotGraalRuntimeProvider runtime, MetaAccessProvider metaAccess, ForeignCallsProvider foreignCalls, HotSpotRegistersProvider registers,
 208                     HotSpotConstantReflectionProvider constantReflection, TargetDescription target) {
 209         super(metaAccess, foreignCalls, target, runtime.getVMConfig().useCompressedOops);
 210         this.runtime = runtime;
 211         this.registers = registers;
 212         this.constantReflection = constantReflection;
 213     }
 214 
 215     @Override
 216     public void initialize(OptionValues options, Iterable<DebugHandlersFactory> factories, HotSpotProviders providers, GraalHotSpotVMConfig config) {
 217         super.initialize(options, factories, runtime, providers, providers.getSnippetReflection());
 218 
 219         assert target == providers.getCodeCache().getTarget();
 220         instanceofSnippets = new InstanceOfSnippets.Templates(options, factories, runtime, providers, target);
 221         newObjectSnippets = new NewObjectSnippets.Templates(options, factories, runtime, providers, target, config);
 222         monitorSnippets = new MonitorSnippets.Templates(options, factories, runtime, providers, target, config.useFastLocking);
 223         writeBarrierSnippets = new WriteBarrierSnippets.Templates(options, factories, runtime, providers, target, config);
 224         exceptionObjectSnippets = new LoadExceptionObjectSnippets.Templates(options, factories, providers, target);
 225         unsafeLoadSnippets = new UnsafeLoadSnippets.Templates(options, factories, providers, target);
 226         assertionSnippets = new AssertionSnippets.Templates(options, factories, providers, target);
 227         arraycopySnippets = new ArrayCopySnippets.Templates(new HotSpotArraycopySnippets(), options, factories, runtime, providers, providers.getSnippetReflection(), target);
 228         stringToBytesSnippets = new StringToBytesSnippets.Templates(options, factories, providers, target);
 229         hashCodeSnippets = new HashCodeSnippets.Templates(options, factories, providers, target);
 230         resolveConstantSnippets = new ResolveConstantSnippets.Templates(options, factories, providers, target);
 231         if (!JavaVersionUtil.Java8OrEarlier && GeneratePIC.getValue(options)) {
 232             profileSnippets = new ProfileSnippets.Templates(options, factories, providers, target);
 233         }
 234         objectCloneSnippets = new ObjectCloneSnippets.Templates(options, factories, providers, target);
 235         foreignCallSnippets = new ForeignCallSnippets.Templates(options, factories, providers, target);
 236     }
 237 
 238     public ArrayCopySnippets.Templates getArraycopySnippets() {
 239         return arraycopySnippets;
 240     }
 241 
 242     public MonitorSnippets.Templates getMonitorSnippets() {
 243         return monitorSnippets;
 244     }
 245 
 246     @Override
 247     @SuppressWarnings("try")
 248     public void lower(Node n, LoweringTool tool) {
 249         StructuredGraph graph = (StructuredGraph) n.graph();
 250         try (DebugCloseable context = n.withNodeSourcePosition()) {
 251             if (n instanceof Invoke) {
 252                 lowerInvoke((Invoke) n, tool, graph);
 253             } else if (n instanceof LoadMethodNode) {
 254                 lowerLoadMethodNode((LoadMethodNode) n);
 255             } else if (n instanceof GetClassNode) {
 256                 lowerGetClassNode((GetClassNode) n, tool, graph);
 257             } else if (n instanceof StoreHubNode) {
 258                 lowerStoreHubNode((StoreHubNode) n, graph);
 259             } else if (n instanceof OSRStartNode) {
 260                 lowerOSRStartNode((OSRStartNode) n);
 261             } else if (n instanceof BytecodeExceptionNode) {
 262                 lowerBytecodeExceptionNode((BytecodeExceptionNode) n);
 263             } else if (n instanceof InstanceOfNode) {
 264                 InstanceOfNode instanceOfNode = (InstanceOfNode) n;
 265                 if (graph.getGuardsStage().areDeoptsFixed()) {
 266                     instanceofSnippets.lower(instanceOfNode, tool);
 267                 } else {
 268                     if (instanceOfNode.allowsNull()) {
 269                         ValueNode object = instanceOfNode.getValue();
 270                         LogicNode newTypeCheck = graph.addOrUniqueWithInputs(InstanceOfNode.create(instanceOfNode.type(), object, instanceOfNode.profile(), instanceOfNode.getAnchor()));
 271                         LogicNode newNode = LogicNode.or(graph.unique(IsNullNode.create(object)), newTypeCheck, GraalDirectives.UNLIKELY_PROBABILITY);
 272                         instanceOfNode.replaceAndDelete(newNode);
 273                     }
 274                 }
 275             } else if (n instanceof InstanceOfDynamicNode) {
 276                 InstanceOfDynamicNode instanceOfDynamicNode = (InstanceOfDynamicNode) n;
 277                 if (graph.getGuardsStage().areDeoptsFixed()) {
 278                     instanceofSnippets.lower(instanceOfDynamicNode, tool);
 279                 } else {
 280                     ValueNode mirror = instanceOfDynamicNode.getMirrorOrHub();
 281                     if (mirror.stamp(NodeView.DEFAULT).getStackKind() == JavaKind.Object) {
 282                         ClassGetHubNode classGetHub = graph.unique(new ClassGetHubNode(mirror));
 283                         instanceOfDynamicNode.setMirror(classGetHub);
 284                     }
 285 
 286                     if (instanceOfDynamicNode.allowsNull()) {
 287                         ValueNode object = instanceOfDynamicNode.getObject();
 288                         LogicNode newTypeCheck = graph.addOrUniqueWithInputs(
 289                                         InstanceOfDynamicNode.create(graph.getAssumptions(), tool.getConstantReflection(), instanceOfDynamicNode.getMirrorOrHub(), object, false));
 290                         LogicNode newNode = LogicNode.or(graph.unique(IsNullNode.create(object)), newTypeCheck, GraalDirectives.UNLIKELY_PROBABILITY);
 291                         instanceOfDynamicNode.replaceAndDelete(newNode);
 292                     }
 293                 }
 294             } else if (n instanceof ClassIsAssignableFromNode) {
 295                 if (graph.getGuardsStage().areDeoptsFixed()) {
 296                     instanceofSnippets.lower((ClassIsAssignableFromNode) n, tool);
 297                 }
 298             } else if (n instanceof NewInstanceNode) {
 299                 if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 300                     newObjectSnippets.lower((NewInstanceNode) n, registers, tool);
 301                 }
 302             } else if (n instanceof DynamicNewInstanceNode) {
 303                 DynamicNewInstanceNode newInstanceNode = (DynamicNewInstanceNode) n;
 304                 if (newInstanceNode.getClassClass() == null) {
 305                     JavaConstant classClassMirror = constantReflection.asJavaClass(metaAccess.lookupJavaType(Class.class));
 306                     ConstantNode classClass = ConstantNode.forConstant(classClassMirror, tool.getMetaAccess(), graph);
 307                     newInstanceNode.setClassClass(classClass);
 308                 }
 309                 if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 310                     newObjectSnippets.lower(newInstanceNode, registers, tool);
 311                 }
 312             } else if (n instanceof NewArrayNode) {
 313                 if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 314                     newObjectSnippets.lower((NewArrayNode) n, registers, tool);
 315                 }
 316             } else if (n instanceof DynamicNewArrayNode) {
 317                 DynamicNewArrayNode dynamicNewArrayNode = (DynamicNewArrayNode) n;
 318                 if (dynamicNewArrayNode.getVoidClass() == null) {
 319                     JavaConstant voidClassMirror = constantReflection.asJavaClass(metaAccess.lookupJavaType(void.class));
 320                     ConstantNode voidClass = ConstantNode.forConstant(voidClassMirror, tool.getMetaAccess(), graph);
 321                     dynamicNewArrayNode.setVoidClass(voidClass);
 322                 }
 323                 if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 324                     newObjectSnippets.lower(dynamicNewArrayNode, registers, tool);
 325                 }
 326             } else if (n instanceof VerifyHeapNode) {
 327                 if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 328                     newObjectSnippets.lower((VerifyHeapNode) n, registers, tool);
 329                 }
 330             } else if (n instanceof RawMonitorEnterNode) {
 331                 if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 332                     monitorSnippets.lower((RawMonitorEnterNode) n, registers, tool);
 333                 }
 334             } else if (n instanceof MonitorExitNode) {
 335                 if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 336                     monitorSnippets.lower((MonitorExitNode) n, registers, tool);
 337                 }
 338             } else if (n instanceof ArrayCopyNode) {
 339                 arraycopySnippets.lower((ArrayCopyNode) n, tool);
 340             } else if (n instanceof ArrayCopyWithDelayedLoweringNode) {
 341                 arraycopySnippets.lower((ArrayCopyWithDelayedLoweringNode) n, tool);
 342             } else if (n instanceof G1PreWriteBarrier) {
 343                 writeBarrierSnippets.lower((G1PreWriteBarrier) n, registers, tool);
 344             } else if (n instanceof G1PostWriteBarrier) {
 345                 writeBarrierSnippets.lower((G1PostWriteBarrier) n, registers, tool);
 346             } else if (n instanceof G1ReferentFieldReadBarrier) {
 347                 writeBarrierSnippets.lower((G1ReferentFieldReadBarrier) n, registers, tool);
 348             } else if (n instanceof SerialWriteBarrier) {
 349                 writeBarrierSnippets.lower((SerialWriteBarrier) n, tool);
 350             } else if (n instanceof SerialArrayRangeWriteBarrier) {
 351                 writeBarrierSnippets.lower((SerialArrayRangeWriteBarrier) n, tool);
 352             } else if (n instanceof G1ArrayRangePreWriteBarrier) {
 353                 writeBarrierSnippets.lower((G1ArrayRangePreWriteBarrier) n, registers, tool);
 354             } else if (n instanceof G1ArrayRangePostWriteBarrier) {
 355                 writeBarrierSnippets.lower((G1ArrayRangePostWriteBarrier) n, registers, tool);
 356             } else if (n instanceof NewMultiArrayNode) {
 357                 if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 358                     newObjectSnippets.lower((NewMultiArrayNode) n, tool);
 359                 }
 360             } else if (n instanceof LoadExceptionObjectNode) {
 361                 exceptionObjectSnippets.lower((LoadExceptionObjectNode) n, registers, tool);
 362             } else if (n instanceof AssertionNode) {
 363                 assertionSnippets.lower((AssertionNode) n, tool);
 364             } else if (n instanceof StringToBytesNode) {
 365                 if (graph.getGuardsStage().areDeoptsFixed()) {
 366                     stringToBytesSnippets.lower((StringToBytesNode) n, tool);
 367                 }
 368             } else if (n instanceof IntegerDivRemNode) {
 369                 // Nothing to do for division nodes. The HotSpot signal handler catches divisions by
 370                 // zero and the MIN_VALUE / -1 cases.
 371             } else if (n instanceof AbstractDeoptimizeNode || n instanceof UnwindNode || n instanceof RemNode || n instanceof SafepointNode) {
 372                 /* No lowering, we generate LIR directly for these nodes. */
 373             } else if (n instanceof ClassGetHubNode) {
 374                 lowerClassGetHubNode((ClassGetHubNode) n, tool);
 375             } else if (n instanceof HubGetClassNode) {
 376                 lowerHubGetClassNode((HubGetClassNode) n, tool);
 377             } else if (n instanceof KlassLayoutHelperNode) {
 378                 lowerKlassLayoutHelperNode((KlassLayoutHelperNode) n, tool);
 379             } else if (n instanceof ComputeObjectAddressNode) {
 380                 if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 381                     lowerComputeObjectAddressNode((ComputeObjectAddressNode) n);
 382                 }
 383             } else if (n instanceof IdentityHashCodeNode) {
 384                 hashCodeSnippets.lower((IdentityHashCodeNode) n, tool);
 385             } else if (n instanceof ResolveDynamicConstantNode) {
 386                 if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 387                     resolveConstantSnippets.lower((ResolveDynamicConstantNode) n, tool);
 388                 }
 389             } else if (n instanceof ResolveConstantNode) {
 390                 if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 391                     resolveConstantSnippets.lower((ResolveConstantNode) n, tool);
 392                 }
 393             } else if (n instanceof ResolveMethodAndLoadCountersNode) {
 394                 if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 395                     resolveConstantSnippets.lower((ResolveMethodAndLoadCountersNode) n, tool);
 396                 }
 397             } else if (n instanceof InitializeKlassNode) {
 398                 if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 399                     resolveConstantSnippets.lower((InitializeKlassNode) n, tool);
 400                 }
 401             } else if (n instanceof ProfileNode) {
 402                 profileSnippets.lower((ProfileNode) n, tool);
 403             } else {
 404                 super.lower(n, tool);
 405             }
 406         }
 407     }
 408 
 409     private static void lowerComputeObjectAddressNode(ComputeObjectAddressNode n) {
 410         /*
 411          * Lower the node into a ComputeObjectAddress node and an Add but ensure that it's below any
 412          * potential safepoints and above it's uses.
 413          */
 414         for (Node use : n.usages().snapshot()) {
 415             if (use instanceof FixedNode) {
 416                 FixedNode fixed = (FixedNode) use;
 417                 StructuredGraph graph = n.graph();
 418                 GetObjectAddressNode address = graph.add(new GetObjectAddressNode(n.getObject()));
 419                 graph.addBeforeFixed(fixed, address);
 420                 AddNode add = graph.addOrUnique(new AddNode(address, n.getOffset()));
 421                 use.replaceFirstInput(n, add);
 422             } else {
 423                 throw GraalError.shouldNotReachHere("Unexpected floating use of ComputeObjectAddressNode " + n);
 424             }
 425         }
 426         GraphUtil.unlinkFixedNode(n);
 427         n.safeDelete();
 428     }
 429 
 430     private void lowerKlassLayoutHelperNode(KlassLayoutHelperNode n, LoweringTool tool) {
 431         if (tool.getLoweringStage() == LoweringTool.StandardLoweringStage.HIGH_TIER) {
 432             return;
 433         }
 434         StructuredGraph graph = n.graph();
 435         assert !n.getHub().isConstant();
 436         AddressNode address = createOffsetAddress(graph, n.getHub(), runtime.getVMConfig().klassLayoutHelperOffset);
 437         n.replaceAtUsagesAndDelete(graph.unique(new FloatingReadNode(address, KLASS_LAYOUT_HELPER_LOCATION, null, n.stamp(NodeView.DEFAULT), null, BarrierType.NONE)));
 438     }
 439 
 440     private void lowerHubGetClassNode(HubGetClassNode n, LoweringTool tool) {
 441         if (tool.getLoweringStage() == LoweringTool.StandardLoweringStage.HIGH_TIER) {
 442             return;
 443         }
 444 
 445         ValueNode hub = n.getHub();
 446         GraalHotSpotVMConfig vmConfig = runtime.getVMConfig();
 447         StructuredGraph graph = n.graph();
 448         assert !hub.isConstant() || GraalOptions.ImmutableCode.getValue(graph.getOptions());
 449         AddressNode mirrorAddress = createOffsetAddress(graph, hub, vmConfig.classMirrorOffset);
 450         FloatingReadNode read = graph.unique(
 451                         new FloatingReadNode(mirrorAddress, CLASS_MIRROR_LOCATION, null, vmConfig.classMirrorIsHandle ? StampFactory.forKind(target.wordJavaKind) : n.stamp(NodeView.DEFAULT),
 452                                         null, BarrierType.NONE));
 453         if (vmConfig.classMirrorIsHandle) {
 454             AddressNode address = createOffsetAddress(graph, read, 0);
 455             read = graph.unique(new FloatingReadNode(address, CLASS_MIRROR_HANDLE_LOCATION, null, n.stamp(NodeView.DEFAULT), null, BarrierType.NONE));
 456         }
 457         n.replaceAtUsagesAndDelete(read);
 458     }
 459 
 460     private void lowerClassGetHubNode(ClassGetHubNode n, LoweringTool tool) {
 461         if (tool.getLoweringStage() == LoweringTool.StandardLoweringStage.HIGH_TIER) {
 462             return;
 463         }
 464 
 465         StructuredGraph graph = n.graph();
 466         assert !n.getValue().isConstant();
 467         AddressNode address = createOffsetAddress(graph, n.getValue(), runtime.getVMConfig().klassOffset);
 468         FloatingReadNode read = graph.unique(new FloatingReadNode(address, CLASS_KLASS_LOCATION, null, n.stamp(NodeView.DEFAULT), null, BarrierType.NONE));
 469         n.replaceAtUsagesAndDelete(read);
 470     }
 471 
 472     private void lowerInvoke(Invoke invoke, LoweringTool tool, StructuredGraph graph) {
 473         if (invoke.callTarget() instanceof MethodCallTargetNode) {
 474             MethodCallTargetNode callTarget = (MethodCallTargetNode) invoke.callTarget();
 475             NodeInputList<ValueNode> parameters = callTarget.arguments();
 476             ValueNode receiver = parameters.isEmpty() ? null : parameters.get(0);
 477 
 478             if (!callTarget.isStatic()) {
 479                 assert receiver != null : "non-static call must have a receiver";
 480                 if (receiver.stamp(NodeView.DEFAULT) instanceof ObjectStamp && !StampTool.isPointerNonNull(receiver)) {
 481                     ValueNode nonNullReceiver = createNullCheckedValue(receiver, invoke.asNode(), tool);
 482                     parameters.set(0, nonNullReceiver);
 483                     receiver = nonNullReceiver;
 484                 }
 485             }
 486             JavaType[] signature = callTarget.targetMethod().getSignature().toParameterTypes(callTarget.isStatic() ? null : callTarget.targetMethod().getDeclaringClass());
 487 
 488             LoweredCallTargetNode loweredCallTarget = null;
 489             OptionValues options = graph.getOptions();
 490             if (InlineVTableStubs.getValue(options) && callTarget.invokeKind().isIndirect() && (AlwaysInlineVTableStubs.getValue(options) || invoke.isPolymorphic())) {
 491                 HotSpotResolvedJavaMethod hsMethod = (HotSpotResolvedJavaMethod) callTarget.targetMethod();
 492                 ResolvedJavaType receiverType = invoke.getReceiverType();
 493                 if (hsMethod.isInVirtualMethodTable(receiverType)) {
 494                     JavaKind wordKind = runtime.getTarget().wordJavaKind;
 495                     ValueNode hub = createReadHub(graph, receiver, tool);
 496 
 497                     ReadNode metaspaceMethod = createReadVirtualMethod(graph, hub, hsMethod, receiverType);
 498                     // We use LocationNode.ANY_LOCATION for the reads that access the
 499                     // compiled code entry as HotSpot does not guarantee they are final
 500                     // values.
 501                     int methodCompiledEntryOffset = runtime.getVMConfig().methodCompiledEntryOffset;
 502                     AddressNode address = createOffsetAddress(graph, metaspaceMethod, methodCompiledEntryOffset);
 503                     ReadNode compiledEntry = graph.add(new ReadNode(address, any(), StampFactory.forKind(wordKind), BarrierType.NONE));
 504 
 505                     loweredCallTarget = graph.add(new HotSpotIndirectCallTargetNode(metaspaceMethod, compiledEntry, parameters.toArray(new ValueNode[parameters.size()]), callTarget.returnStamp(),
 506                                     signature, callTarget.targetMethod(),
 507                                     HotSpotCallingConventionType.JavaCall, callTarget.invokeKind()));
 508 
 509                     graph.addBeforeFixed(invoke.asNode(), metaspaceMethod);
 510                     graph.addAfterFixed(metaspaceMethod, compiledEntry);
 511                 }
 512             }
 513 
 514             if (loweredCallTarget == null) {
 515                 loweredCallTarget = graph.add(new HotSpotDirectCallTargetNode(parameters.toArray(new ValueNode[parameters.size()]), callTarget.returnStamp(),
 516                                 signature, callTarget.targetMethod(),
 517                                 HotSpotCallingConventionType.JavaCall,
 518                                 callTarget.invokeKind()));
 519             }
 520             callTarget.replaceAndDelete(loweredCallTarget);
 521         }
 522     }
 523 
 524     private CompressEncoding getOopEncoding() {
 525         return runtime.getVMConfig().getOopEncoding();
 526     }
 527 
 528     @Override
 529     protected Stamp loadCompressedStamp(ObjectStamp stamp) {
 530         return HotSpotNarrowOopStamp.compressed(stamp, getOopEncoding());
 531     }
 532 
 533     @Override
 534     protected ValueNode newCompressionNode(CompressionOp op, ValueNode value) {
 535         return new HotSpotCompressionNode(op, value, getOopEncoding());
 536     }
 537 
 538     @Override
 539     public ValueNode staticFieldBase(StructuredGraph graph, ResolvedJavaField f) {
 540         HotSpotResolvedJavaField field = (HotSpotResolvedJavaField) f;
 541         JavaConstant base = constantReflection.asJavaClass(field.getDeclaringClass());
 542         return ConstantNode.forConstant(base, metaAccess, graph);
 543     }
 544 
 545     @Override
 546     protected ValueNode createReadArrayComponentHub(StructuredGraph graph, ValueNode arrayHub, FixedNode anchor) {
 547         /*
 548          * Anchor the read of the element klass to the cfg, because it is only valid when arrayClass
 549          * is an object class, which might not be the case in other parts of the compiled method.
 550          */
 551         AddressNode address = createOffsetAddress(graph, arrayHub, runtime.getVMConfig().arrayClassElementOffset);
 552         return graph.unique(new FloatingReadNode(address, OBJ_ARRAY_KLASS_ELEMENT_KLASS_LOCATION, null, KlassPointerStamp.klassNonNull(), AbstractBeginNode.prevBegin(anchor)));
 553     }
 554 
 555     @Override
 556     protected void lowerUnsafeLoadNode(RawLoadNode load, LoweringTool tool) {
 557         StructuredGraph graph = load.graph();
 558         if (!(load instanceof GuardedUnsafeLoadNode) && !graph.getGuardsStage().allowsFloatingGuards() && addReadBarrier(load)) {
 559             unsafeLoadSnippets.lower(load, tool);
 560         } else {
 561             super.lowerUnsafeLoadNode(load, tool);
 562         }
 563     }
 564 
 565     private void lowerLoadMethodNode(LoadMethodNode loadMethodNode) {
 566         StructuredGraph graph = loadMethodNode.graph();
 567         HotSpotResolvedJavaMethod method = (HotSpotResolvedJavaMethod) loadMethodNode.getMethod();
 568         ReadNode metaspaceMethod = createReadVirtualMethod(graph, loadMethodNode.getHub(), method, loadMethodNode.getReceiverType());
 569         graph.replaceFixed(loadMethodNode, metaspaceMethod);
 570     }
 571 
 572     private static void lowerGetClassNode(GetClassNode getClass, LoweringTool tool, StructuredGraph graph) {
 573         StampProvider stampProvider = tool.getStampProvider();
 574         LoadHubNode hub = graph.unique(new LoadHubNode(stampProvider, getClass.getObject()));
 575         HubGetClassNode hubGetClass = graph.unique(new HubGetClassNode(tool.getMetaAccess(), hub));
 576         getClass.replaceAtUsagesAndDelete(hubGetClass);
 577         hub.lower(tool);
 578         hubGetClass.lower(tool);
 579     }
 580 
 581     private void lowerStoreHubNode(StoreHubNode storeHub, StructuredGraph graph) {
 582         WriteNode hub = createWriteHub(graph, storeHub.getObject(), storeHub.getValue());
 583         graph.replaceFixed(storeHub, hub);
 584     }
 585 
 586     @Override
 587     public BarrierType fieldInitializationBarrier(JavaKind entryKind) {
 588         return (entryKind == JavaKind.Object && !runtime.getVMConfig().useDeferredInitBarriers) ? BarrierType.IMPRECISE : BarrierType.NONE;
 589     }
 590 
 591     @Override
 592     public BarrierType arrayInitializationBarrier(JavaKind entryKind) {
 593         return (entryKind == JavaKind.Object && !runtime.getVMConfig().useDeferredInitBarriers) ? BarrierType.PRECISE : BarrierType.NONE;
 594     }
 595 
 596     private void lowerOSRStartNode(OSRStartNode osrStart) {
 597         StructuredGraph graph = osrStart.graph();
 598         if (graph.getGuardsStage() == StructuredGraph.GuardsStage.FIXED_DEOPTS) {
 599             StartNode newStart = graph.add(new StartNode());
 600             ParameterNode buffer = graph.addWithoutUnique(new ParameterNode(0, StampPair.createSingle(StampFactory.forKind(runtime.getTarget().wordJavaKind))));
 601             ForeignCallNode migrationEnd = graph.add(new ForeignCallNode(foreignCalls, OSR_MIGRATION_END, buffer));
 602             migrationEnd.setStateAfter(osrStart.stateAfter());
 603             newStart.setNext(migrationEnd);
 604             FixedNode next = osrStart.next();
 605             osrStart.setNext(null);
 606             migrationEnd.setNext(next);
 607             graph.setStart(newStart);
 608 
 609             final int wordSize = target.wordSize;
 610 
 611             // @formatter:off
 612             // taken from c2 locals_addr = osr_buf + (max_locals-1)*wordSize)
 613             // @formatter:on
 614             int localsOffset = (graph.method().getMaxLocals() - 1) * wordSize;
 615             for (OSRLocalNode osrLocal : graph.getNodes(OSRLocalNode.TYPE)) {
 616                 int size = osrLocal.getStackKind().getSlotCount();
 617                 int offset = localsOffset - (osrLocal.index() + size - 1) * wordSize;
 618                 AddressNode address = createOffsetAddress(graph, buffer, offset);
 619                 ReadNode load = graph.add(new ReadNode(address, any(), osrLocal.stamp(NodeView.DEFAULT), BarrierType.NONE));
 620                 osrLocal.replaceAndDelete(load);
 621                 graph.addBeforeFixed(migrationEnd, load);
 622             }
 623 
 624             // @formatter:off
 625             // taken from c2 monitors_addr = osr_buf + (max_locals+mcnt*2-1)*wordSize);
 626             // @formatter:on
 627             final int lockCount = osrStart.stateAfter().locksSize();
 628             final int locksOffset = (graph.method().getMaxLocals() + lockCount * 2 - 1) * wordSize;
 629 
 630             // first initialize the lock slots for all enters with the displaced marks read from the
 631             // buffer
 632             for (OSRMonitorEnterNode osrMonitorEnter : graph.getNodes(OSRMonitorEnterNode.TYPE)) {
 633                 MonitorIdNode monitorID = osrMonitorEnter.getMonitorId();
 634                 OSRLockNode lock = (OSRLockNode) osrMonitorEnter.object();
 635                 final int index = lock.index();
 636 
 637                 final int offsetDisplacedHeader = locksOffset - ((index * 2) + 1) * wordSize;
 638                 final int offsetLockObject = locksOffset - index * 2 * wordSize;
 639 
 640                 // load the displaced mark from the osr buffer
 641                 AddressNode addressDisplacedHeader = createOffsetAddress(graph, buffer, offsetDisplacedHeader);
 642                 ReadNode loadDisplacedHeader = graph.add(new ReadNode(addressDisplacedHeader, any(), lock.stamp(NodeView.DEFAULT), BarrierType.NONE));
 643                 graph.addBeforeFixed(migrationEnd, loadDisplacedHeader);
 644 
 645                 // we need to initialize the stack slot for the lock
 646                 BeginLockScopeNode beginLockScope = graph.add(new BeginLockScopeNode(lock.getStackKind(), monitorID.getLockDepth()));
 647                 graph.addBeforeFixed(migrationEnd, beginLockScope);
 648 
 649                 // write the displaced mark to the correct stack slot
 650                 AddressNode addressDisplacedMark = createOffsetAddress(graph, beginLockScope, runtime.getVMConfig().basicLockDisplacedHeaderOffset);
 651                 WriteNode writeStackSlot = graph.add(new WriteNode(addressDisplacedMark, DISPLACED_MARK_WORD_LOCATION, loadDisplacedHeader, BarrierType.NONE));
 652                 graph.addBeforeFixed(migrationEnd, writeStackSlot);
 653 
 654                 // load the lock object from the osr buffer
 655                 AddressNode addressLockObject = createOffsetAddress(graph, buffer, offsetLockObject);
 656                 ReadNode loadObject = graph.add(new ReadNode(addressLockObject, any(), lock.stamp(NodeView.DEFAULT), BarrierType.NONE));
 657                 lock.replaceAndDelete(loadObject);
 658                 graph.addBeforeFixed(migrationEnd, loadObject);
 659             }
 660 
 661             osrStart.replaceAtUsagesAndDelete(newStart);
 662         }
 663     }
 664 
 665     static final class Exceptions {
 666         protected static final EnumMap<BytecodeExceptionKind, RuntimeException> cachedExceptions;
 667 
 668         static {
 669             cachedExceptions = new EnumMap<>(BytecodeExceptionKind.class);
 670             cachedExceptions.put(BytecodeExceptionKind.NULL_POINTER, clearStackTrace(new NullPointerException()));
 671             cachedExceptions.put(BytecodeExceptionKind.OUT_OF_BOUNDS, clearStackTrace(new ArrayIndexOutOfBoundsException()));
 672             cachedExceptions.put(BytecodeExceptionKind.CLASS_CAST, clearStackTrace(new ClassCastException()));
 673             cachedExceptions.put(BytecodeExceptionKind.ARRAY_STORE, clearStackTrace(new ArrayStoreException()));
 674             cachedExceptions.put(BytecodeExceptionKind.DIVISION_BY_ZERO, clearStackTrace(new ArithmeticException()));
 675         }
 676 
 677         private static RuntimeException clearStackTrace(RuntimeException ex) {
 678             ex.setStackTrace(new StackTraceElement[0]);
 679             return ex;
 680         }
 681     }
 682 
 683     public static final class RuntimeCalls {
 684         public static final EnumMap<BytecodeExceptionKind, ForeignCallDescriptor> runtimeCalls;
 685 
 686         static {
 687             runtimeCalls = new EnumMap<>(BytecodeExceptionKind.class);
 688             runtimeCalls.put(BytecodeExceptionKind.ARRAY_STORE, new ForeignCallDescriptor("createArrayStoreException", ArrayStoreException.class, Object.class));
 689             runtimeCalls.put(BytecodeExceptionKind.CLASS_CAST, new ForeignCallDescriptor("createClassCastException", ClassCastException.class, Object.class, KlassPointer.class));
 690             runtimeCalls.put(BytecodeExceptionKind.NULL_POINTER, new ForeignCallDescriptor("createNullPointerException", NullPointerException.class));
 691             runtimeCalls.put(BytecodeExceptionKind.OUT_OF_BOUNDS, new ForeignCallDescriptor("createOutOfBoundsException", ArrayIndexOutOfBoundsException.class, int.class, int.class));
 692             runtimeCalls.put(BytecodeExceptionKind.DIVISION_BY_ZERO, new ForeignCallDescriptor("createDivisionByZeroException", ArithmeticException.class));
 693             runtimeCalls.put(BytecodeExceptionKind.INTEGER_EXACT_OVERFLOW, new ForeignCallDescriptor("createIntegerExactOverflowException", ArithmeticException.class));
 694             runtimeCalls.put(BytecodeExceptionKind.LONG_EXACT_OVERFLOW, new ForeignCallDescriptor("createLongExactOverflowException", ArithmeticException.class));
 695         }
 696     }
 697 
 698     private void throwCachedException(BytecodeExceptionNode node) {
 699         if (IS_IN_NATIVE_IMAGE) {
 700             throw new InternalError("Can't throw exception from SVM object");
 701         }
 702         Throwable exception = Exceptions.cachedExceptions.get(node.getExceptionKind());
 703         assert exception != null;
 704 
 705         StructuredGraph graph = node.graph();
 706         FloatingNode exceptionNode = ConstantNode.forConstant(constantReflection.forObject(exception), metaAccess, graph);
 707         graph.replaceFixedWithFloating(node, exceptionNode);
 708     }
 709 
 710     private void lowerBytecodeExceptionNode(BytecodeExceptionNode node) {
 711         if (OmitHotExceptionStacktrace.getValue(node.getOptions())) {
 712             throwCachedException(node);
 713             return;
 714         }
 715 
 716         ForeignCallDescriptor descriptor = RuntimeCalls.runtimeCalls.get(node.getExceptionKind());
 717         assert descriptor != null;
 718 
 719         StructuredGraph graph = node.graph();
 720         ForeignCallNode foreignCallNode = graph.add(new ForeignCallNode(foreignCalls, descriptor, node.stamp(NodeView.DEFAULT), node.getArguments()));
 721         graph.replaceFixedWithFixed(node, foreignCallNode);
 722     }
 723 
 724     private boolean addReadBarrier(RawLoadNode load) {
 725         if (runtime.getVMConfig().useG1GC && load.graph().getGuardsStage() == StructuredGraph.GuardsStage.FIXED_DEOPTS && load.object().getStackKind() == JavaKind.Object &&
 726                         load.accessKind() == JavaKind.Object && !StampTool.isPointerAlwaysNull(load.object())) {
 727             ResolvedJavaType type = StampTool.typeOrNull(load.object());
 728             if (type != null && !type.isArray()) {
 729                 return true;
 730             }
 731         }
 732         return false;
 733     }
 734 
 735     private ReadNode createReadVirtualMethod(StructuredGraph graph, ValueNode hub, HotSpotResolvedJavaMethod method, ResolvedJavaType receiverType) {
 736         return createReadVirtualMethod(graph, hub, method.vtableEntryOffset(receiverType));
 737     }
 738 
 739     private ReadNode createReadVirtualMethod(StructuredGraph graph, ValueNode hub, int vtableEntryOffset) {
 740         assert vtableEntryOffset > 0;
 741         // We use LocationNode.ANY_LOCATION for the reads that access the vtable
 742         // entry as HotSpot does not guarantee that this is a final value.
 743         Stamp methodStamp = MethodPointerStamp.methodNonNull();
 744         AddressNode address = createOffsetAddress(graph, hub, vtableEntryOffset);
 745         ReadNode metaspaceMethod = graph.add(new ReadNode(address, any(), methodStamp, BarrierType.NONE));
 746         return metaspaceMethod;
 747     }
 748 
 749     @Override
 750     protected ValueNode createReadHub(StructuredGraph graph, ValueNode object, LoweringTool tool) {
 751         if (tool.getLoweringStage() != LoweringTool.StandardLoweringStage.LOW_TIER) {
 752             return graph.unique(new LoadHubNode(tool.getStampProvider(), object));
 753         }
 754         assert !object.isConstant() || object.isNullConstant();
 755 
 756         KlassPointerStamp hubStamp = KlassPointerStamp.klassNonNull();
 757         if (runtime.getVMConfig().useCompressedClassPointers) {
 758             hubStamp = hubStamp.compressed(runtime.getVMConfig().getKlassEncoding());
 759         }
 760 
 761         AddressNode address = createOffsetAddress(graph, object, runtime.getVMConfig().hubOffset);
 762         LocationIdentity hubLocation = runtime.getVMConfig().useCompressedClassPointers ? COMPRESSED_HUB_LOCATION : HUB_LOCATION;
 763         FloatingReadNode memoryRead = graph.unique(new FloatingReadNode(address, hubLocation, null, hubStamp, null, BarrierType.NONE));
 764         if (runtime.getVMConfig().useCompressedClassPointers) {
 765             return HotSpotCompressionNode.uncompress(memoryRead, runtime.getVMConfig().getKlassEncoding());
 766         } else {
 767             return memoryRead;
 768         }
 769     }
 770 
 771     private WriteNode createWriteHub(StructuredGraph graph, ValueNode object, ValueNode value) {
 772         assert !object.isConstant() || object.asConstant().isDefaultForKind();
 773 
 774         ValueNode writeValue = value;
 775         if (runtime.getVMConfig().useCompressedClassPointers) {
 776             writeValue = HotSpotCompressionNode.compress(value, runtime.getVMConfig().getKlassEncoding());
 777         }
 778 
 779         AddressNode address = createOffsetAddress(graph, object, runtime.getVMConfig().hubOffset);
 780         return graph.add(new WriteNode(address, HUB_WRITE_LOCATION, writeValue, BarrierType.NONE));
 781     }
 782 
 783     @Override
 784     protected BarrierType fieldLoadBarrierType(ResolvedJavaField f) {
 785         HotSpotResolvedJavaField loadField = (HotSpotResolvedJavaField) f;
 786         BarrierType barrierType = BarrierType.NONE;
 787         if (runtime.getVMConfig().useG1GC && loadField.getJavaKind() == JavaKind.Object && metaAccess.lookupJavaType(Reference.class).equals(loadField.getDeclaringClass()) &&
 788                         loadField.getName().equals("referent")) {
 789             barrierType = BarrierType.PRECISE;
 790         }
 791         return barrierType;
 792     }
 793 
 794     @Override
 795     public int fieldOffset(ResolvedJavaField f) {
 796         return f.getOffset();
 797     }
 798 
 799     @Override
 800     public int arrayLengthOffset() {
 801         return runtime.getVMConfig().arrayOopDescLengthOffset();
 802     }
 803 
 804     @Override
 805     protected final JavaKind getStorageKind(ResolvedJavaField field) {
 806         return field.getJavaKind();
 807     }
 808 
 809     @Override
 810     public ObjectCloneSnippets.Templates getObjectCloneSnippets() {
 811         return objectCloneSnippets;
 812     }
 813 
 814     @Override
 815     public ForeignCallSnippets.Templates getForeignCallSnippets() {
 816         return foreignCallSnippets;
 817     }
 818 }